How to Deploy Ingress Service Using MiniKube in Kubernetes — Kubernetes Assignment 5

Visal Tyagi
DevOps-Guides
Published in
7 min readJul 17, 2024

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:

How to Deploy Ingress Service Using MiniKube in Kubernetes — Kubernetes Assignment 5
How to Deploy Ingress Service Using MiniKube in Kubernetes — Kubernetes Assignment 5

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”.

Go to Instances
Go to Instances

Step 2: Click on “Launch Instance”.

Launch the New Instance
Launch the New Instance

Step 3: Choose the “Name” as “Assignment5-Minikube” in the “Name and tags”.

Write Instance Name Here
Write Instance Name Here

Step 4: Choose “AMI” as “Ubuntu”.

Ubuntu AMI
Ubuntu AMI

Step 5: Choose “Instance type” as “t2.medium”, whle “key pair (login)” as “Docker”.

Choose Instance type & key pair
Choose Instance type & key pair

Step 6: Click on “Edit” in “Network Settings”.

Edit Network Settings
Edit Network Settings

Step 7: Choose “Firewall (security groups)” as “Select existing security group”, while “Common security groups” as “Assignment-Security Group”.

Select the Existing Security Group
Select the Existing Security Group

Step 8: Choose the “Configure Storage” as “20 GiB“.

Redefine Configure Storage
Redefine Configure Storage

Step 9: Click on “Launch Instance”.

Launch the Instance
Launch the Instance

Step 10: The instance will be successfully launched, click on the “hyperlink(i-05cabcdfa3b6eb81d)”.

Click on Hyperlink
Click on Hyperlink

Step 11: The instance will be in the “Running” State. Select the “Assignment5-Minikube” & click on “Connect”.

Select the Instance to Connect
Select the Instance to Connect

Step 12: Again, click on “Connect”.

Click on Connect
Click on Connect

Step 13: Run the below-given command to update the machine:

sudo apt-get update
Update the Machine
Update the Machine

Step 14: Login as root user via typing the below-given command:

sudo su –
Login as a Root User
Login as a Root User

You will successfully logged in as root user.

Step 15: Create the “install.sh” file using the below-given command:

sudo nano install.sh
Create an install.sh file
Create an install.sh file

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
Paste the Code for MiniKube Installation
Paste the Code for MiniKube Installation

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
Run the bash command
Run the bash command

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.”.

MiniKube Error
MiniKube Error

Step 19: Run the below-given command to remove this error:

minikube start --force --driver=docker
MiniKube Successfully Installed
MiniKube Successfully Installed

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
Ingress AddOn Enabled
Ingress AddOn Enabled

Step 21: Run the below-given command to find the cluster is created or not:

kubectl get no
Find the Nodes
Find the Nodes

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
NGINX Deployment With 3 Replicas
NGINX Deployment With 3 Replicas

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
Apache Deployment With 3 Replicas
Apache Deployment With 3 Replicas

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
Deploy NGINX on NodePort
Deploy NGINX on NodePort

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.

Deploy Apache on NodePort
Deploy Apache on NodePort

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
Create an ingress.yaml file
Create an ingress.yaml file

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
Paste the Ingress code
Paste the Ingress code

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
Create an ingress rule
Create an ingress rule

The “Ingress rule” will be successfully created.

Step 4: Use the below-given command to check the ingress:

kubectl get ing
Find the Ingress
Find the Ingress

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.

Port Forwarding
Port Forwarding

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:

NGINX Accessed
NGINX Accessed

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:

Apache Accessed
Apache Accessed

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

--

--