Kubernetes Ingress

This task describes how to configure Istio to expose a service outside of the service mesh cluster, using the Kubernetes Ingress Resource.

Using a Gateway, rather than Ingress, is recommended to make use of the full feature set that Istio offers, such as rich traffic management and security features.

Before you begin

Follow the instructions in the Before you begin and Determining the ingress IP and ports sections of the Ingress Gateways task.

Configuring ingress using an Ingress resource

A Kubernetes Ingress Resources exposes HTTP and HTTPS routes from outside the cluster to services within the cluster.

Let’s see how you can configure a Ingress on port 80 for HTTP traffic.

  1. Create an Ingress resource:

    1. $ kubectl apply -f - <<EOF
    2. apiVersion: networking.k8s.io/v1
    3. kind: Ingress
    4. metadata:
    5. annotations:
    6. kubernetes.io/ingress.class: istio
    7. name: ingress
    8. spec:
    9. rules:
    10. - host: httpbin.example.com
    11. http:
    12. paths:
    13. - path: /status
    14. pathType: Prefix
    15. backend:
    16. service:
    17. name: httpbin
    18. port:
    19. number: 8000
    20. EOF

    The kubernetes.io/ingress.class annotation is required to tell the Istio gateway controller that it should handle this Ingress, otherwise it will be ignored.

  2. Access the httpbin service using curl:

    1. $ curl -s -I -HHost:httpbin.example.com "http://$INGRESS_HOST:$INGRESS_PORT/status/200"
    2. HTTP/1.1 200 OK
    3. server: istio-envoy
    4. ...

    Note that you use the -H flag to set the Host HTTP header to “httpbin.example.com”. This is needed because the Ingress 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.

  3. Access any other URL that has not been explicitly exposed. You should see an HTTP 404 error:

    1. $ curl -s -I -HHost:httpbin.example.com "http://$INGRESS_HOST:$INGRESS_PORT/headers"
    2. HTTP/1.1 404 Not Found
    3. ...

Next Steps

TLS

Ingress supports specifying TLS settings. This is supported by Istio, but the referenced Secret must exist in the namespace of the istio-ingressgateway deployment (typically istio-system). cert-manager can be used to generate these certificates.

Specifying path type

By default, Istio will treat paths as exact matches, unless they end in /* or .*, in which case they will become prefix matches. Other regular expressions are not supported.

In Kubernetes 1.18, a new field, pathType, was added. This allows explicitly declaring a path as Exact or Prefix.

Specifying IngressClass

In Kubernetes 1.18, a new resource, IngressClass, was added, replacing the kubernetes.io/ingress.class annotation on the Ingress resource. If you are using this resource, you will need to set the controller field to istio.io/ingress-controller. For example:

  1. apiVersion: networking.k8s.io/v1
  2. kind: IngressClass
  3. metadata:
  4. name: istio
  5. spec:
  6. controller: istio.io/ingress-controller
  7. ---
  8. apiVersion: networking.k8s.io/v1
  9. kind: Ingress
  10. metadata:
  11. name: ingress
  12. spec:
  13. ingressClassName: istio
  14. rules:
  15. - host: httpbin.example.com
  16. http:
  17. paths:
  18. - path: /
  19. pathType: Prefix
  20. backend:
  21. service:
  22. name: httpbin
  23. port:
  24. number: 8000

Cleanup

Delete the Ingress configuration, and shutdown the httpbin service:

Zip

  1. $ kubectl delete ingress ingress
  2. $ kubectl delete --ignore-not-found=true -f @samples/httpbin/httpbin.yaml@