Rolling Updates And Rolling Back Deployments in Kubernetes Kodekloud

 

Question:  There is a production deployment planned for next week. The Nautilus DevOps team wants to test the deployment update and rollback on Dev environment first so that they can identify the risks in advance. Below you can find more details about the plan they want to execute.

    Create a namespace xfusion. Create a deployment called httpd-deploy under this new namespace, It should have one container called httpd, use httpd:2.4.27 image and 3 replicas. The deployment should use RollingUpdate strategy with maxSurge=1, and maxUnavailable=2. Also create a NodePort type service named httpd-service and expose the deployment on nodePort: 30008.

    Now upgrade the deployment to version httpd:2.4.43 using a rolling update.

    Finally, once all pods are updated undo the recent update and roll back to the previous/original version.

Note: The kubectl utility on jump_host has been configured to work with the kubernetes cluster.

Solution:

Create the mentioned namespace at first

kubectl create ns xfusion

Then create the deployment.yml and service.yml according to question

vi deployment.yml

apiVersion: apps/v1
kind: Deployment
metadata:
name: httpd-deploy
namespace: xfusion
spec:
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 2
selector:
matchLabels:
app: httpd
template:
metadata:
labels:
app: httpd
spec:
containers:
- name: httpd
image: httpd:2.4.27

 vi service.yml

apiVersion: v1
kind: Service
metadata:
name: httpd-service
namespace: xfusion
spec:
type: NodePort
selector:
app: httpd
ports:
- port: 80
targetPort: 80
nodePort: 30008

 Now run the kubectl command to apply 

 kubectl apply -f .

 Check the pods and service by running this command

 kubectl get po -n xfusion

 kubectl get svc -n xfusion

 Hit the Apache button on the right side of the portal to check if it works or not

 Then create the rolling update to update the httpd image of the deployment

 kubectl set image deployment httpd-deploy  httpd=httpd:2.4.43 --namespace xfusion --record=true

 Finally roll back to previous deployment using this command

 kubectl rollout undo deployment httpd-deploy -n xfusion

 

Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment