Configure Istio Ingress Gateway

Until now, you used a Kubernetes Ingress to access your application from the outside. In this module, you configure the traffic to enter through an Istio ingress gateway, in order to apply Istio control on traffic to your microservices.

  1. Store the name of your namespace in the NAMESPACE environment variable. You will need it to recognize your microservices in the logs:

    1. $ export NAMESPACE=$(kubectl config view -o jsonpath="{.contexts[?(@.name == \"$(kubectl config current-context)\")].context.namespace}")
    2. $ echo $NAMESPACE
    3. tutorial
  2. Create an environment variable for the hostname of the Istio ingress gateway:

    1. $ export MY_INGRESS_GATEWAY_HOST=istio.$NAMESPACE.bookinfo.com
    2. $ echo $MY_INGRESS_GATEWAY_HOST
    3. istio.tutorial.bookinfo.com
  3. Configure an Istio ingress gateway:

    1. $ kubectl apply -f - <<EOF
    2. apiVersion: networking.istio.io/v1alpha3
    3. kind: Gateway
    4. metadata:
    5. name: bookinfo-gateway
    6. spec:
    7. selector:
    8. istio: ingressgateway # use Istio default gateway implementation
    9. servers:
    10. - port:
    11. number: 80
    12. name: http
    13. protocol: HTTP
    14. hosts:
    15. - $MY_INGRESS_GATEWAY_HOST
    16. ---
    17. apiVersion: networking.istio.io/v1alpha3
    18. kind: VirtualService
    19. metadata:
    20. name: bookinfo
    21. spec:
    22. hosts:
    23. - $MY_INGRESS_GATEWAY_HOST
    24. gateways:
    25. - bookinfo-gateway.$NAMESPACE.svc.cluster.local
    26. http:
    27. - match:
    28. - uri:
    29. exact: /productpage
    30. - uri:
    31. exact: /login
    32. - uri:
    33. exact: /logout
    34. - uri:
    35. prefix: /static
    36. route:
    37. - destination:
    38. host: productpage
    39. port:
    40. number: 9080
    41. EOF
  4. Set INGRESS_HOST and INGRESS_PORT using the instructions in the Determining the Ingress IP and ports section.

  5. Add the output of this command to your /etc/hosts file:

    1. $ echo $INGRESS_HOST $MY_INGRESS_GATEWAY_HOST
  6. Access the application’s home page from the command line:

    1. $ curl -s $MY_INGRESS_GATEWAY_HOST:$INGRESS_PORT/productpage | grep -o "<title>.*</title>"
    2. <title>Simple Bookstore App</title>
  7. Paste the output of the following command in your browser address bar:

    1. $ echo http://$MY_INGRESS_GATEWAY_HOST:$INGRESS_PORT/productpage
  8. Simulate real-world user traffic to your application by setting an infinite loop in a new terminal window:

    1. $ while :; do curl -s <output of the previous command> | grep -o "<title>.*</title>"; sleep 1; done
    2. <title>Simple Bookstore App</title>
    3. <title>Simple Bookstore App</title>
    4. <title>Simple Bookstore App</title>
    5. <title>Simple Bookstore App</title>
    6. ...
  9. Check the graph of your namespace in the Kiali console my-kiali.io/kiali/console. (The my-kiali.io URL should be in your /etc/hosts file that you set previously).

    This time, you can see that traffic arrives from two sources, unknown (the Kubernetes Ingress) and from istio-ingressgateway istio-system (the Istio Ingress Gateway).

    Kiali Graph Tab with Istio Ingress Gateway

    Kiali Graph Tab with Istio Ingress Gateway

  10. At this point you can stop sending requests through the Kubernetes Ingress and use Istio Ingress Gateway only. Stop the infinite loop (Ctrl-C in the terminal window) you set in the previous steps. In a real production environment, you would update the DNS entry of your application to contain the IP of Istio ingress gateway or configure your external Load Balancer.

  11. Delete the Kubernetes Ingress resource:

    1. $ kubectl delete ingress bookinfo
    2. ingress.extensions "bookinfo" deleted
  12. In a new terminal window, restart the real-world user traffic simulation as described in the previous steps.

  13. Check your graph in the Kiali console. After about a minute, you will see the Istio Ingress Gateway as a single source of traffic for your application.

    Kiali Graph Tab with Istio Ingress Gateway as a single source of traffic

    Kiali Graph Tab with Istio Ingress Gateway as a single source of traffic

You are ready to configure logging with Istio.