LinuxDady.Com
Kubernetes rolling update strategy
for prod infra
For more information visit
https://linuxdady.com
Kubernetes Rolling Update
Strategy in our production infra
BY DEEPAK KUMAR · PUBLISHED SEPTEMBER 23, 2019 · UPDATED SEPTEMBER 23, 2019
Kubernetes rolling update strategy means suppose we are running pod
(containers) in our live infra and we want to update new changes into our
running pod like build update, confrontational changes etc. While deployment
new pod with new changes suppose our containers got stuck or failed due to
any reason.
So, we have to redeploy old pod with old changes again to avoid downtime of
our application. This complete process is called Kubernetes rolling update
strategy.
Kubernetes rolling update strategy
Before moving to next we should aware about new pod deployment strategy of
Kubernetes means how many new pods it will deploy at a time without taking
downtime. Because high availability of our website is our first priority. So, while
deploying new pod Kubernetes will deploy 25% or you can say one fourth of
the total pod. Suppose we are running four pods first it will terminate 25% of
total pod means one pod. Then it will launch 25% new pod and so on.
Advantage of rolling updates
â–Ş To maintain our application high availability during deployment.
â–Ş Save our time and manpower
â–Ş Easy to roll back if facing any issue
â–Ş Support versioning
â–Ş Recreate pod
[Click & Read:– Kubernetes deployments by yaml
file for beginner]
[Click & Read:– Pod deployment in kubernetes by command
line ]
Versioning in Kubernetes
I think you know very well about versioning means to store all changes for
backup purpose called versioning. Similarly, in Kubernetes we store our yaml
file old changes before new changes for backup point of view. Because in case
of any issue we will be able to deploy older version and our application will
become in upstate. So let’s enable versioning before deployment. But first make
nginx-deployment.yaml file first.
1 vim nginx-deployment.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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.7.9
ports:
- containerPort: 80
1
2
3
kubectl create -f nginx-deployment.yaml --record=true
kubectl rollout history deployment nginx-deployment
kubectl get pod -o wide
nginx-deployment.yaml -::- This file is our confrontational file of
Kubernetes where all parameters are defines.
record=true -::- This option creates the latest version of nginx-deployment
before deployment new changes.
rollout history -::- To check the current version of our deployment.
Change new image instead of nginx
Note that still we are deploying containers from nginx image. Now we are going
to check we can roll back older version of our deployment if we got stuck
anywhere. So, for this purpose we have to make two version of nginx
deployment. Our first version will be with nginx image. For second version
change nginx image with new required image that we want to deploy. In my
case I am changing it with apache. So, open below file and change your older
image parameter with image: nginx:1.7.9 with new image:
docker.io/centos/httpd
1 vim nginx-deployment.yaml
1
2
3
4
5
6
7
8
9
10
11
12
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
13
14
15
16
17
18
19
20
21
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: docker.io/centos/httpd
ports:
- containerPort: 80
Note in my case I have taken apache image in your case you can select
accordingly. After changing your desire image save the yaml file. After saving
this file let’s create version of this yaml.
1
2
kubectl apply -f nginx-deployment.yaml --record=true
kubectl rollout history deployment nginx-deployment
Now we have two version one for nginx and another for apache server.
If we will do deployment form version one, then it will reach into nginx image
state and if we will use version two it will reach into apache image state. So,
let’s take a scenario suppose now we are running nginx image and we want to
update it with apache and due to any reason, it got stuck. Then we will roll back
with older version nginx again from apache. So, check the pod life. In given
below fig. It is showing 15 minutes and still running our apache container now.
1 kubectl get pod
Kubernetes rolling update strategy and roll back to older version
Now we are going to roll back from version 2 to nginx version 1. So, Change
version accordingly in your case.
1
2
kubectl rollout undo deployment/nginx-deployment --to-revision=1
kubectl get pod -o wide
As we have checked our old version has been updated successfully and it’s show
“welcome to nginx” but before rollback it was showing “Apache HTTP Server
Test Page”. So, it’s all about Kubernetes rolling update. Now we will go through
some basic command that is useful in rolling update. Now check version
properly updated or not.
1 kubectl rollout status deployment nginx-deployment
1 kubectl rollout history deployment nginx-deployment
We can check all available version from above command. Output will be like
below.
1
2
3
4
deployment.extensions/nginx-deployment
REVISION CHANGE-CAUSE
2 kubectl apply --filename=nginx-deployment.yaml --record=true
3 kubectl create --filename=nginx-deployment.yaml --record=true
Suppose we need full description of and version then below command will be
helpful.
1 kubectl rollout history deployment nginx-deployment --revision=3
Only change revision version = 3 accordingly in above command. Output will be
look like below.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
deployment.extensions/nginx-deployment with revision #3
Pod Template:
Labels: app=nginx
pod-template-hash=5754944d6c
Annotations: kubernetes.io/change-cause: kubectl create -
filename=nginx-deployment.yaml --record=true
Containers:
nginx:
Image: nginx:1.7.9
Port: 80/TCP
Host Port: 0/TCP
Environment: none
Mounts: none
Volumes: none
rs stand for replica status means we can check status and number of old replica
and new replica.
1 kubectl get rs
Watch the status of the rollout until it’s done.
1 kubectl get rs -w
All about Kubernetes Rolling Update Strategy
In this tutorial we have discussed about Kubernetes rolling update
strategy and its advantages for our infra. We have covered this topic because
this is daily routine task. So, if anyone still have any query write me in comment
box. I will try my best to resolve them.
My interview discussion in a company
I have faced recently an interview related to Kubernetes jobs. So, I thought I
should share all question and answer during that interview. If I am wrong in
any answer, please correct me in comment box.
How will you update the new changes in Kubernetes and what will be the
step?
MyAns. I told him first of all I will create new version of running deployment
for backup purpose. Then I will update new changes. So simple.
Then Interviewer again asked next question suppose you are updating changes
and your changes got stuck and due to that changes your application goes
down. Now what will be your step to recover that?
My Ans. I replied him sir my first priority will be to bring up our application
first anyhow. So first I will try to analyse logs and if find any issue into logs
related to any other teams like development, testing, security etc. Then I will
send logs to them. After sending logs I will roll back last version.
Again, Interviewer ask me a question suppose Deepak again your older version
got stuck. Now what will be your approach?
My Ans.. I replied him sir first of all I will again analyse logs. If into logs
everything is looking fine. Might be we do not have proper backup of our old
version.
Again, Interviewer ask me ok Deepak we don’t have proper backup. Now what
will be next approach because our application is not up still?
My Ans. I have replied Sir there is an alternate way we can use manually means
by command mode instead of yaml file.
Again, Interviewer ask me Deepak all team replied everything is ok from our
end. Then what will be possible reason of failure.
My Ans. From our end this can occur due to some of the following reason
â–Ş Insufficient quota
â–Ş Readiness probe failures
â–Ş Image pull errors
â–Ş Insufficient permissions
â–Ş Limit ranges
â–Ş Application runtime misconfiguratio

