SlideShare a Scribd company logo
1 of 9
Download to read offline
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

What's hot

Jenkins and rails app - Le Dinh Vu
Jenkins and rails app - Le Dinh VuJenkins and rails app - Le Dinh Vu
Jenkins and rails app - Le Dinh Vu
Framgia Vietnam
 
Spark Streaming Info
Spark Streaming InfoSpark Streaming Info
Spark Streaming Info
Doug Chang
 
Release With Maven
Release With MavenRelease With Maven
Release With Maven
eugenn
 
Checkitmobile advanced git
Checkitmobile advanced gitCheckitmobile advanced git
Checkitmobile advanced git
Gerrit Wanderer
 

What's hot (20)

A Series of Fortunate Events: Building an Operator in Java
A Series of Fortunate Events: Building an Operator in JavaA Series of Fortunate Events: Building an Operator in Java
A Series of Fortunate Events: Building an Operator in Java
 
Jenkins and rails app - Le Dinh Vu
Jenkins and rails app - Le Dinh VuJenkins and rails app - Le Dinh Vu
Jenkins and rails app - Le Dinh Vu
 
The History of React-Hot-Loader
The History of React-Hot-LoaderThe History of React-Hot-Loader
The History of React-Hot-Loader
 
Integration testing for salt states using aws ec2 container service
Integration testing for salt states using aws ec2 container serviceIntegration testing for salt states using aws ec2 container service
Integration testing for salt states using aws ec2 container service
 
Automated Deployment with Maven - going the whole nine yards
Automated Deployment with Maven - going the whole nine yardsAutomated Deployment with Maven - going the whole nine yards
Automated Deployment with Maven - going the whole nine yards
 
Spark Streaming Info
Spark Streaming InfoSpark Streaming Info
Spark Streaming Info
 
Release With Maven
Release With MavenRelease With Maven
Release With Maven
 
A taste for aether
A taste for aetherA taste for aether
A taste for aether
 
Continuous delivery-with-maven
Continuous delivery-with-mavenContinuous delivery-with-maven
Continuous delivery-with-maven
 
Creating an nuget package for EPiServer
Creating an nuget package for EPiServerCreating an nuget package for EPiServer
Creating an nuget package for EPiServer
 
Kubermatic How to Migrate 100 Clusters from On-Prem to Google Cloud Without D...
Kubermatic How to Migrate 100 Clusters from On-Prem to Google Cloud Without D...Kubermatic How to Migrate 100 Clusters from On-Prem to Google Cloud Without D...
Kubermatic How to Migrate 100 Clusters from On-Prem to Google Cloud Without D...
 
Dockerized .Net Core based app services in azure K8s
Dockerized .Net Core based app services in azure K8s Dockerized .Net Core based app services in azure K8s
Dockerized .Net Core based app services in azure K8s
 
Developingapiplug insforcs-151112204727-lva1-app6891
Developingapiplug insforcs-151112204727-lva1-app6891Developingapiplug insforcs-151112204727-lva1-app6891
Developingapiplug insforcs-151112204727-lva1-app6891
 
Exploring the Future of Helm
Exploring the Future of HelmExploring the Future of Helm
Exploring the Future of Helm
 
Version control Git -Lecture-2
Version control Git -Lecture-2Version control Git -Lecture-2
Version control Git -Lecture-2
 
Apache Kafka Reliability
Apache Kafka Reliability Apache Kafka Reliability
Apache Kafka Reliability
 
Checkitmobile Git Workshop
Checkitmobile Git WorkshopCheckitmobile Git Workshop
Checkitmobile Git Workshop
 
Version control git - lecture-1
Version control git - lecture-1Version control git - lecture-1
Version control git - lecture-1
 
Intelligent infrastructure with SaltStack
Intelligent infrastructure with SaltStackIntelligent infrastructure with SaltStack
Intelligent infrastructure with SaltStack
 
Checkitmobile advanced git
Checkitmobile advanced gitCheckitmobile advanced git
Checkitmobile advanced git
 

Similar to Kubernetes rolling back

Kubernetes and its Infrastructure - a walkthrough from the paths of container...
Kubernetes and its Infrastructure - a walkthrough from the paths of container...Kubernetes and its Infrastructure - a walkthrough from the paths of container...
Kubernetes and its Infrastructure - a walkthrough from the paths of container...
niharikadhanik
 
