Ingress Gateways
Along with support for Kubernetes Ingress6 resources, Istio also allows you to configure ingress traffic
using either an Istio Gateway or Kubernetes Gateway7 resource.
A Gateway
provides more extensive customization and flexibility than Ingress
, and allows Istio features such as monitoring and route rules to be applied to traffic entering the cluster.
This task describes how to configure Istio to expose a service outside of the service mesh using a Gateway
.
Before you begin
Setup Istio by following the instructions in the Installation guide9.
Start the httpbin10 sample, which will serve as the target service for ingress traffic:
Note that for the purpose of this document, which shows how to use a gateway to control ingress traffic into your “Kubernetes cluster”, you can start the
httpbin
service with or without sidecar injection enabled (i.e., the target service can be either inside or outside of the Istio mesh).
Configuring ingress using a gateway
An ingress Gateway
describes a load balancer operating at the edge of the mesh that receives incoming HTTP/TCP connections.
It configures exposed ports, protocols, etc.
but, unlike Kubernetes Ingress Resources12,
does not include any traffic routing configuration. Traffic routing for ingress traffic is instead configured
using routing rules, exactly in the same way as for internal service requests.
Let’s see how you can configure a Gateway
on port 80 for HTTP traffic.
Create an Istio Gateway13:
Configure routes for traffic entering via the Gateway
:
You have now created a virtual service14
configuration for the httpbin
service containing two route rules that allow traffic for paths /status
and
/delay
.
The gateways list
specifies that only requests through your httpbin-gateway
are allowed.
All other external requests will be rejected with a 404 response.
Create a Kubernetes Gateway:
Because creating a Kubernetes Gateway
resource will also
deploy an associated proxy service,
run the following command to wait for the gateway to be ready:
Configure routes for traffic entering via the Gateway
:
You have now created an HTTP Route
configuration for the httpbin
service containing two route rules that allow traffic for paths /status
and
/delay
.
Determining the ingress IP and ports
Every Gateway
is backed by a service of type LoadBalancer15.
The external load balancer IP and ports for this service are used to access the gateway.
Kubernetes services of type LoadBalancer
are supported by default in clusters running on most cloud platforms but
in some environments (e.g., test) you may need to do the following:
minikube
- start an external load balancer by running the following command in a different terminal:kind
- follow the guide16 to getLoadBalancer
type services to work.other platforms - you may be able to use MetalLB17 to get an
EXTERNAL-IP
forLoadBalancer
services.
For convenience, we will store the ingress IP and ports in environment variables which will be used in later instructions.
Set the INGRESS_HOST
and INGRESS_PORT
environment variables according to the following instructions:
Set the following environment variables to the name and namespace where the Istio ingress gateway is located in your cluster:
Run the following command to determine if your Kubernetes cluster is in an environment that supports external load balancers:
If the EXTERNAL-IP
value is set, your environment has an external load balancer that you can use for the ingress gateway.
If the EXTERNAL-IP
value is <none>
(or perpetually <pending>
), your environment does not provide an external load balancer for the ingress gateway.
If your environment does not support external load balancers, you can try accessing the ingress gateway using node ports. Otherwise, set the ingress IP and ports using the following commands:
Get the gateway address and port from the httpbin gateway resource:
Accessing ingress services
Access the httpbin service using curl:
Note that you use the
-H
flag to set the Host HTTP header to “httpbin.example.com”. This is needed because your ingressGateway
is configured to handle “httpbin.example.com”, but in your test environment you have no DNS binding for that host and are simply sending your request to the ingress IP.Access any other URL that has not been explicitly exposed. You should see an HTTP 404 error:
Accessing ingress services using a browser
Entering the httpbin
service URL in a browser won’t work because you can’t pass the Host header
to a browser like you did with curl
. In a real world situation, this is not a problem
because you configure the requested host properly and DNS resolvable. Thus, you use the host’s domain name
in the URL, for example, https://httpbin.example.com/status/200
.
You can work around this problem for simple tests and demos as follows:
Use a wildcard *
value for the host in the Gateway
and VirtualService
configurations. For example, change your ingress configuration to the following:
If you remove the host names from the Gateway
and HTTPRoute
configurations, they will apply to any request.
For example, change your ingress configuration to the following:
You can then use $INGRESS_HOST:$INGRESS_PORT
in the browser URL. For example,
http://$INGRESS_HOST:$INGRESS_PORT/headers
will display all the headers that your browser sends.
Understanding what happened
The Gateway
configuration resources allow external traffic to enter the
Istio service mesh and make the traffic management and policy features of Istio
available for edge services.
In the preceding steps, you created a service inside the service mesh and exposed an HTTP endpoint of the service to external traffic.
Using node ports of the ingress gateway service
If your environment does not support external load balancers, you can still experiment with some of the Istio features by
using the istio-ingressgateway
service’s node ports.
Set the ingress ports:
Setting the ingress IP depends on the cluster provider:
GKE:
You need to create firewall rules to allow the TCP traffic to the ingressgateway service’s ports. Run the following commands to allow the traffic for the HTTP port, the secure port (HTTPS) or both:
IBM Cloud Kubernetes Service:
Docker For Desktop:
Other environments:
Troubleshooting
Inspect the values of the
INGRESS_HOST
andINGRESS_PORT
environment variables. Make sure they have valid values, according to the output of the following commands:Check that you have no other Istio ingress gateways defined on the same port:
Check that you have no Kubernetes Ingress resources defined on the same IP and port:
If you have an external load balancer and it does not work for you, try to access the gateway using its node port.