More Related Content

PDF
Api Versioning with Docker and Nginx
PDF
Tomcat Maven Plugin
PDF
Workflow automation for Front-end web applications
PPTX
Getting started with k8
PPTX
Build using jenkins on rtc repository
PDF
PuppetConf 2016: Best Practices for Puppet in the Cloud – Randall Hunt, Amazo...
 
PDF
When Old Meets New: Turning Maven into a High Scalable, Resource Efficient, C...
PDF
Two-Step Deployment with Rails
Api Versioning with Docker and Nginx
Tomcat Maven Plugin
Workflow automation for Front-end web applications
Getting started with k8
Build using jenkins on rtc repository
PuppetConf 2016: Best Practices for Puppet in the Cloud – Randall Hunt, Amazo...
 
When Old Meets New: Turning Maven into a High Scalable, Resource Efficient, C...
Two-Step Deployment with Rails

What's hot (19)

PDF
A Series of Fortunate Events: Building an Operator in Java
ODP
Jenkins and rails app - Le Dinh Vu
PDF
The History of React-Hot-Loader
PPTX
Integration testing for salt states using aws ec2 container service
PDF
Automated Deployment with Maven - going the whole nine yards
PPT
Spark Streaming Info
PPTX
Release With Maven
 
PPTX
A taste for aether
PDF
Continuous delivery-with-maven
DOCX
Creating an nuget package for EPiServer
PDF
Kubermatic How to Migrate 100 Clusters from On-Prem to Google Cloud Without D...
PDF
Dockerized .Net Core based app services in azure K8s
ODP
Developingapiplug insforcs-151112204727-lva1-app6891
 