Kubernetes+-CKA-+0400+-+Application+Lifecycle+Management.pdf
Kubernetes+-CKA-+0400+-+Application+Lifecycle+Management.pdfKubernetes+-CKA-+0400+-+Application+Lifecycle+Management.pdf
Kubernetes+-CKA-+0400+-+Application+Lifecycle+Management.pdf
Srinivasa Rao
 

Similar to Kubernetes rolling back (20)

Kubernetes and its Infrastructure - a walkthrough from the paths of container...
Kubernetes and its Infrastructure - a walkthrough from the paths of container...Kubernetes and its Infrastructure - a walkthrough from the paths of container...
Kubernetes and its Infrastructure - a walkthrough from the paths of container...
 
Kubernetes Overview - Deploy your app with confidence
Kubernetes Overview - Deploy your app with confidenceKubernetes Overview - Deploy your app with confidence
Kubernetes Overview - Deploy your app with confidence
 
Run K8s on Local Environment
Run K8s on Local EnvironmentRun K8s on Local Environment
Run K8s on Local Environment
 
Effective images remix
Effective images remixEffective images remix
Effective images remix
 
How to Handle your Kubernetes Upgrades
How to Handle your Kubernetes UpgradesHow to Handle your Kubernetes Upgrades
How to Handle your Kubernetes Upgrades
 
2016 - Easing Your Way Into Docker: Lessons From a Journey to Production
2016 - Easing Your Way Into Docker: Lessons From a Journey to Production2016 - Easing Your Way Into Docker: Lessons From a Journey to Production
2016 - Easing Your Way Into Docker: Lessons From a Journey to Production
 
Using kubernetes to lose your fear of using containers
Using kubernetes to lose your fear of using containersUsing kubernetes to lose your fear of using containers
Using kubernetes to lose your fear of using containers
 
ClickHouse on Kubernetes, by Alexander Zaitsev, Altinity CTO
ClickHouse on Kubernetes, by Alexander Zaitsev, Altinity CTOClickHouse on Kubernetes, by Alexander Zaitsev, Altinity CTO
ClickHouse on Kubernetes, by Alexander Zaitsev, Altinity CTO
 
Zero downtime deployment of micro-services with Kubernetes
Zero downtime deployment of micro-services with KubernetesZero downtime deployment of micro-services with Kubernetes
Zero downtime deployment of micro-services with Kubernetes
 
Can I Contain This?
Can I Contain This?Can I Contain This?
Can I Contain This?
 
Kubernetes in Google Cloud
Kubernetes in Google CloudKubernetes in Google Cloud
Kubernetes in Google Cloud
 
How to install ReactJS software
How to install ReactJS software How to install ReactJS software
How to install ReactJS software
 
ReactJS software installation
ReactJS software installationReactJS software installation
ReactJS software installation
 
Expert Day 2019 - CaaSP et CAP
Expert Day 2019 - CaaSP et CAPExpert Day 2019 - CaaSP et CAP
Expert Day 2019 - CaaSP et CAP
 
K8s
K8sK8s
K8s
 
7 Habits of Highly Effective Jenkins Users
7 Habits of Highly Effective Jenkins Users7 Habits of Highly Effective Jenkins Users
7 Habits of Highly Effective Jenkins Users
 
Setting up the hyperledger composer in ubuntu
Setting up the hyperledger composer in ubuntuSetting up the hyperledger composer in ubuntu
Setting up the hyperledger composer in ubuntu
 
Angular version 10 is here check out the new features, notable changes, depr...
Angular version 10 is here  check out the new features, notable changes, depr...Angular version 10 is here  check out the new features, notable changes, depr...
Angular version 10 is here check out the new features, notable changes, depr...
 
JOIN 2022: Patching 3rd party software Like a boss
JOIN 2022: Patching 3rd party software Like a bossJOIN 2022: Patching 3rd party software Like a boss
JOIN 2022: Patching 3rd party software Like a boss
 
Kubernetes+-CKA-+0400+-+Application+Lifecycle+Management.pdf
Kubernetes+-CKA-+0400+-+Application+Lifecycle+Management.pdfKubernetes+-CKA-+0400+-+Application+Lifecycle+Management.pdf
Kubernetes+-CKA-+0400+-+Application+Lifecycle+Management.pdf
 

Recently uploaded

Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 

Recently uploaded (20)

OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 

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