Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Rolling updates of Kubernetes Pod applications (8)

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

I. Environmental preparation

We follow the environment of the previous section and do the following. If you are not clear, you can check the previous blog post first.

Rolling update is to update only a small number of copies at a time, and then update more copies after success, and finally complete the update of all copies. The biggest advantage of rolling updates is zero downtime, and there is always a copy running in the whole update process, thus ensuring business continuity.

II. Update

Let's take a look at the configuration file mytest-deploy.yaml from the previous section.

ApiVersion: extensions/v1beta1kind: Deploymentmetadata: name: mytestspec: replicas: 3 template: metadata: labels: run: mytestspec: containers:-name: mytest image: wangzan18/mytest:v1 ports:-containerPort: 80

We see that the image version is set to v1. Let's take a look at the ReplicaSet created.

[root@master] # kubectl get rs-o wideNAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTORmytest-88d46bf99 3 3 3 68 m mytest wangzan18/mytest:v1 pod-template-hash=88d46bf99,run=mytest

Currently running Pod is controlled by ReplicaSet mytest-88d46bf99, so we replace v1 with v2 in the configuration file and apply it again.

[root@master ~] # kubectl apply-f mytest-deploy.yaml deployment.extensions/mytest configured [root@master ~] # kubectl get podsNAME READY STATUS RESTARTS AGEmytest-56c55b4c6-6gjxc 1 Running 0 24smytest-56c55b4c6-f5trx 1 18smytest-56c55b4c6-sh6wd 1 Running 0 18smytest-56c55b4c6-sh6wd 1 Running 0 24smytest-88d46bf99-48f6n 1 Terminating 0 70mmytest-88d46bf99-mv6cf 1 * # kubectl get rs-o wideNAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTORmytest-56c55b4c6 3 3 3 59s mytest wangzan18/mytest:v2 pod-template-hash=56c55b4c6 Run=mytestmytest-88d46bf99 0 0 0 71m mytest wangzan18/mytest:v1 pod-template-hash=88d46bf99,run=mytest

We can see that the mirror of Deployment is updated to wangzan18/mytest:v2, a new ReplicaSet mytest-56c55b4c6 is created, and three new Pod are managed.

[root@master] # kubectl describe deployment mytestEvents: Type Reason Age From Message-Normal ScalingReplicaSet 4m9s deployment-controller Scaled up replica set mytest-56c55b4c6 to 1 Normal ScalingReplicaSet 4m9s deployment-controller Scaled down replica set mytest-88d46bf99 to 2 Normal ScalingReplicaSet 4m9s deployment-controller Scaled up Replica set mytest-56c55b4c6 to 2 Normal ScalingReplicaSet 4m3s deployment-controller Scaled down replica set mytest-88d46bf99 to 1 Normal ScalingReplicaSet 4m3s deployment-controller Scaled up replica set mytest-56c55b4c6 to 3 Normal ScalingReplicaSet 4m3s deployment-controller Scaled down replica set mytest-88d46bf99 to 0

Only one Pod is updated and replaced at a time.

III. Rollback

Each time kubectl apply updates the application, Kubernetes records the current configuration and saves it as a revision (version number) so that it can be rolled back to a particular revision.

By default, Kubernetes retains only the most recent revision, and you can increase the number of revision through the revisionHistoryLimit attribute in the Deployment configuration file.

We can roll back to the previous version with the command kubectl rollout undo.

[root@master ~] # kubectl rollout undo deploy mytestdeployment.extensions/mytest rolled back [root@master ~] # kubectl get rs-o wideNAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTORmytest-56c55b4c6 0.0012m mytest wangzan18/mytest:v2 pod-template-hash=56c55b4c6,run=mytestmytest-88d46bf99 3 3382m mytest wangzan18/mytest:v1 pod-template-hash=88d46bf99,run=mytest

You can see that the three Pod are again taken over by the ReplicaSet mirrored as wangzan18/mytest:v1.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report