Skip to content

Exercise

Exercise : Ingress

  1. Install the Traefik Ingress Controller

    Info

    We use Helm, the Kubernetes package manager, to install Traefik. We'll detail the usage of Helm in a next section.

    First get the Helm Client:

    curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
    chmod 700 get_helm.sh
    ./get_helm.sh
    

    Then install Traefik:

    helm repo add traefik https://traefik.github.io/charts
    helm install traefik traefik/traefik --version 31.0.0 -n traefik --create-namespace
    

    This will create Traefik Pods and expose them with a Service of type load-balancer. Get the external IP of this load-balancer as we will need it in the next part. This IP can be retrieved: - from the details of the Traefik Service

    $ kubectl get service -n traefik
    NAME      TYPE           CLUSTER-IP     EXTERNAL-IP    PORT(S)                      AGE
    traefik   LoadBalancer   10.97.184.29   85.217.161.3   80:32426/TCP,443:32198/TCP   76s
    
    • from the Exoscale console

    Console

    In this example the external IP of the load balancer is 85.217.161.3

  2. In a file named ingress.yaml, define the specification for an Ingress resource with the following characteristics:

    • Name: vote
    • ingressClassName: traefik
    • All requests to the URL vote.votingapp.com should be redirected to port 80 of the vote-ui service
    • All requests to the URL result.votingapp.com should be redirected to port 80 of the result-ui service

    Update your /etc/hosts file so that the URLs vote.votingapp.com and result.votingapp.com resolve to the IP address of the Ingress Controller (the one you get before)

    Then you should modify your /etc/hosts file to add the following entry:

    ...
    IP_OF_YOUR_VM vote.votingapp.com result.votingapp.com
    

    Tip

    If you do not have the necessary permissions to modify your /etc/hosts file, you can use the nip.io service and set the domain names vote.IP_OF_YOUR_VM.nip.io / result.IP_OF_YOUR_VM.nip.io instead of vote.votingapp.com / result.votingapp.com in your Ingress resource definition.

  3. Deploy the application and verify that the vote interface is available at http://vote.votingapp.com and the result interface is available at http://result.votingapp.com (or at http://vote.IP_OF_YOUR_VM.nip.io / http://result.IP_OF_YOUR_VM.nip.io if you are using the nip.io approach).

  4. Delete the application.

Tip
  1. The specification for the Ingress resource is as follows:

    ingress.yaml
    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
    name: vote
    spec:
    ingressClassName: traefik
    rules:
    - host: vote.votingapp.com
      http:
        paths:
        - path: /
          pathType: Prefix
          backend:
            service:
              name: vote-ui
              port:
                number: 80
    - host: result.votingapp.com
      http:
        paths:
        - path: /
          pathType: Prefix
          backend:
            service:
              name: result-ui
              port:
                number: 80
    
  2. Deploy the application with the following command from the manifests directory:

    kubectl apply -f .
    

    You can then access the different interfaces using real domain names instead of a port number.

    Vote

    Result

  3. Delete the application with the following command from the manifests directory:

    kubectl delete -f .