Rolling Updates And Rolling Back Deployments in Kubernetes

Shubham K. Sawant
3 min readJan 16, 2024

--

There is a production deployment planned for next week. The 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 nautilus. Create a deployment called httpd-deploy under this new namespace, It should have one container called httpd, use httpd:2.4.25 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.

  1. At first kubectl utility configure and working on server, run commands “kubectl get namespace” to check all existing namespace

2. to create the new namespace “kubectl create namespace nautilus“

3. Create yaml file with all the parameters “cat deploy.yaml”

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

apiVersion: apps/v1
kind: Deployment
metadata:
name: httpd-deploy
namespace: nautilus
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.25

4. Run below command to create pod “kubectl apply -f deploy.yaml — namespace= nautilus“

5. Wait for pods to get running status “kubectl get all -n nautilus”

6. Perform rolling update by running command “kubectl set image deployment httpd-deploy httpd=httpd:2.4.43 — namespace nautilus — record=true “ then validate the deployment with “kubectl get all -n nautilus” command

7. Rollback the deployment with command “ kubectl rollout undo deployment httpd-deploy -n nautilus” then validate the deployment with “kubectl get all -n nautilus” command

Join our DevOps knowledge sharing community with DevOps Knowledge Junction linked group :-
https://www.linkedin.com/groups/9501755/

Reachout to me on linkedin :-https://www.linkedin.com/in/shubhamsawant/

Checkout my work on GitHub :-https://github.com/shubhamksawant/shubhamksawant

--

--

Shubham K. Sawant
Shubham K. Sawant

Written by Shubham K. Sawant

Tech enthusiasts #DevOps engineer (newblogpost/week) #KnowledgeSimplified

No responses yet