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.
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 load balancer service when you have to expose gateways to traffic outside the cluster.
Procedure
-
Ensure that the Service
type is set to ClusterIP
by running the following command:
$ oc patch service -n -p '{"spec": {"type": "ClusterIP"}}'
-
Create a YAML file named httpbin-route.yaml
that defines a Route
for the httpbin
service.
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: None
-
Apply the YAML file by running the following command:
$ oc apply -f httpbin-route.yaml
-
Verify that httpbin
service can be accessed from outside the cluster through the ingress router. Ensure that you set the INGRESS_HOST
variable appropriately for the environment that your cluster is running in.
-
If the cluster runs on AWS, set the INGRESS_HOST
variable 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_HOST
variable by running the following command:
$ INGRESS_HOST=$(oc get service router-default -n openshift-ingress -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
-
Send a curl
request to the httpbin
service 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 OK
status, which indicates that the request was successful.