How to Deploy Ingress Service Using MiniKube in Kubernetes — Kubernetes Assignment 5
You have been asked to:
● Use the previous deployment
● Deploy a nginx & apache deployment of 3 replicas
● Create a nginx & apache service of type NodePort
● Create an ingress service /apache to apache service /nginx to nginx service
Check the Git Hub Repository for this Assignment to Copy the Commands & Code:
Problem (1) Solution: Use the previous deployment
Note: Here we cannot use the previous deployment because ingress is frozen on “Kubeadm”. We will install “minikube” & perform the ingress task.
Step 1: Go to the “Services” section & search “EC2” here. Put cursor over “EC2” & click on “Instances”.
Step 2: Click on “Launch Instance”.
Step 3: Choose the “Name” as “Assignment5-Minikube” in the “Name and tags”.
Step 4: Choose “AMI” as “Ubuntu”.
Step 5: Choose “Instance type” as “t2.medium”, whle “key pair (login)” as “Docker”.
Step 6: Click on “Edit” in “Network Settings”.
Step 7: Choose “Firewall (security groups)” as “Select existing security group”, while “Common security groups” as “Assignment-Security Group”.
Step 8: Choose the “Configure Storage” as “20 GiB“.
Step 9: Click on “Launch Instance”.
Step 10: The instance will be successfully launched, click on the “hyperlink(i-05cabcdfa3b6eb81d)”.
Step 11: The instance will be in the “Running” State. Select the “Assignment5-Minikube” & click on “Connect”.
Step 12: Again, click on “Connect”.
Step 13: Run the below-given command to update the machine:
sudo apt-get update
Step 14: Login as root user via typing the below-given command:
sudo su –
You will successfully logged in as root user.
Step 15: Create the “install.sh” file using the below-given command:
sudo nano install.sh
Step 16: Press “Enter” from the keyboard & the “install.sh” file will be opened. Paste this content in the “install.sh” file.
sudo apt update
sudo apt install docker.io -y
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb
sudo dpkg -i minikube_latest_amd64.deb
sudo chmod 777 /var/run/docker.sock
minikube start
sudo snap install kubectl --classic
minikube addons enable ingress
Do “CTRL+X” to “Exit” & Press “Y” from the keyboard to save the changes. Press “Enter” from the keyboard. Your file will be successfully saved.
Step 17: Run the below-given command to start the “minikube” installation:
bash install.sh
Step 18: “Minikube” is not successfully installed. It throws an error “Exiting due to DRV_AS_ROOT: The “docker” driver should not be used with root privileges.”.
Step 19: Run the below-given command to remove this error:
minikube start --force --driver=docker
The “Minikube” has been successfully installed.
Step 20: Run the below-given command to enable the ingress addon. Because due to docker driver, the ingress is not enabled.
minikube addons enable ingress
Step 21: Run the below-given command to find the cluster is created or not:
kubectl get no
A “control-plane” will be successfully shown.
Problem (2) Solution: Deploy a nginx & apache deployment of 3 replicas
Step 1: Run the below-given command to create a nginx deployment with 3 replicas.
kubectl create deployment nginx --image=nginx --port=80 --replicas=3
When you run the below-given command, you will notice that nginx deployment has been successfully created with 3 replicas.
kubectl get deploy
Step 2: If you want to deploy an “apache” service, first create a deployment for it.
kubectl create deployment apache --image=ubuntu/apache2 --port=80 --replicas=3
When you run the below-given command, you will notice that apache deployment has been successfully created with 3 replicas.
kubectl get deploy
Problem (3) Solution: Create a nginx & apache service of type NodePort
Step 1: Deploy “nginx” on the “NodePort” service. Use the below-given command:
kubectl expose deploy nginx --type=NodePort
The nginx service will be successfully deployed on “NodePort”.
Run the below-given command to view the nginx deployment is successfully deployed on “NodePort” or not.
kubectl get svc -o wide
Step 2: Deploy “apache” on the “NodePort” service. Use the below-given command:
kubectl expose deploy apache --type=NodePort
The apache service will be successfully deployed on “NodePort”.
Run the below-given command to view the apache deployment is successfully deployed on “NodePort” or not.
Problem (4) Solution: Create an ingress service /apache to apache service /nginx to nginx service
Step 1: Run the below-given command to create an “ingress” file:
sudo nano ingress.yaml
Step 2: Press “Enter” from the keyboard & paste this content to the “ingress.yaml” file.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
ingressClassName: nginx
rules:
- http:
paths:
- path: /apache
pathType: Prefix
backend:
service:
name: apache
port:
number: 80
- path: /nginx
pathType: Prefix
backend:
service:
name: nginx
port:
number: 80
Do “CTRL+X” to “Exit” & Type “Yes” for save the file. Press “Enter” from the keyboard to save the file.
Step 3: Run the below-given command to execute the “ingress.yaml” file:
kubectl apply -f ingress.yaml
The “Ingress rule” will be successfully created.
Step 4: Use the below-given command to check the ingress:
kubectl get ing
Step 5: Paste the below-given command into “EC2 Machine”:
kubectl port-forward service/ingress-nginx-controller -n ingress-nginx --address 0.0.0.0 :443
Press “Enter” from the keyboard.
The port has been successfully forwarded.
Step 6: Go to the “Browser Address Bar” & type this URL there:
https://65.1.131.18:45799/nginx
Your nginx page has been successfully accessed like this:
Step 7: Go to the “Browser Address Bar” & type this URL there:
https://65.1.131.18:45799/apache
Your “Apache Web page” has been successfully accessed like this:
Please Follow Our Medium Profile & Publication to More HandsOn for you.
More Kubernetes Assignments to Perfrom on Your End:
How to Deploy a Kubernetes Cluster & Create 3 Replica of Nginx Deployment — Kubernetes Assignment 1
How to Create A NodePort Service & Deploy NGINX on It — Kubernetes Assignment 2
How to Change the Replicas for the Deployment — Kubernetes Assignment 3
How to Change the NodePort Service to Cluster IP — Kubernetes Assignment 4
How to Deploy a Sample Website on Kubernetes Using Ingress — Kubernetes Case Study