Gateways
Gateways and OpenShift Service Mesh
Abstract
Chapter 1. About gateways Copy linkLink copied to clipboard!
A gateway is a standalone Envoy proxy deployment and an associated Kubernetes service operating at the edge of a service mesh. You can configure a gateway to give fine-grained control over the traffic that enters or leaves the mesh. In Red Hat OpenShift Service Mesh, you can install gateways by using gateway injection or via the Gateway API.
Red Hat OpenShift Service Mesh supports different gateway configurations based on the deployment mode. You can deploy gateways by using gateway injection and configure them with Istio Gateway and VirtualService resources in sidecar mode or with Kubernetes Gateway API resources in both sidecar and ambient modes.
1.1. About gateway injection Copy linkLink copied to clipboard!
Gateway injection relies upon the same mechanism as sidecar injection to inject the Envoy proxy into gateway pods. To install a gateway using gateway injection, you create a Kubernetes Deployment object and an associated Kubernetes Service object in a namespace that is visible to the Istio control plane. When creating the Deployment object you label and annotate it so that the Istio control plane injects a proxy, and the proxy is configured as a gateway. After installing the gateway, you configure it to control ingress and egress traffic using the Istio Gateway and VirtualService resources.
1.1.1. Installing a gateway by using gateway injection Copy linkLink copied to clipboard!
This procedure explains how to install a gateway by using gateway injection.
You can use this procedure to create ingress or egress gateways.
Prerequisites
- You have installed the OpenShift Service Mesh Operator version 3.0 or later.
- You have created an Istio control plane.
-
You have created an
IstioCNIresource.
Procedure
Create a namespace that you will use to install the gateway.
oc create namespace <gateway_namespace>
$ oc create namespace <gateway_namespace>Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteInstall the gateway and the Istio control plane in different namespaces.
You can install the gateway in a dedicated gateway namespace. This approach allows the gateway to be shared by many applications operating in different namespaces. Alternatively, you can install the gateway in an application namespace. In this approach, the gateway acts as a dedicated gateway for the application in that namespace.
Create a YAML file named
secret-reader.ymlthat defines the service account, role, and role binding for the gateway deployment. These settings enable the gateway to read the secrets, which is required for obtaining TLS credentials.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Apply the YAML file by running the following command:
oc apply -f secret-reader.yml
$ oc apply -f secret-reader.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a YAML file named
gateway-deployment.ymlthat defines the KubernetesDeploymentobject for the gateway.Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Indicates that the Istio control plane uses the gateway injection template instead of the default sidecar template.
- 2
- Ensure that a unique label is set for the gateway deployment. A unique label is required so that Istio
Gatewayresources can select gateway workloads. - 3
- Enables gateway injection by setting the
sidecar.istio.io/injectlabel totrue. If the name of the Istio resource is notdefaultyou must use theistio.io/rev: <istio_revision>label instead, where the revision represents the active revision of the Istio resource. - 4
- Sets the image field to
autoso that the image automatically updates each time the pod starts. - 5
- Sets the
serviceAccountNameto the name of theServiceAccountcreated previously.
Apply the YAML file by running the following command:
oc apply -f gateway-deployment.yml
$ oc apply -f gateway-deployment.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that the gateway
Deploymentrollout was successful by running the following command:oc rollout status deployment/<gateway_name> -n <gateway_namespace>
$ oc rollout status deployment/<gateway_name> -n <gateway_namespace>Copy to Clipboard Copied! Toggle word wrap Toggle overflow You should see output similar to the following:
Example output
Waiting for deployment "<gateway_name>" rollout to finish: 0 of 1 updated replicas are available... deployment "<gateway_name>" successfully rolled out
Waiting for deployment "<gateway_name>" rollout to finish: 0 of 1 updated replicas are available... deployment "<gateway_name>" successfully rolled outCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a YAML file named
gateway-service.ymlthat contains the KubernetesServiceobject for the gateway.Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- When you set
spec.typetoClusterIPthe gatewayServiceobject can be accessed only from within the cluster. If the gateway has to handle ingress traffic from outside the cluster, setspec.typetoLoadBalancer. Alternatively, you can use OpenShift Routes. - 2
- Set the
selectorto the unique label or set of labels specified in the pod template of the gateway deployment that you previously created.
Apply the YAML file by running the following command:
oc apply -f gateway-service.yml
$ oc apply -f gateway-service.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that the gateway service is targeting the endpoint of the gateway pods by running the following command:
oc get endpoints <gateway_name> -n <gateway_namespace>
$ oc get endpoints <gateway_name> -n <gateway_namespace>Copy to Clipboard Copied! Toggle word wrap Toggle overflow You should see output similar to the following example:
Example output
NAME ENDPOINTS AGE <gateway_name> 10.131.0.181:8080,10.131.0.181:8443 1m
NAME ENDPOINTS AGE <gateway_name> 10.131.0.181:8080,10.131.0.181:8443 1mCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: Create a YAML file named
gateway-hpa.ymlthat defines a horizontal pod autoscaler for the gateway. The following example sets the minimum replicas to2and the maximum replicas to5and scales the replicas up when average CPU utilization exceeds 80% of the CPU resource limit. This limit is specified in the pod template of the deployment for the gateway.Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Set
spec.scaleTargetRef.nameto the name of the gateway deployment previously created.
Optional: Apply the YAML file by running the following command:
oc apply -f gateway-hpa.yml
$ oc apply -f gateway-hpa.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: Create a YAML file named
gateway-pdb.ymlthat defines a pod disruption budget for the gateway. The following example allows gateway pods to be evicted only when at least 1 healthy gateway pod will remain on the cluster after the eviction.Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Set the
spec.selector.matchLabelsto the unique label or set of labels specified in the pod template of the gateway deployment previously created.
Optional: Apply the YAML file by running the following command:
oc apply -f gateway-pdb.yml
$ oc apply -f gateway-pdb.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Chapter 2. Getting traffic into a mesh Copy linkLink copied to clipboard!
Using Istio APIs, you can configure gateway proxies that were installed using gateway injection to accept traffic originating from outside the mesh, and route that traffic to the services within the mesh.
You can expose gateway proxies to traffic outside a cluster by using either a LoadBalancer type Service or OpenShift Routes.
2.1. About ingress traffic routing approaches Copy linkLink copied to clipboard!
Red Hat OpenShift Service Mesh offers two approaches to configure ingress traffic routing to services in the mesh. The approach depends on the service mesh deployment mode and traffic management requirements.
- Ingress routing with gateway injection and Istio APIs
-
When you install a gateway by using gateway injection, you can configure it to receive ingress traffic by using the Istio
GatewayandVirtualServiceresources in combination.
The gateway injection approach is compatible with sidecar-based service mesh deployments where you enable sidecar injection in namespaces by using the istio-injection=enabled label or the istio.io/rev=<revision> label.
- Ingress routing with Kubernetes Gateway API
-
The Kubernetes Gateway API provides a standardized approach for configuring ingress traffic routing using native Kubernetes resources. With this approach, you use
GatewayandHTTPRoute(orGRPCRoute) resources to configure how traffic enters the mesh and routes to services.
While Istio Gateway and VirtualService resources can be used for certain ingress use cases in ambient mode, the recommended approach is to use the Kubernetes Gateway API, which provides full support and integration with ambient. You can also use the Gateway API with sidecar-based deployments.
2.2. Exposing a service by using the Istio Gateway and VirtualService resources Copy linkLink copied to clipboard!
You can use the Istio Gateway and VirtualService resources to configure a gateway that was deployed by using gateway injection. The resources expose a service in the mesh to traffic outside the mesh. You can set the gateway Service type to LoadBalancer to allow traffic from outside the cluster.
Prerequisites
- You have installed Istio gateways using gateway injection.
-
You are using the Istio
GatewayandVirtualServiceresources. -
You have existing
VirtualServiceconfigurations and do not plan on migrating to ambient mode.
Procedure
Create namespace called
httpbinby running the following command:oc create namespace httpbin
$ oc create namespace httpbinCopy to Clipboard Copied! Toggle word wrap Toggle overflow Enable sidecar injection in the namespace. If you are using the
InPlaceupgrade strategy, run the following command:oc label namespace httpbin istio-injection=enabled
$ oc label namespace httpbin istio-injection=enabledCopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteIf you are using the
RevisionBasedupgrade strategy, run the following commands:To find your
<revision-name>, run the following command:oc get istiorevisions.sailoperator.io
$ oc get istiorevisions.sailoperator.ioCopy to Clipboard Copied! Toggle word wrap Toggle overflow You will get an output similar to the following example:
NAME TYPE READY STATUS IN USE VERSION AGE default Local True Healthy True v1.24.3 3m33s
NAME TYPE READY STATUS IN USE VERSION AGE default Local True Healthy True v1.24.3 3m33sCopy to Clipboard Copied! Toggle word wrap Toggle overflow Label the namespace with the revision name to enable sidecar injection:
oc label namespace httpbin istio.io/rev=default
$ oc label namespace httpbin istio.io/rev=defaultCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Deploy a sample service named
httpbinby running the following command:oc apply -n httpbin -f https://raw.githubusercontent.com/openshift-service-mesh/istio/refs/heads/master/samples/httpbin/httpbin.yaml
$ oc apply -n httpbin -f https://raw.githubusercontent.com/openshift-service-mesh/istio/refs/heads/master/samples/httpbin/httpbin.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a YAML file named
httpbin-gw.yamlthat defines an IstioGatewayresource. This resource configures gateway proxies to expose port 80 (HTTP) for the host,httpbin.example.com.Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Set the
selectorto the unique label or set of labels specified in the pod template of the gateway proxyDeployment. By default, the IstioGatewayresource configuration will apply to matching gateway pods in all namespaces. - 2
- Using the
hostsfield, specify a list of addresses that can be used by clients when attempting to access a mesh service at the associated port.
Apply the YAML file by running the following command:
oc apply -f httpbin-gw.yaml
$ oc apply -f httpbin-gw.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a YAML file named
httpbin-vs.yamlfor aVirtualService. TheVirtualServicedefines the rules that route traffic from the gateway proxy to thehttpbinservice.Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Specify the
hoststhat the routing rules of theVirtualServicewill be applied to. Thehostsspecified must be exposed by the IstioGatewayresource the VirtualService is bound to. - 2
- Bind the
VirtualServiceto the IstioGatewayresource created in the previous step by adding theGatewayname to the list of gateways. - 3
- Route matching traffic to the
httpbinservice deployed earlier by defining adestinationthat includes thehostandportof thehttpbinService.
Apply the YAML file by running the following command:
oc apply -f httpbin-vs.yaml
$ oc apply -f httpbin-vs.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow For verification purposes, create a namespace for a
curlclient by running the following command:oc create namespace curl
$ oc create namespace curlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Deploy the
curlclient by running the following command:oc apply -n curl -f https://raw.githubusercontent.com/openshift-service-mesh/istio/refs/heads/master/samples/curl/curl.yaml
$ oc apply -n curl -f https://raw.githubusercontent.com/openshift-service-mesh/istio/refs/heads/master/samples/curl/curl.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Set a
CURL_PODvariable with the name of thecurlpod by running the following command:CURL_POD=$(oc get pods -n curl -l app=curl -o jsonpath='{.items[*].metadata.name}')$ CURL_POD=$(oc get pods -n curl -l app=curl -o jsonpath='{.items[*].metadata.name}')Copy to Clipboard Copied! Toggle word wrap Toggle overflow Using the
curlclient, send a request to the/headersendpoint of thehttpbinapplication through the ingress gatewayServiceresource. Set theHostheader of the request tohttpbin.example.comto match the host that the IstioGatewayandVirtualServiceresources specify. Run the followingcurlcommand to send the request:oc exec $CURL_POD -n curl -- \ curl -s -I \ -H Host:httpbin.example.com \ <gateway_name>.<gateway_namespace>.svc.cluster.local/headers$ oc exec $CURL_POD -n curl -- \ curl -s -I \ -H Host:httpbin.example.com \ <gateway_name>.<gateway_namespace>.svc.cluster.local/headersCopy to Clipboard Copied! Toggle word wrap Toggle overflow The response should have a
200 OK HTTPstatus indicating that the request was successful.HTTP/1.1 200 OK server: istio-envoy ...
HTTP/1.1 200 OK server: istio-envoy ...Copy to Clipboard Copied! Toggle word wrap Toggle overflow Send a curl request to an endpoint that does not have a corresponding URI prefix match defined in the
httpbinVirtualServiceby running the following command:oc exec $CURL_POD -n curl -- \ curl -s -I \ -H Host:httpbin.example.com \ <gateway_name>.<gateway_namespace>.svc.cluster.local/get$ oc exec $CURL_POD -n curl -- \ curl -s -I \ -H Host:httpbin.example.com \ <gateway_name>.<gateway_namespace>.svc.cluster.local/getCopy to Clipboard Copied! Toggle word wrap Toggle overflow The response should return a
404 Not Foundstatus. This is expected because the/getendpoint does not have a matching URI prefix in thehttpbinVirtualServiceresource.HTTP/1.1 404 Not Found server: istio-envoy ...
HTTP/1.1 404 Not Found server: istio-envoy ...Copy to Clipboard Copied! Toggle word wrap Toggle overflow Expose the gateway proxy to traffic outside the cluster by setting the
Servicetype toLoadBalancer:oc patch service <gateway_name> -n <gateway_namespace> -p '{"spec": {"type": "LoadBalancer"}}'$ oc patch service <gateway_name> -n <gateway_namespace> -p '{"spec": {"type": "LoadBalancer"}}'Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteA gateway can also be exposed to traffic outside the cluster by using OpenShift Routes. For more information, see "Exposing a gateway to traffic outside the cluster using OpenShift Routes".
Verify that
httpbinservice can be accessed from outside the cluster when using the external hostname or IP address of the gatewayServiceresource. Ensure that you set theINGRESS_HOSTvariable appropriately for the environment that your cluster is running in.If the cluster runs on AWS, set the
INGRESS_HOSTvariable by running the following command:INGRESS_HOST=$(oc get service <gateway_name> -n <gateway_namespace> -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')$ INGRESS_HOST=$(oc get service <gateway_name> -n <gateway_namespace> -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')Copy to Clipboard Copied! Toggle word wrap Toggle overflow If the cluster runs on GCP or Azure, set the
INGRESS_HOSTvariable by running the following command:INGRESS_HOST=$(oc get service <gateway_name> -n <gateway_namespace> -o jsonpath='{.status.loadBalancer.ingress[0].ip}')$ INGRESS_HOST=$(oc get service <gateway_name> -n <gateway_namespace> -o jsonpath='{.status.loadBalancer.ingress[0].ip}')Copy to Clipboard Copied! Toggle word wrap Toggle overflow Send a
curlrequest to thehttpbinservice using the host of the gateway by running the following command:curl -s -I -H Host:httpbin.example.com http://$INGRESS_HOST/headers
$ curl -s -I -H Host:httpbin.example.com http://$INGRESS_HOST/headersCopy to Clipboard Copied! Toggle word wrap Toggle overflow
-
Verify that the response has the
HTTP/1.1 200 OKstatus, which indicates that the request was successful.
2.3. About exposing services to traffic outside a cluster Copy linkLink copied to clipboard!
To enable traffic from outside an OpenShift cluster to access services in a mesh, you must expose a gateway proxy by either setting its Service type to LoadBalancer or by using the OpenShift Router.
Using Kubernetes load balancing to handle incoming traffic directly through the inbound gateway can reduce latency associated with data encryption. By managing encryption at the inbound gateway, you avoid the intermediate decryption and re-encryption steps within the mesh that often add latency. This approach allows mesh traffic to be encrypted and decrypted only once, which is generally more efficient.
The OpenShift Router provides a standard approach for managing ingress traffic, and you can use the router to manage certificates for all cluster ingress traffic using the same methods. However, the OpenShift Router introduces an additional hop between the inbound traffic and the mesh applications. Typically, you route the traffic by decrypting it at the router and then re-encrypting it at the service mesh ingress gateway, which introduces latency.
2.3.1. Exposing a gateway to traffic outside the cluster by using OpenShift Routes Copy linkLink copied to clipboard!
You can expose a gateway to traffic outside the cluster by using OpenShift Routes. This approach provides an alternative to using Kubernetes load balancer service when you have to expose gateways to traffic outside the cluster.
Prerequisites
- You have completed the procedure, Exposing a Service by using the Istio Gateway and VirtualService resources.
Procedure
Ensure that the
Servicetype is set toClusterIPby running the following command:oc patch service <gateway_name> -n <gateway_namespace> -p '{"spec": {"type": "ClusterIP"}}'$ oc patch service <gateway_name> -n <gateway_namespace> -p '{"spec": {"type": "ClusterIP"}}'Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a YAML file named
httpbin-route.yamlthat defines aRoutefor thehttpbinservice.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Apply the YAML file by running the following command:
oc apply -f httpbin-route.yaml
$ oc apply -f httpbin-route.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that
httpbinservice can be accessed from outside the cluster through the ingress router. Ensure that you set theINGRESS_HOSTvariable appropriately for the environment that your cluster is running in.If the cluster runs on AWS, set the
INGRESS_HOSTvariable by running the following command:INGRESS_HOST=$(oc get service router-default -n openshift-ingress -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')$ INGRESS_HOST=$(oc get service router-default -n openshift-ingress -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')Copy to Clipboard Copied! Toggle word wrap Toggle overflow If the cluster runs on GCP or Azure, set the
INGRESS_HOSTvariable by running the following command:INGRESS_HOST=$(oc get service router-default -n openshift-ingress -o jsonpath='{.status.loadBalancer.ingress[0].ip}')$ INGRESS_HOST=$(oc get service router-default -n openshift-ingress -o jsonpath='{.status.loadBalancer.ingress[0].ip}')Copy to Clipboard Copied! Toggle word wrap Toggle overflow Send a
curlrequest to thehttpbinservice using the host of the ingress router by running the following command:curl -s -I -H Host:httpbin.example.com http://$INGRESS_HOST/headers
$ curl -s -I -H Host:httpbin.example.com http://$INGRESS_HOST/headersCopy to Clipboard Copied! Toggle word wrap Toggle overflow
-
Verify that the response has the
HTTP/1.1 200 OKstatus, which indicates that the request was successful.
2.4. Exposing a service by using the Kubernetes Gateway API in sidecar mode Copy linkLink copied to clipboard!
You can use the Kubernetes Gateway API to create Gateway and HTTPRoute resources and deploy a gateway. The resources configure the gateway to expose a service in the mesh to traffic outside the mesh.
Prerequisites
-
You are logged in to the OpenShift Container Platform web console as a user with the
cluster-adminrole. - You installed the Red Hat OpenShift Service Mesh Operator.
-
You have deployed the
Istioresource.
Procedure
Create a namespace called
httpbinby running the following command:oc create namespace httpbin
$ oc create namespace httpbinCopy to Clipboard Copied! Toggle word wrap Toggle overflow When using sidecar injection instead of ambient mode, you must enable the sidecar injection in the namespace:
For the
InPlaceupgrade strategy, run the following command:oc label namespace httpbin istio-injection=enabled
$ oc label namespace httpbin istio-injection=enabledCopy to Clipboard Copied! Toggle word wrap Toggle overflow For the
RevisionBasedupgrade strategy, run the following command:oc label namespace httpbin istio.io/rev=<revision-name>
$ oc label namespace httpbin istio.io/rev=<revision-name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Deploy a sample service named
httpbinby running the following command:oc apply -n httpbin -f https://raw.githubusercontent.com/openshift-service-mesh/istio/refs/heads/master/samples/httpbin/httpbin.yaml
$ oc apply -n httpbin -f https://raw.githubusercontent.com/openshift-service-mesh/istio/refs/heads/master/samples/httpbin/httpbin.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a YAML file named
httpbin-gw.yamlthat defines a Kubernetes Gateway resource, similar to the following example:Copy to Clipboard Copied! Toggle word wrap Toggle overflow "httpbin.example.com"- Specifies the virtual hostname that clients use when attempting to access a mesh service on the associated port.
The
HTTPRouteresource specifies the rules that route traffic from the gateway proxy to thehttpbinservice.Apply the YAML file by running the following command:
oc apply -f httpbin-gw.yaml
$ oc apply -f httpbin-gw.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a YAML file named
httpbin-ingress-hr.yamlthat defines anHTTPRouteresource for the ingress gateway, similar to the following example:Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
spec.parentRefsbinds theHTTPROUTEresource to the Kubernetes Gateway resource that was created in the earlier step. -
spec.rules.backendRefsroutes the matching traffic to thehttpbinservice by defining abackendRefsthat includes the name and port of thehttpbinservice.
The
HTTPRouteresource specifies the rules that route traffic from the gateway proxy to thehttpbinservice.-
Apply the YAML file by running the following command:
oc apply -f httpbin-ingress-hr.yaml
$ oc apply -f httpbin-ingress-hr.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Ensure that the Gateway API service is ready, and that an address is allocated to the service, by running the following command:
oc wait --for=condition=programmed gtw httpbin-gateway -n httpbin
$ oc wait --for=condition=programmed gtw httpbin-gateway -n httpbinCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Create a namespace for a
curlclient by running the following command:oc create namespace curl
$ oc create namespace curlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Deploy a
curlclient by running the following command:oc apply -n curl -f https://raw.githubusercontent.com/openshift-service-mesh/istio/refs/heads/master/samples/curl/curl.yaml
$ oc apply -n curl -f https://raw.githubusercontent.com/openshift-service-mesh/istio/refs/heads/master/samples/curl/curl.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Set a
CURL_PODvariable with the name of thecurlpod by running the following command:CURL_POD=$(oc get pods -n curl -l app=curl -o jsonpath='{.items[*].metadata.name}')$ CURL_POD=$(oc get pods -n curl -l app=curl -o jsonpath='{.items[*].metadata.name}')Copy to Clipboard Copied! Toggle word wrap Toggle overflow Using the
curlclient, send a request to the/headersendpoint of thehttpbinapplication through the ingress gatewayServiceresource. Set the Host header of the request tohttpbin.example.comto match the host that the Kubernetes Gateway andHTTPROUTEresources specify. Send thecurlrequest by running the following command:oc exec $CURL_POD -n curl -- \ curl -s -I \ -H Host:httpbin.example.com \ <gateway_name>-istio.<gateway_namespace>.svc.cluster.local/headers$ oc exec $CURL_POD -n curl -- \ curl -s -I \ -H Host:httpbin.example.com \ <gateway_name>-istio.<gateway_namespace>.svc.cluster.local/headersCopy to Clipboard Copied! Toggle word wrap Toggle overflow The response should return a
200 OKHTTP status, which indicates that the request was successful, similar to the following example:HTTP/1.1 200 OK server: istio-envoy ...
HTTP/1.1 200 OK server: istio-envoy ...Copy to Clipboard Copied! Toggle word wrap Toggle overflow Send a
curlrequest to an endpoint that does not have a corresponding Uniform Resource Identifier (URI) prefix match defined in thehttpbinHTTPROUTEby running the following command:oc exec $CURL_POD -n curl -- \ curl -s -I \ -H Host:httpbin.example.com \ <gateway_name>-istio.<gateway_namespace>.svc.cluster.local/get$ oc exec $CURL_POD -n curl -- \ curl -s -I \ -H Host:httpbin.example.com \ <gateway_name>-istio.<gateway_namespace>.svc.cluster.local/getCopy to Clipboard Copied! Toggle word wrap Toggle overflow The response returns a
404 Not Foundstatus, as expected, because the/getendpoint does not have a matching URI prefix in thehttpbinHTTPROUTEresource, similar to the following example:HTTP/1.1 404 Not Found server: istio-envoy ...
HTTP/1.1 404 Not Found server: istio-envoy ...Copy to Clipboard Copied! Toggle word wrap Toggle overflow Expose the gateway proxy to traffic outside the cluster by setting the
Servicetype toLoadBalancer. Run the following command:oc patch service <gateway_name>-istio -n <gateway_namespace> -p '{"spec": {"type": "LoadBalancer"}}'$ oc patch service <gateway_name>-istio -n <gateway_namespace> -p '{"spec": {"type": "LoadBalancer"}}'Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteA gateway can also be exposed to traffic outside the cluster by using OpenShift Routes. For more information, see "Exposing a gateway to traffic outside the cluster using OpenShift Routes".
Verify that the
httpbinservice can be accessed from outside the cluster when using the external hostname or IP address of the gateway Service resource. Ensure that you set theINGRESS_HOSTvariable appropriately for the environment in which your cluster is running.Set the
INGRESS_HOSTvariable by running the following command:export INGRESS_HOST=$(oc get gtw <gateway_name> -n <gateway_namespace> -o jsonpath='{.status.addresses[0].value}')$ export INGRESS_HOST=$(oc get gtw <gateway_name> -n <gateway_namespace> -o jsonpath='{.status.addresses[0].value}')Copy to Clipboard Copied! Toggle word wrap Toggle overflow Set the
INGRESS_PORTvariable by running the following command:INGRESS_PORT=$(oc get gtw <gateway_name> -n <gateway_namespace> -o jsonpath='{.spec.listeners[?(@.name=="http")].port}')$ INGRESS_PORT=$(oc get gtw <gateway_name> -n <gateway_namespace> -o jsonpath='{.spec.listeners[?(@.name=="http")].port}')Copy to Clipboard Copied! Toggle word wrap Toggle overflow Using the gateway host, send a
curlrequest to thehttpbinservice by running the following command:curl -s -I -H Host:httpbin.example.com http://$INGRESS_HOST:$INGRESS_PORT/headers
$ curl -s -I -H Host:httpbin.example.com http://$INGRESS_HOST:$INGRESS_PORT/headersCopy to Clipboard Copied! Toggle word wrap Toggle overflow
-
Verify that the response has the
HTTP/1.1 200 OKstatus, which indicates that the request was successful.
2.5. About ingress traffic routing approaches in ambient mode Copy linkLink copied to clipboard!
When using the Istio ambient mode, you can use the Kubernetes Gateway API to configure ingress traffic routing.
- Waypoint proxies for Layer 7 routing
-
You can deploy a waypoint proxy in the namespace that has your service to apply Layer 7 (L7) routing policies, such as path-based routing or header matching. In ambient mode, waypoint proxies process L7 traffic and enforce
HTTPRouteandGRPCRouterules.
VirtualService resources are considered technology preview in ambient mode and should not be mixed with Gateway API configuration. The recommended approach in ambient mode is to use Kubernetes Gateway API resources.
2.6. Exposing a service by using the Kubernetes Gateway API in ambient mode Copy linkLink copied to clipboard!
You can use the Kubernetes Gateway API to create Gateway and HTTPRoute resources and deploy a gateway in ambient mode. The resources configure the gateway to expose a service in the mesh to traffic outside the mesh.
Prerequisites
-
You are logged in to the OpenShift Container Platform web console as a user with the
cluster-adminrole. - You have installed the Red Hat OpenShift Service Mesh Operator.
-
You have deployed the
Istioresource. - You use the Kubernetes-native Gateway API resources.
- You are either using the Istio ambient mode or planning on migrating to the ambient mode.
When using ambient mode (istio.io/dataplane-mode=ambient), it is recommended to use the Kubernetes Gateway API for ingress configuration, as Istio Gateway and VirtualService resources are not fully compatible with ambient mode.
Procedure
Create a namespace called
httpbinby running the following command:oc create namespace httpbin
$ oc create namespace httpbinCopy to Clipboard Copied! Toggle word wrap Toggle overflow Apply the label for ambient mode by running the following command:
oc label namespace httpbin istio.io/dataplane-mode=ambient
$ oc label namespace httpbin istio.io/dataplane-mode=ambientCopy to Clipboard Copied! Toggle word wrap Toggle overflow Deploy a sample service named
httpbinby running the following command:oc apply -n httpbin -f https://raw.githubusercontent.com/openshift-service-mesh/istio/refs/heads/master/samples/httpbin/httpbin.yaml
$ oc apply -n httpbin -f https://raw.githubusercontent.com/openshift-service-mesh/istio/refs/heads/master/samples/httpbin/httpbin.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Deploy a waypoint proxy by creating a YAML file named
httpbin-waypoint.yaml, similar to the following example:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Apply the YAML file by running the following command:
oc apply -f httpbin-waypoint.yaml
$ oc apply -f httpbin-waypoint.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Enable ingress waypoint routing on the
httpbinservice by running the following command:oc label service httpbin -n httpbin istio.io/ingress-use-waypoint=true
$ oc label service httpbin -n httpbin istio.io/ingress-use-waypoint=trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow The label ensures that traffic from the ingress gateway routes through the waypoint proxy and the Layer 7 (L7) policies configured on the waypoint proxy are applied to the ingress traffic, before it reaches the
httpbinservice.Apply the waypoint label to the namespace so that all the services inside the namespace routes through the waypoint, by running the following command:
oc label ns httpbin istio.io/use-waypoint=httpbin-waypoint
$ oc label ns httpbin istio.io/use-waypoint=httpbin-waypointCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a YAML file named
httpbin-gw.yamlthat defines a Kubernetes Gateway resource. This resource configures gateway proxies to expose port 80 (HTTP) for the host,httpbin.example.com.Copy to Clipboard Copied! Toggle word wrap Toggle overflow "httpbin.example.com"- Specifies the virtual hostname that clients use when attempting to access a mesh service on the associated port.
Apply the YAML file by running the following command:
oc apply -f httpbin-gw.yaml
$ oc apply -f httpbin-gw.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a YAML file named
httpbin-ingress-hr.yamlthat defines anHTTPRouteresource for the ingress gateway, similar to the following example:Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
spec.parentRefsbinds theHTTPROUTEresource to the Kubernetes Gateway resource that was created in the earlier step. -
spec.rules.backendRefsroutes the matching traffic to thehttpbinservice by defining abackendRefsthat includes the name and port of thehttpbinservice.
The
HTTPRouteresource specifies the rules that route traffic from the gateway proxy to thehttpbinservice.-
Apply the YAML file by running the following command:
oc apply -f httpbin-ingress-hr.yaml
$ oc apply -f httpbin-ingress-hr.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a YAML file named
httpbin-waypoint-hr.yamlthat defines anHTTPRouteresource for the waypoint proxy.Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
spec.parentRefsbinds theHTTPRouteresource to thehttpbinservice. When combined with theistio.io/ingress-use-waypoint=truelabel on the service, theHTTPRouteconfigures the L7 routing rules that the waypoint proxy will enforce for traffic destined to that service. -
spec.rules.backendRefsroutes the matching traffic to thehttpbinservice by defining abackendRefsthat includes the name and port of thehttpbinservice.
-
Apply the YAML file by running the following command:
oc apply -f httpbin-waypoint-hr.yaml
$ oc apply -f httpbin-waypoint-hr.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteIn this example use case, traffic from the ingress gateway flows through the waypoint proxy because of the
istio.io/ingress-use-waypoint=truelabel. TheHTTPRouteresource then applies path-based routing policies before the traffic reaches the httpbin service.Ensure that the waypoint proxy is ready by running the following command:
oc wait --for=condition=programmed gtw httpbin-waypoint -n httpbin
$ oc wait --for=condition=programmed gtw httpbin-waypoint -n httpbinCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Create a namespace for a
curlclient by running the following command:oc create namespace curl
$ oc create namespace curlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Deploy a
curlclient by running the following command:oc apply -n curl -f https://raw.githubusercontent.com/openshift-service-mesh/istio/refs/heads/master/samples/curl/curl.yaml
$ oc apply -n curl -f https://raw.githubusercontent.com/openshift-service-mesh/istio/refs/heads/master/samples/curl/curl.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Apply the label for ambient mode to the
curlnamespace by running the following command:oc label namespace curl istio.io/dataplane-mode=ambient
$ oc label namespace curl istio.io/dataplane-mode=ambientCopy to Clipboard Copied! Toggle word wrap Toggle overflow Set a
CURL_PODvariable with the name of thecurlpod by running the following command:CURL_POD=$(oc get pods -n curl -l app=curl -o jsonpath='{.items[*].metadata.name}')$ CURL_POD=$(oc get pods -n curl -l app=curl -o jsonpath='{.items[*].metadata.name}')Copy to Clipboard Copied! Toggle word wrap Toggle overflow Using the
curlclient, send a request to the/headersendpoint of thehttpbinapplication through the ingress gatewayServiceresource. Set the Host header of the request tohttpbin.example.comto match the host that the Kubernetes Gateway andHTTPROUTEresources specify. Send thecurlrequest by running the following command:oc exec $CURL_POD -n curl -- \ curl -s -I \ -H Host:httpbin.example.com \ httpbin-gateway-istio.httpbin.svc.cluster.local/headers$ oc exec $CURL_POD -n curl -- \ curl -s -I \ -H Host:httpbin.example.com \ httpbin-gateway-istio.httpbin.svc.cluster.local/headersCopy to Clipboard Copied! Toggle word wrap Toggle overflow The response should return a
200 OKHTTP status, which indicates that the request was successful, similar to the following example:HTTP/1.1 200 OK server: istio-envoy ...
HTTP/1.1 200 OK server: istio-envoy ...Copy to Clipboard Copied! Toggle word wrap Toggle overflow Send a
curlrequest to an endpoint that does not have a corresponding Uniform Resource Identifier (URI) prefix match defined in thehttpbinHTTPROUTEby running the following command:oc exec $CURL_POD -n curl -- \ curl -s -I \ -H Host:httpbin.example.com \ httpbin-gateway-istio.httpbin.svc.cluster.local/get$ oc exec $CURL_POD -n curl -- \ curl -s -I \ -H Host:httpbin.example.com \ httpbin-gateway-istio.httpbin.svc.cluster.local/getCopy to Clipboard Copied! Toggle word wrap Toggle overflow The response returns a
404 Not Foundstatus, as expected, because the/getendpoint does not have a matching URI prefix in thehttpbinHTTPROUTEresource, similar to the following example:HTTP/1.1 404 Not Found server: istio-envoy ...
HTTP/1.1 404 Not Found server: istio-envoy ...Copy to Clipboard Copied! Toggle word wrap Toggle overflow Expose the gateway proxy to traffic outside the cluster by setting the
Servicetype toLoadBalancer. Run the following command:oc patch service httpbin-gateway-istio -n httpbin -p '{"spec": {"type": "LoadBalancer"}}'$ oc patch service httpbin-gateway-istio -n httpbin -p '{"spec": {"type": "LoadBalancer"}}'Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteA gateway can also be exposed to traffic outside the cluster by using OpenShift Routes. For more information, see "Exposing a gateway to traffic outside the cluster using OpenShift Routes".
Verify that the
httpbinservice can be accessed from outside the cluster when using the external hostname or IP address of the gateway Service resource. Ensure that you set theINGRESS_HOSTvariable appropriately for the environment in which your cluster is running.Set the
INGRESS_HOSTvariable by running the following command:export INGRESS_HOST=$(oc get gtw httpbin-gateway -n httpbin -o jsonpath='{.status.addresses[0].value}')$ export INGRESS_HOST=$(oc get gtw httpbin-gateway -n httpbin -o jsonpath='{.status.addresses[0].value}')Copy to Clipboard Copied! Toggle word wrap Toggle overflow Set the
INGRESS_PORTvariable by running the following command:INGRESS_PORT=$(oc get gtw httpbin-gateway -n httpbin -o jsonpath='{.spec.listeners[?(@.name=="http")].port}')$ INGRESS_PORT=$(oc get gtw httpbin-gateway -n httpbin -o jsonpath='{.spec.listeners[?(@.name=="http")].port}')Copy to Clipboard Copied! Toggle word wrap Toggle overflow Using the gateway host, send a
curlrequest to thehttpbinservice by running the following command:curl -s -I -H Host:httpbin.example.com http://$INGRESS_HOST:$INGRESS_PORT/headers
$ curl -s -I -H Host:httpbin.example.com http://$INGRESS_HOST:$INGRESS_PORT/headersCopy to Clipboard Copied! Toggle word wrap Toggle overflow
-
Verify that the response has the
HTTP/1.1 200 OKstatus, which indicates that the request was successful.
Chapter 3. Directing outbound traffic through a gateway Copy linkLink copied to clipboard!
Using Istio APIs, you can configure gateway proxies that were installed using gateway injection to direct traffic that is bound for an external service.
3.1. About directing egress traffic through a gateway Copy linkLink copied to clipboard!
You can configure a gateway installed through gateway injection as an exit point for traffic leaving the service mesh. It acts as a forward proxy for requests sent to services external to the mesh.
- Egress gateway
An egress gateway is configured as an exit point for traffic leaving the service mesh, acting as a forward proxy for requests sent to external services. You can configure an egress gateway to fulfill security requirements:
- Traffic Restrictions: In environments with strict traffic restrictions, an egress gateway ensures all outbound traffic flows through a dedicated set of nodes.
- Network Policy Enforcement: When network policies prevent application nodes from directly accessing external services, the egress gateway handles the external access.
In these scenarios, gateway proxies are deployed on dedicated egress nodes capable of accessing external services. These nodes can then be subjected to strict network policy enforcement or additional monitoring to enhance security.
- Configure egress traffic
You can configure a gateway installed through gateway injection to direct the egress traffic by combining the following Istio resources:
-
Use the
ServiceEntryresource to define the properties of an external service. The external service is added to the Istio service registry for the mesh, which enables you to apply Istio features, such as monitoring and routing rules, to the traffic exiting the mesh that is destined for an external service. -
Use the
Gateway,VirtualService, andDestinationRuleresources to set up rules that route traffic from the mesh to the external service using the gateway proxy.
-
Use the
- Egress routing in ambient mode
If your deployment uses ambient mode, you must configure egress routing using the Kubernetes Gateway API instead of Istio
GatewayandVirtualServiceresources. The Kubernetes Gateway API provides a standardized, Kubernetes-native method for defining how traffic exits the mesh and reaches external services.You can use
GatewayandHTTPRoute(orGRPCRoute) resources to control how mesh traffic is routed to destinations outside the cluster. The Gateway API is fully supported in ambient mode and can also be used with sidecar-based deployments, providing a consistent configuration model for both ingress and egress routing.
3.2. Directing egress traffic through a gateway using Istio APIs Copy linkLink copied to clipboard!
Use Istio APIs to direct outbound HTTP traffic through a gateway that was installed using gateway injection.
Prerequisites
- You have installed a gateway using gateway injection.
Procedure
Create a namespace called
curlby running the following command:oc create namespace curl
$ oc create namespace curlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Depending on the update strategy you are using, enable sidecar injection in the namespace by running the appropriate commands:
If you are using the
InPlaceupdate strategy, run the following command:oc label namespace curl istio-injection=enabled
$ oc label namespace curl istio-injection=enabledCopy to Clipboard Copied! Toggle word wrap Toggle overflow If you are using the
RevisionBasedupdate strategy, run the following commands:Display the revision name by running the following command:
oc get istiorevisions.sailoperator.io
$ oc get istiorevisions.sailoperator.ioCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
NAME TYPE READY STATUS IN USE VERSION AGE default Local True Healthy True v1.24.3 3m33s
NAME TYPE READY STATUS IN USE VERSION AGE default Local True Healthy True v1.24.3 3m33sCopy to Clipboard Copied! Toggle word wrap Toggle overflow Label the namespace with the revision name to enable sidecar injection by running the following command:
oc label namespace curl istio.io/rev=default
$ oc label namespace curl istio.io/rev=defaultCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Deploy a
curlapplication by running the following command:oc apply -n curl -f https://raw.githubusercontent.com/openshift-service-mesh/istio/refs/heads/master/samples/curl/curl.yaml
$ oc apply -n curl -f https://raw.githubusercontent.com/openshift-service-mesh/istio/refs/heads/master/samples/curl/curl.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Export a
CURL_PODenvironment variable that has been initialized with the name of the curl pod:export CURL_POD=$(oc get pod -n curl -l app=curl -o jsonpath='{.items[0].metadata.name}')$ export CURL_POD=$(oc get pod -n curl -l app=curl -o jsonpath='{.items[0].metadata.name}')Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a YAML file named
http-se.yamlthat directs traffic from the mesh to an external service. The following example defines aServiceEntryfor a URL.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Apply the YAML file by running the following command:
oc apply -f http-se.yaml
$ oc apply -f http-se.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Ensure the
ServiceEntryconfiguration was applied correctly. Send an HTTP request to the host that you specified in the previous step by running the following command:oc exec "$CURL_POD" -n curl -c curl -- curl -sSL -o /dev/null -D - http://docs.redhat.com
$ oc exec "$CURL_POD" -n curl -c curl -- curl -sSL -o /dev/null -D - http://docs.redhat.comCopy to Clipboard Copied! Toggle word wrap Toggle overflow This command should return HTTP status codes, such as
301(redirect) or200(success), indicating that the connection works.Create a YAML file named
http-gtw.yamlthat creates an egressGatewayand routes traffic from the mesh to the host specified for the external service.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Apply the YAML file by running the following command:
oc apply -f http-gtw.yaml
$ oc apply -f http-gtw.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a YAML file named
http-vs.yamlthat sets up aVirtualServiceto manage the flow of traffic from the application sidecars through the egress gateway to the external host.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Apply the YAML file by running the following command:
oc apply -f http-vs.yaml
$ oc apply -f http-vs.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Resend the HTTP request to the URL:
oc exec "$CURL_POD" -n curl -c curl -- curl -sSL -o /dev/null -D - http://docs.redhat.com
$ oc exec "$CURL_POD" -n curl -c curl -- curl -sSL -o /dev/null -D - http://docs.redhat.comCopy to Clipboard Copied! Toggle word wrap Toggle overflow The terminal should display information similar to the following output:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Ensure that the request was routed through the gateway by running the following command:
oc logs deployment/<gateway_name> -n <gateway_namespace> | tail -1
$ oc logs deployment/<gateway_name> -n <gateway_namespace> | tail -1Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteAccess logging must be enabled for this verification step to work. You can enable access logging to the standard output by setting the
spec.values.meshConfig.accessLogFilefield to/dev/stdoutin the Istio resource.The terminal should display information similar to the following output:
[2024-11-07T14:35:52.428Z] "GET / HTTP/2" 301 - via_upstream - "-" 0 0 24 24 "10.128.2.30" "curl/8.11.0" "79551af2-341b-456d-b414-9220b487a03b" "docs.redhat.com" "23.55.176.201:80" outbound|80||docs.redhat.com 10.128.2.29:49766 10.128.2.29:80 10.128.2.30:38296 -
[2024-11-07T14:35:52.428Z] "GET / HTTP/2" 301 - via_upstream - "-" 0 0 24 24 "10.128.2.30" "curl/8.11.0" "79551af2-341b-456d-b414-9220b487a03b" "docs.redhat.com" "23.55.176.201:80" outbound|80||docs.redhat.com 10.128.2.29:49766 10.128.2.29:80 10.128.2.30:38296 -Copy to Clipboard Copied! Toggle word wrap Toggle overflow
3.3. Directing egress traffic through a gateway by using the Kubernetes Gateway API Copy linkLink copied to clipboard!
Use the Kubernetes Gateway API to direct outbound HTTP traffic through an egress gateway.
Prerequisites
- You installed an Istio control plane.
-
You configured the
IstioandIstioCNIresources.
Procedure
Optional: Enable the Kubernetes Gateway API custom resource definitions (CRDs).
NoteAs of Kubernetes 1.28 and OpenShift Container Platform 4.18 or earlier version of Red Hat OpenShift Service Mesh, the Kubernetes Gateway API CRDs are not available by default and you must install the CRDs before you can use them. OpenShift Container Platform 4.19 and later versions install the CRDs by default.
Create a YAML file named
gateway-cr.yamlthat enables the Kubernetes Gateway API CRDs.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Apply the YAML file by running the following command:
oc apply -f gateway-cr.yaml
$ oc apply -f gateway-cr.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Create a namespace called
egress-gatewayby running the following command:oc create namespace egress-gateway
$ oc create namespace egress-gatewayCopy to Clipboard Copied! Toggle word wrap Toggle overflow Apply the
istio-injectionlabel to the namespace by running the following command:oc label namespace egress-gateway istio-injection=enabled
$ oc label namespace egress-gateway istio-injection=enabledCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a YAML file named
egress-gateway-cr.yamlthat defines the egress gateway.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Apply the YAML file by running the following command:
oc apply -f egress-gateway-cr.yaml
$ oc apply -f egress-gateway-cr.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Verify the status of the gateway configuration by running the following command:
oc describe gateway -n egress-gateway
$ oc describe gateway -n egress-gatewayCopy to Clipboard Copied! Toggle word wrap Toggle overflow Desired output is indicated by
Programmedshowing in theStatuscolumn.Create a
curlpod in theegress-gatewaynamespace by running the following command:oc run test-pod --image=curlimages/curl:latest -n egress-gateway --rm -it --restart=Never -- sh
$ oc run test-pod --image=curlimages/curl:latest -n egress-gateway --rm -it --restart=Never -- shCopy to Clipboard Copied! Toggle word wrap Toggle overflow By using the
curlclient, verify that you can accesshttpbin.orgthrough the egress gateway by entering following command:curl -v http://httpbin.org/get
$ curl -v http://httpbin.org/getCopy to Clipboard Copied! Toggle word wrap Toggle overflow Desired output shows a response from
httpbin.orgthat indicates egress traffic routes through the configured gateway.
3.4. Directing egress traffic through a gateway using the Kubernetes Gateway API in ambient mode Copy linkLink copied to clipboard!
Use the Kubernetes Gateway API and waypoint proxy to direct outbound HTTP traffic through an egress gateway.
Prerequisites
- You have installed the OpenShift Service Mesh Operator version 3.2 or later.
-
You configured the
IstioandIstioCNIresources with ambient profile. -
You have created a
Ztunnelresource.
Procedure
Optional: Enable the {k8} Gateway API custom resource definitions (CRDs).
NoteAs of Kubernetes 1.28 and OpenShift Container Platform 4.18 or earlier version of Red Hat OpenShift Service Mesh, the Kubernetes Gateway API CRDs are not available by default and you must install the CRDs before you can use them. OpenShift Container Platform 4.19 and later versions install the CRDs by default.
Create a namespace called
egress-gatewayby running the following command:oc create namespace egress-gateway
$ oc create namespace egress-gatewayCopy to Clipboard Copied! Toggle word wrap Toggle overflow Apply the ambient mode label to the namespace by running the following command:
oc label namespace egress-gateway istio.io/dataplane-mode=ambient
$ oc label namespace egress-gateway istio.io/dataplane-mode=ambientCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a YAML file named
egress-se.yamlthat defines theServiceEntry.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Apply the YAML file by running the following command:
oc apply -f egress-se.yaml
$ oc apply -f egress-se.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a YAML file named
waypoint.yamlthat creates a waypoint proxy inegress-gatewaynamespace similar to the following example:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Apply the YAML file by running the following command:
oc apply -f waypoint.yaml
$ oc apply -f waypoint.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
As an alternate to creating the waypoint.yaml YAML file, you can also set up waypoint proxy by running the following command:
istioctl waypoint apply --enroll-namespace --name waypoint --namespace egress-gateway
$ istioctl waypoint apply --enroll-namespace --name waypoint --namespace egress-gateway
When you use the --enroll-namespace option, all services in the egress-gateway namespace (including ServiceEntries), will route their traffic through the waypoint.
Verification
Verify the status of the gateway configuration by running the following command:
oc get gateways.gateway.networking.k8s.io waypoint -n egress-gateway
$ oc get gateways.gateway.networking.k8s.io waypoint -n egress-gatewayCopy to Clipboard Copied! Toggle word wrap Toggle overflow The
PROGRAMMEDcolumn showsTruewhen the configuration succeeds, similar to the following example:NAME CLASS ADDRESS PROGRAMMED AGE waypoint istio-waypoint 172.30.227.148 True 9s
NAME CLASS ADDRESS PROGRAMMED AGE waypoint istio-waypoint 172.30.227.148 True 9sCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a
curlpod in theegress-gatewaynamespace by running the following command:oc run test-pod --image=curlimages/curl:latest -n egress-gateway --rm -it --restart=Never -- sh
$ oc run test-pod --image=curlimages/curl:latest -n egress-gateway --rm -it --restart=Never -- shCopy to Clipboard Copied! Toggle word wrap Toggle overflow By using the
curlclient, verify that you can accesshttpbin.orgthrough the egress gateway by running the following command:curl -v http://httpbin.org/get
$ curl -v http://httpbin.org/getCopy to Clipboard Copied! Toggle word wrap Toggle overflow The output shows a response from
httpbin.orgservice that indicates egress traffic routes through the configured gateway. The ztunnel logs should show traffic routed through the waypoint. The terminal should display information similar to the following output:2025-10-24T08:08:35.242159Z info access connection complete src.addr=[fd01:0:0:5::b0]:56288 src.workload="test-pod" src.namespace="egress-gateway" src.identity="spiffe://cluster.local/ns/egress-gateway/sa/default" dst.addr=[fd01:0:0:5::af]:15008 dst.hbone_addr=[2001:2::2]:80 dst.service="httpbin.org" dst.workload="waypoint-5b668759d5-vrnx8" dst.namespace="egress-gateway" dst.identity="spiffe://cluster.local/ns/egress-gateway/sa/waypoint" direction="outbound" bytes_sent=78 bytes_recv=540 duration="957ms"
2025-10-24T08:08:35.242159Z info access connection complete src.addr=[fd01:0:0:5::b0]:56288 src.workload="test-pod" src.namespace="egress-gateway" src.identity="spiffe://cluster.local/ns/egress-gateway/sa/default" dst.addr=[fd01:0:0:5::af]:15008 dst.hbone_addr=[2001:2::2]:80 dst.service="httpbin.org" dst.workload="waypoint-5b668759d5-vrnx8" dst.namespace="egress-gateway" dst.identity="spiffe://cluster.local/ns/egress-gateway/sa/waypoint" direction="outbound" bytes_sent=78 bytes_recv=540 duration="957ms"Copy to Clipboard Copied! Toggle word wrap Toggle overflow