PPTX
Exploring the Future of Helm
PDF
Version control Git -Lecture-2
PPTX
Apache Kafka Reliability
PDF
Version control git - lecture-1
PDF
Intelligent infrastructure with SaltStack
PDF
Subversion to Git Migration
A Series of Fortunate Events: Building an Operator in Java
Jenkins and rails app - Le Dinh Vu
The History of React-Hot-Loader
Integration testing for salt states using aws ec2 container service
Automated Deployment with Maven - going the whole nine yards
Spark Streaming Info
Release With Maven
 
A taste for aether
Continuous delivery-with-maven
Creating an nuget package for EPiServer
Kubermatic How to Migrate 100 Clusters from On-Prem to Google Cloud Without D...
Dockerized .Net Core based app services in azure K8s
Developingapiplug insforcs-151112204727-lva1-app6891
 
Exploring the Future of Helm
Version control Git -Lecture-2
Apache Kafka Reliability
Version control git - lecture-1
Intelligent infrastructure with SaltStack
Subversion to Git Migration
Ad

Similar to Kubernetes rolling back (20)

PDF
Kubernetes and its Infrastructure - a walkthrough from the paths of container...
PPTX
Kubernetes Overview - Deploy your app with confidence
PDF
WP_The Beginners Guide to Kubernetes_2020.pdf
PDF
Run K8s on Local Environment
PPTX
Effective images remix
PPTX
How to Handle your Kubernetes Upgrades
PDF
2016 - Easing Your Way Into Docker: Lessons From a Journey to Production
PDF
LFCS Questions and Answers pdf dumps.pdf
PDF
Using kubernetes to lose your fear of using containers
PDF
ClickHouse on Kubernetes, by Alexander Zaitsev, Altinity CTO
PDF
Zero downtime deployment of micro-services with Kubernetes
PDF
Can I Contain This?
PDF
Kubernetes in Google Cloud
PPTX
How to install ReactJS software
PPTX
ReactJS software installation
PDF
Expert Day 2019 - CaaSP et CAP
 
PDF
K8s
ODP
7 Habits of Highly Effective Jenkins Users
PPTX
Openshift Presentation ppt compare with VM
PPT
Setting up the hyperledger composer in ubuntu
Kubernetes and its Infrastructure - a walkthrough from the paths of container...
Kubernetes Overview - Deploy your app with confidence
WP_The Beginners Guide to Kubernetes_2020.pdf
Run K8s on Local Environment
Effective images remix
How to Handle your Kubernetes Upgrades
2016 - Easing Your Way Into Docker: Lessons From a Journey to Production
LFCS Questions and Answers pdf dumps.pdf
Using kubernetes to lose your fear of using containers
ClickHouse on Kubernetes, by Alexander Zaitsev, Altinity CTO
Zero downtime deployment of micro-services with Kubernetes
Can I Contain This?
Kubernetes in Google Cloud
How to install ReactJS software
ReactJS software installation
Expert Day 2019 - CaaSP et CAP
 
K8s
7 Habits of Highly Effective Jenkins Users
Openshift Presentation ppt compare with VM
Setting up the hyperledger composer in ubuntu
Ad

Recently uploaded (20)

