This guide demonstrates using Istio Gateway
and VirtualService
resources to configure a gateway deployed via gateway injection. These resources set up the gateway to expose a service inside the mesh to traffic from outside. Afterward, you expose the gateway to traffic external to the cluster by changing the gateway's Service
to type LoadBalancer
.
Create a new namespace named httpbin
by executing the command below:
Enable sidecar injection for the namespace. If your setup uses the InPlace
upgrade strategy, run this command:
If you are using the RevisionBased
upgrade strategy, execute these commands:
To discover your <revision-name>
, run the following:
Sample output:
Label the namespace using the revision name to enable sidecar injection:
Deploy the httpbin
sample service by running the following command:
Create a file named httpbin-gw.yaml
that contains an Istio Gateway
resource definition. This resource configures the gateway proxies to open port 80 (HTTP) for the host httpbin.example.com
.
selector
to match the unique label or labels defined in the pod template of the gateway proxy Deployment
. By default, the Istio Gateway
configuration applies to matching gateway pods across all namespaces.hosts
field, list the addresses that clients can use to access a mesh service on the corresponding port.Apply the YAML file with this command:
Create another YAML file named httpbin-vs.yaml
for a VirtualService
. This VirtualService
will define rules to route traffic from the gateway proxy to the httpbin
service.
hosts
to which the VirtualService
routing rules will apply. The specified hosts
must be exposed by the Istio Gateway
resource to which this VirtualService
is attached.VirtualService
to the Istio Gateway
resource from the previous step by adding the Gateway
's name to the gateways list.httpbin
service by defining a destination
that specifies the host
and port
of the httpbin
Service
.Apply the YAML file using this command:
Create a namespace for a curl
client by executing this command:
Deploy the curl
client with the following command:
Store the name of the curl
pod in a CURL_POD
variable by running this command:
From the curl
client, send a request to the /headers
endpoint of the httpbin
application via the ingress gateway Service
. Set the Host
header to httpbin.example.com
to align with the host specified in the Istio Gateway
and VirtualService
. Execute the following curl
command:
The response should show a 200 OK
HTTP status, confirming the request was successful.
Example output
Send another request to an endpoint that lacks a corresponding URI prefix match in the httpbin
VirtualService
by running this command:
The response should be a 404 Not Found
status. This is the expected outcome because the /get
endpoint does not have a defined URI prefix match in the httpbin
VirtualService
.
Example output
Expose the gateway proxy to traffic from outside the cluster by changing its Service
type to LoadBalancer
:
Confirm that the httpbin
service is accessible from outside the cluster using the gateway Service
's external hostname or IP address. Make sure to set the INGRESS_HOST
variable correctly for your cluster's environment.
Set the INGRESS_HOST
variable with this command:
In certain environments, the load balancer may be exposed using a host name, instead of an IP address. In this case, the ingress gateway's EXTERNAL-IP
value will not be an IP address, but rather a host name, and the above command will have failed to set the INGRESS_HOST
environment variable. Use the following command to correct the INGRESS_HOST
value:
Send a curl
request to the httpbin
service using the gateway's host by running this command:
Check that the response includes the HTTP/1.1 200 OK
status, which confirms the request succeeded.