Ingress with custom domain

- By: Thomas Jungbauer ( Lastmod: 2021-08-14 ) - 2 min read

Since Service Mesh 1.1, there is a better way to achieve the following. Especially the manual creation of the route is not required anymore. Check the following article to Enable Automatic Route Creation.

Often the question is how to get traffic into the Service Mesh when using a custom domains. Part 4 our our tutorials series OpenShift 4 and Service Mesh will use a dummy domain "hello-world.com" and explains the required settings which must be done.

Modify Gateway and VirtualService

Issue #3 explains how to get ingress traffic into the Service Mesh, by defining the Gateway and the VirtualService. We are currently using the default ingress route defined in the istio_system project.
But what if a custom domain shall be used?
In such case another route must be defined in the istio-system project and small configuration changes must be applied.

  1. First lets create a slightly modified Gateway.yaml:

    apiVersion: networking.istio.io/v1alpha3
    kind: Gateway
    metadata:
      name: ingress-gateway-exampleapp
    spec:
      selector:
        istio: ingressgateway # use istio default controller
      servers:
      - port:
          number: 80
          name: http
          protocol: HTTP
        hosts:
        - "hello-world.com" (1)
    1add you custom domain here

    The only difference is at the hosts which was changed from '*' to 'hello-world.com'

  2. As second change, the VirtualService must be modified as well with the custom domain:

    VirtualService.yaml:

    apiVersion: networking.istio.io/v1alpha3
    kind: VirtualService
    metadata:
      name: ingress-gateway-exampleapp
    spec:
      hosts:
      - "hello-world.com" (1)
      gateways:
      - ingress-gateway-exampleapp
      http:
      - match:
        - uri:
            exact: /
        route:
        - destination:
            host: customer
            port:
              number: 8080
    1add you custom domain here
  3. Replace current objects in OpenShift:

    oc replace -f Gateway.yaml -n tutorial
    oc replace -f VirtualService.yaml -n tutorial
  4. Create a new route under the project istio-system:

    apiVersion: route.openshift.io/v1
    kind: Route
    metadata:
      name: hello-world.com (1)
      namespace: istio-system (2)
    spec:
      host: hello-world.com (3)
      to:
        kind: Service
        name: istio-ingressgateway (4)
      port:
        targetPort: 8080
    1add you custom domain here
    2the route must be created at istio-system
    3add you custom domain here
    4this is the service as it was created by the operator

OPTIONAL: Add custom domain to local hosts file

The custom domain hello-world.com must be resolvable somehow, pointing to the ingress router of OpenShift. This can be done, by adding the domain into the local hosts file (with all limitations this brings with it)

# Get IP address of:
oc -n istio-system get route istio-ingressgateway
echo "x.x.x.x hello-world.com" >> /etc/hosts

Create some example traffic

We will reuse the script of Issue #3 to simulate traffic. Since we changed the domain, the connection will go to hello-world.com

sh run-check.sh 1000 hello-world.com

This will send 1000 requests to our application:

# 0: customer => preference => recommendation v1 from 'f11b097f1dd0': 6626
# 1: customer => preference => recommendation v1 from 'f11b097f1dd0': 6627
# 2: customer => preference => recommendation v1 from 'f11b097f1dd0': 6628
# 3: customer => preference => recommendation v1 from 'f11b097f1dd0': 6629
# 4: customer => preference => recommendation v1 from 'f11b097f1dd0': 6630
# 5: customer => preference => recommendation v1 from 'f11b097f1dd0': 6631
...