이 콘텐츠는 선택한 언어로 제공되지 않습니다.
Chapter 2. Getting traffic into a mesh
Route external traffic to mesh services by configuring Istio gateway proxies and exposing them through LoadBalancer services or OpenShift routes.
2.1. About ingress traffic routing approaches 링크 복사링크가 클립보드에 복사되었습니다!
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 support 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 링크 복사링크가 클립보드에 복사되었습니다!
Expose mesh services to external traffic by configuring injected gateways with Istio Gateway and VirtualService resources to route traffic from outside the cluster.
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 httpbinEnable sidecar injection in the namespace. If you are using the
InPlaceupgrade strategy, run the following command:$ oc label namespace httpbin istio-injection=enabledNoteIf you are using the
RevisionBasedupgrade strategy, run the following commands:To find your
<revision-name>, run the following command:$ oc get istiorevisions.sailoperator.ioYou should see output similar to the following example:
NAME TYPE READY STATUS IN USE VERSION AGE default Local True Healthy True v1.24.3 3m33sLabel the namespace with the revision name to enable sidecar injection:
$ oc label namespace httpbin istio.io/rev=default
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.yamlCreate 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.You can see the following example configuration for reference:
apiVersion: networking.istio.io/v1 kind: Gateway metadata: name: httpbin-gateway namespace: httpbin spec: selector: istio: <gateway_name> servers: - port: number: 80 name: http protocol: HTTP hosts: - httpbin.example.com-
spec.selectorspecifies the unique label or set of labels in the pod template of the gateway proxyDeployment. By default, the IstioGatewayresource configuration will apply to matching gateway pods in all namespaces. -
spec.servers.hostsspecifies a list of addresses that the clients use 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.yamlCreate a YAML file named
httpbin-vs.yamlfor aVirtualService. TheVirtualServicedefines the rules that route traffic from the gateway proxy to thehttpbinservice.You can see the following example configuration for reference:
apiVersion: networking.istio.io/v1 kind: VirtualService metadata: name: httpbin namespace: httpbin spec: hosts: - httpbin.example.com gateways: - httpbin-gateway http: - match: - uri: prefix: /status - uri: prefix: /headers route: - destination: port: number: 8000 host: httpbin-
spec.hoststhe destinationhostsfor theVirtualServicerouting rules. The IstioGatewayresource must expose the hosts that you bind to theVirtualService. -
spec.gatewaysbinds theVirtualServiceto the IstioGatewayresource created in the previous step by adding theGatewayname to the list of gateways. -
spec.http.routeroute matching traffic to thehttpbinservice deployed earlier by defining adestinationthat includes thehostandportof thehttpbinService.
-
Apply the YAML file by running the following command:
$ oc apply -f httpbin-vs.yamlFor verification purposes, create a namespace for a
curlclient by running the following command:$ oc create namespace curlDeploy 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.yamlSet 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}')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/headersThe response should have a
200 OK HTTPstatus indicating that the request was successful.HTTP/1.1 200 OK server: istio-envoy ...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/getThe response should return a
404 Not Foundstatus as thehttpbinVirtualServiceresource lacks a matching URI prefix for the/getendpoint.HTTP/1.1 404 Not Found server: istio-envoy ...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"}}'NoteOpenShift Routes can also expose a gateway to traffic outside the cluster. For more information, see "Exposing a gateway to traffic outside the cluster using OpenShift Routes".
Verify that you can access the
httpbinservice 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}')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}')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
-
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 링크 복사링크가 클립보드에 복사되었습니다!
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 encrypts and decrypts mesh traffic 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 by 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 링크 복사링크가 클립보드에 복사되었습니다!
You can expose a gateway to traffic outside the cluster by using OpenShift Routes. This approach provides an alternative to using Kubernetes LoadBalancer 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
GatewayandVirtualServiceresources".
Procedure
Ensure that you set the
Servicetype toClusterIPby running the following command:$ oc patch service <gateway_name> -n <gateway_namespace> -p '{"spec": {"type": "ClusterIP"}}'Create a YAML file named
httpbin-route.yamlthat defines aRoutefor thehttpbinservice similar to the following example:apiVersion: route.openshift.io/v1 kind: Route metadata: name: httpbin namespace: <gateway_namespace> spec: host: httpbin.example.com port: targetPort: http2 to: kind: Service name: <gateway_name> weight: 100 wildcardPolicy: NoneApply the YAML file by running the following command:
$ oc apply -f httpbin-route.yamlVerify that you can access the
httpbinservice 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}')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}')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
-
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 링크 복사링크가 클립보드에 복사되었습니다!
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 have 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 httpbinWhen 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=enabledFor the
RevisionBasedupgrade strategy, run the following command:$ oc label namespace httpbin istio.io/rev=<revision-name>
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.yamlCreate a YAML file named
httpbin-gw.yamlthat defines a Kubernetes Gateway resource, similar to the following example:apiVersion: gateway.networking.k8s.io/v1 kind: Gateway metadata: name: httpbin-gateway namespace: httpbin spec: gatewayClassName: istio listeners: - name: default hostname: "httpbin.example.com" port: 80 protocol: HTTP allowedRoutes: namespaces: from: All"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.yamlCreate a YAML file named
httpbin-ingress-hr.yamlthat defines anHTTPRouteresource for the ingress gateway, similar to the following example:apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: httpbin-ingress namespace: httpbin spec: parentRefs: - name: httpbin-gateway namespace: httpbin hostnames: - "httpbin.example.com" rules: - matches: - path: type: PathPrefix value: /status - path: type: PathPrefix value: /headers - backendRefs: - name: httpbin port: 8000-
spec.parentRefsbinds theHTTPROUTEresource to the KubernetesGatewayresource you created in the previous 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.yamlEnsure that the Gateway API service is ready and has an allocated address by running the following command:
$ oc wait --for=condition=programmed gtw httpbin-gateway -n httpbin
Verification
Create a namespace for a
curlclient by running the following command:$ oc create namespace curlDeploy 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.yamlSet 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}')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/headersThe 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 ...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/getThe 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 ...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"}}'NoteOpenShift Routes can also expose a gateway to traffic outside the cluster. For more information, see "Exposing a gateway to traffic outside the cluster using OpenShift Routes".
Verify that you can access the
httpbinservice 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}')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}')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
-
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 링크 복사링크가 클립보드에 복사되었습니다!
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.
Service Mesh classifies VirtualService resources as Technology Preview (TP) in ambient mode. Therefore, you should not mix them 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 링크 복사링크가 클립보드에 복사되었습니다!
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 have 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.
Service Mesh recommends the Kubernetes Gateway API for ingress configuration in ambient mode (istio.io/dataplane-mode=ambient), because Istio Gateway and VirtualService resources lack full compatibility.
Procedure
Create a namespace called
httpbinby running the following command:$ oc create namespace httpbinApply the label for ambient mode by running the following command:
$ oc label namespace httpbin istio.io/dataplane-mode=ambientDeploy 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.yamlDeploy a waypoint proxy by creating a YAML file named
httpbin-waypoint.yaml, similar to the following example:apiVersion: gateway.networking.k8s.io/v1 kind: Gateway metadata: name: httpbin-waypoint namespace: httpbin labels: istio.io/waypoint-for: service spec: gatewayClassName: istio-waypoint listeners: - name: mesh port: 15008 protocol: HBONEApply the YAML file by running the following command:
$ oc apply -f httpbin-waypoint.yamlEnable ingress waypoint routing on the
httpbinservice by running the following command:$ oc label service httpbin -n httpbin istio.io/ingress-use-waypoint=trueThe label ensures that the ingress gateway routes traffic through the waypoint proxy, which applies its Layer 7 (L7) policies to the 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-waypointCreate 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.apiVersion: gateway.networking.k8s.io/v1 kind: Gateway metadata: name: httpbin-gateway namespace: httpbin spec: gatewayClassName: istio listeners: - name: default hostname: "httpbin.example.com" port: 80 protocol: HTTP allowedRoutes: namespaces: from: All"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.yamlCreate a YAML file named
httpbin-ingress-hr.yamlthat defines anHTTPRouteresource for the ingress gateway, similar to the following example:apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: httpbin-ingress namespace: httpbin spec: parentRefs: - name: httpbin-gateway namespace: httpbin hostnames: - "httpbin.example.com" rules: - backendRefs: - name: httpbin port: 8000-
spec.parentRefsbinds theHTTPROUTEresource to the Kubernetes Gateway resource that you created in the previous 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.yamlCreate a YAML file named
httpbin-waypoint-hr.yamlthat defines anHTTPRouteresource for the waypoint proxy.apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: httpbin-waypoint-route namespace: httpbin spec: parentRefs: - group: "" kind: service name: httpbin namespace: httpbin rules: - matches: - path: type: PathPrefix value: /status - path: type: PathPrefix value: /headers backendRefs: - name: httpbin port: 8000-
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.yamlNoteIn 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
Verification
Create a namespace for a
curlclient by running the following command:$ oc create namespace curlDeploy 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.yamlApply the label for ambient mode to the
curlnamespace by running the following command:$ oc label namespace curl istio.io/dataplane-mode=ambientSet 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}')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/headersThe 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 ...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/getThe 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 ...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"}}'NoteOpenShift Routes can also expose a gateway to traffic outside the cluster. For more information, see "Exposing a gateway to traffic outside the cluster using OpenShift Routes".
Verify that the you can access the
httpbinservice 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}')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}')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
-
Verify that the response has the
HTTP/1.1 200 OKstatus, which indicates that the request was successful.