Kubernetes Ingress

What is Ingress?

Ingress is another core system of Kubernetes. It has several functions:

  • Expose a service with a user-friendly URL: instead of having 192.168.82.1:8080, the user can see www.example.com/login and access directly the pod that offers the service.
  • Traffic load balancing (Weā€™ll see later why it is not the same a a Cloud providerā€™s load balancing system)
  • Process SSL Certificates

  • Appoint virtual hosting ā†’ Can easily change the domain name, or have several ones that use the same pods.

Visualize Ingress

Ingress-map-1.001

Install Ingress

  • After installing Kubernetes (and Minikube), follow this link

  • Because weā€™re on a Google Compute Engine weā€™ll be installing Ingress for bare-metal: wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.0/deploy/static/provider/baremetal/deploy.yaml ā†’ deploy.yaml file is downloaded

    install-ingress-1

  • We can check the contents of this file: cat deploy.yaml

  • To execute the deploy.yaml file execute the kubectl create -f deploy.yamlcommand.

    create-deploy-yaml

    • We now have created a namespace, a service and a controller!
  • To check their status: kubectl get pod -n ingress-nginx ā†’ ingress-nginx as per the namespace above!

    check-pod-status-1

  • Weā€™ll now check the service status: kubectl get svc -n ingress-nginx

    check-svc-status-1

    • We can see the port numbers, internal IPs of the service.

Ingress Controller is installed and working!

In practice

Build 2 services: main page, then pay service.

We want the Ingress rule to redirect to home page if address is XXX.COM/ and to the pay-service if the link is XXX.COM/pay

  • Need to download resources to our VM: git clone https://github.com/237summit/cloud-native ā†’ we have downloaded the cloud native folder. Inside, the ingress folder contains :
    • yaml files we need to deploy: marvel-home.yaml, pay.yaml.
    • and the docker files, html files needed for the webserver.
  • We create the files in deployment with following command: kubectl create -f marvel-home.yaml -f pay.yaml:

create-deploy-mvl-pay

The services are created properly

  • Then we can check the status with the kubectl get all command:

get-all-mvl

  • Rules set for Ingress controller:

ingress-rulesWe can see how the redirection rules are set here: if the path entered is / then redirect to the marvel-service service. If the path entered is /pay then redirect to the pay-service service.

šŸ˜„ The rest - was impossible to realise following ė”°ė² ģæ ģŒ¤ā€™s class as kubernetes versions have changed. šŸ˜„ There seems to be similar issues with other online classes (Tech With Nana students reported an issue)

Please refer to this video for the rest

Bonus:

Install minikube to create nodes inside 1 single VM/Instance!

Minikube allows to quickly and simply create a local Kubernetes cluster - perfect for testing environments!

  • Install rules on this link āš ļø requires 2CPUs, 2GB free memory and 20GB free storageāš ļø

    • For Linux/Ubuntu, x86-64 architecture, copy these lanes in your terminal:

      curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
      sudo install minikube-linux-amd64 /usr/local/bin/minikube
      
    • It requires docker, and a root access to it though Minikube canā€™t be installed on root. Here is the trick! You should give root access to the main user:

      • $ sudo groupadd docker
      • $ sudo usermod -aG docker $USER
      • Log out and should be good.
  • To start with a 3 node cluster: minikube start --nodes 3 -p [clustername]

  • The process takes some time, but after itā€™s done, for a cluster name tabeku here is how it comes out:nodelist
    • To rename the roles of the nodes, execute: kubectl label node [nodename] node-role.kubernetes.io/worker=worker
  • Minikube has an addon for using ingress: minikube addons enable ingress

How is Ingress different from load balance service?

  • Load balancer: standard way to expose a service to Interner. Only provides one IP, and requires an IP per service. It can be expensive.
  • Ingress: It is in front of the services and smartly reroutes the user to the right service, through the same IP.

Sources

  • https://www.youtube.com/watch?v=NPFbYpb0I7w

  • https://www.youtube.com/watch?v=80Ew_fsV4rM

  • https://medium.com/google-cloud/kubernetes-101-pods-nodes-containers-and-clusters-c1509e409e16
  • https://medium.com/google-cloud/kubernetes-nodeport-vs-loadbalancer-vs-ingress-when-should-i-use-what-922f010849e0
  • https://stackoverflow.com/questions/45079988/ingress-vs-load-balancer
  • Minikube documentation