How to Change the Replicas for the Deployment — Kubernetes Assignment 3
You have been asked to:
● Use the previous deployment
● Change the replicas to 5 for the deployment
Check the Git Hub Repository for this Assignment to Copy the Commands:
Problem (1) Solution: Use the previous deployment
Before working on this assignment, you have to check the Kubernetes Assignment 1, where we have created a Kubernetes Cluster with 3 nodes & create 3 replica using the deployment.yaml file. Please check that assignment, now we will change the 3 replica to the 5 replicas.
We will use a new t2.medium machine with 3 replica node because t2.medium is chargeable, not possible to run the machine everytime.
Problem (2) Solution: Change the replicas to 5 for the deployment
Step 1: Open the deployment.yaml file using this command:
nano deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.16.1
ports:
- containerPort: 80
Note: We are not using the sudo command because we are not working as a root user, only work as a normal user. Take care if you are working as a root user then use sudo otherwise start command without sudo. Otherwise, in the deployment creation, you will face the issue.
Step 2: Replace replicas as 3 to 5.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 5
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.16.1
ports:
- containerPort: 80
Do “CTRL+X” to “Exit” & Type “Yes” to save the file. Press “Enter” from the keyboard after typing “Yes”.
Step 3: Now, again run the below-given command:
kubectl apply –f deployment.yaml
Run the below-given command to check the deployment status:
kubectl get deploy
A deployment with 5 replicas will be successfully created.
Step 4: If you run the below-given command, you will notice that 5 pods are successfully running.
kubectl get po
This means our replica have been successfully changed from 3 to 5.
More Assignments:
How to Create A NodePort Service & Deploy NGINX on It — Kubernetes Assignment 2
How to Change the NodePort Service to Cluster IP — Kubernetes Assignment 4
How to Deploy Ingress Service Using MiniKube in Kubernetes — Kubernetes Assignment 5
How to Deploy a Sample Website on Kubernetes Using Ingress — Kubernetes Case Study