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
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 -
We can check the contents of this file:
cat deploy.yaml
-
To execute the
deploy.yaml
file execute thekubectl create -f deploy.yaml
command.- 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! -
Weāll now check the service status:
kubectl get svc -n ingress-nginx
- 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.
- yaml files we need to deploy:
- We create the files in deployment with following command:
kubectl create -f marvel-home.yaml -f pay.yaml
:
The services are created properly
- Then we can check the status with the
kubectl get all
command:
- Rules set for Ingress controller:
We 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:- To rename the roles of the nodes, execute:
kubectl label node [nodename] node-role.kubernetes.io/worker=worker
- To rename the roles of the nodes, execute:
- 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