PDF
FORM 1 BIOLOGY MIND MAPS and their schemes
PDF
AI-driven educational solutions for real-life interventions in the Philippine...
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PPTX
Virtual and Augmented Reality in Current Scenario
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
PDF
My India Quiz Book_20210205121199924.pdf
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
Trump Administration's workforce development strategy
PDF
Hazard Identification & Risk Assessment .pdf
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PDF
Empowerment Technology for Senior High School Guide
PDF
Complications of Minimal Access-Surgery.pdf
PDF
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
FORM 1 BIOLOGY MIND MAPS and their schemes
AI-driven educational solutions for real-life interventions in the Philippine...
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
A powerpoint presentation on the Revised K-10 Science Shaping Paper
Virtual and Augmented Reality in Current Scenario
Paper A Mock Exam 9_ Attempt review.pdf.
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
My India Quiz Book_20210205121199924.pdf
What if we spent less time fighting change, and more time building what’s rig...
Trump Administration's workforce development strategy
Hazard Identification & Risk Assessment .pdf
Weekly quiz Compilation Jan -July 25.pdf
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
Empowerment Technology for Senior High School Guide
Complications of Minimal Access-Surgery.pdf
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
Practical Manual AGRO-233 Principles and Practices of Natural Farming
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf

Kubernetes rolling back

  • 1. LinuxDady.Com Kubernetes rolling update strategy for prod infra For more information visit https://linuxdady.com
  • 2. Kubernetes Rolling Update Strategy in our production infra BY DEEPAK KUMAR · PUBLISHED SEPTEMBER 23, 2019 · UPDATED SEPTEMBER 23, 2019 Kubernetes rolling update strategy means suppose we are running pod (containers) in our live infra and we want to update new changes into our running pod like build update, confrontational changes etc. While deployment new pod with new changes suppose our containers got stuck or failed due to any reason. So, we have to redeploy old pod with old changes again to avoid downtime of our application. This complete process is called Kubernetes rolling update strategy. Kubernetes rolling update strategy Before moving to next we should aware about new pod deployment strategy of Kubernetes means how many new pods it will deploy at a time without taking downtime. Because high availability of our website is our first priority. So, while deploying new pod Kubernetes will deploy 25% or you can say one fourth of the total pod. Suppose we are running four pods first it will terminate 25% of total pod means one pod. Then it will launch 25% new pod and so on. Advantage of rolling updates â–Ş To maintain our application high availability during deployment. â–Ş Save our time and manpower â–Ş Easy to roll back if facing any issue â–Ş Support versioning â–Ş Recreate pod [Click & Read:– Kubernetes deployments by yaml file for beginner] [Click & Read:– Pod deployment in kubernetes by command line ] Versioning in Kubernetes I think you know very well about versioning means to store all changes for backup purpose called versioning. Similarly, in Kubernetes we store our yaml file old changes before new changes for backup point of view. Because in case of any issue we will be able to deploy older version and our application will become in upstate. So let’s enable versioning before deployment. But first make nginx-deployment.yaml file first.
  • 3. 1 vim nginx-deployment.yaml 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 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.7.9 ports: - containerPort: 80 1 2 3 kubectl create -f nginx-deployment.yaml --record=true kubectl rollout history deployment nginx-deployment kubectl get pod -o wide nginx-deployment.yaml -::- This file is our confrontational file of Kubernetes where all parameters are defines. record=true -::- This option creates the latest version of nginx-deployment before deployment new changes. rollout history -::- To check the current version of our deployment.
  • 4. Change new image instead of nginx Note that still we are deploying containers from nginx image. Now we are going to check we can roll back older version of our deployment if we got stuck anywhere. So, for this purpose we have to make two version of nginx deployment. Our first version will be with nginx image. For second version change nginx image with new required image that we want to deploy. In my case I am changing it with apache. So, open below file and change your older image parameter with image: nginx:1.7.9 with new image: docker.io/centos/httpd 1 vim nginx-deployment.yaml 1 2 3 4 5 6 7 8 9 10 11 12 apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment labels: app: nginx spec: replicas: 3 selector: matchLabels: app: nginx template:
  • 5. 13 14 15 16 17 18 19 20 21 metadata: labels: app: nginx spec: containers: - name: nginx image: docker.io/centos/httpd ports: - containerPort: 80 Note in my case I have taken apache image in your case you can select accordingly. After changing your desire image save the yaml file. After saving this file let’s create version of this yaml. 1 2 kubectl apply -f nginx-deployment.yaml --record=true kubectl rollout history deployment nginx-deployment Now we have two version one for nginx and another for apache server. If we will do deployment form version one, then it will reach into nginx image state and if we will use version two it will reach into apache image state. So, let’s take a scenario suppose now we are running nginx image and we want to update it with apache and due to any reason, it got stuck. Then we will roll back with older version nginx again from apache. So, check the pod life. In given below fig. It is showing 15 minutes and still running our apache container now. 1 kubectl get pod
  • 6. Kubernetes rolling update strategy and roll back to older version Now we are going to roll back from version 2 to nginx version 1. So, Change version accordingly in your case. 1 2 kubectl rollout undo deployment/nginx-deployment --to-revision=1 kubectl get pod -o wide As we have checked our old version has been updated successfully and it’s show “welcome to nginx” but before rollback it was showing “Apache HTTP Server Test Page”. So, it’s all about Kubernetes rolling update. Now we will go through some basic command that is useful in rolling update. Now check version properly updated or not. 1 kubectl rollout status deployment nginx-deployment 1 kubectl rollout history deployment nginx-deployment We can check all available version from above command. Output will be like below.
  • 7. 1 2 3 4 deployment.extensions/nginx-deployment REVISION CHANGE-CAUSE 2 kubectl apply --filename=nginx-deployment.yaml --record=true 3 kubectl create --filename=nginx-deployment.yaml --record=true Suppose we need full description of and version then below command will be helpful. 1 kubectl rollout history deployment nginx-deployment --revision=3 Only change revision version = 3 accordingly in above command. Output will be look like below. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 deployment.extensions/nginx-deployment with revision #3 Pod Template: Labels: app=nginx pod-template-hash=5754944d6c Annotations: kubernetes.io/change-cause: kubectl create - filename=nginx-deployment.yaml --record=true Containers: nginx: Image: nginx:1.7.9 Port: 80/TCP Host Port: 0/TCP Environment: none Mounts: none Volumes: none rs stand for replica status means we can check status and number of old replica and new replica. 1 kubectl get rs
  • 8. Watch the status of the rollout until it’s done. 1 kubectl get rs -w All about Kubernetes Rolling Update Strategy In this tutorial we have discussed about Kubernetes rolling update strategy and its advantages for our infra. We have covered this topic because this is daily routine task. So, if anyone still have any query write me in comment box. I will try my best to resolve them. My interview discussion in a company I have faced recently an interview related to Kubernetes jobs. So, I thought I should share all question and answer during that interview. If I am wrong in any answer, please correct me in comment box. How will you update the new changes in Kubernetes and what will be the step? MyAns. I told him first of all I will create new version of running deployment for backup purpose. Then I will update new changes. So simple. Then Interviewer again asked next question suppose you are updating changes and your changes got stuck and due to that changes your application goes down. Now what will be your step to recover that? My Ans. I replied him sir my first priority will be to bring up our application first anyhow. So first I will try to analyse logs and if find any issue into logs related to any other teams like development, testing, security etc. Then I will send logs to them. After sending logs I will roll back last version. Again, Interviewer ask me a question suppose Deepak again your older version got stuck. Now what will be your approach? My Ans.. I replied him sir first of all I will again analyse logs. If into logs everything is looking fine. Might be we do not have proper backup of our old version. Again, Interviewer ask me ok Deepak we don’t have proper backup. Now what will be next approach because our application is not up still? My Ans. I have replied Sir there is an alternate way we can use manually means by command mode instead of yaml file.
  • 9. Again, Interviewer ask me Deepak all team replied everything is ok from our end. Then what will be possible reason of failure. My Ans. From our end this can occur due to some of the following reason â–Ş Insufficient quota â–Ş Readiness probe failures â–Ş Image pull errors â–Ş Insufficient permissions â–Ş Limit ranges â–Ş Application runtime misconfiguratio