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

How to implement scrolling update in Kubernetes

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article introduces you how to achieve rolling update in Kubernetes, the content is very detailed, interested friends can refer to, hope to be helpful to you.

What is a rolling update?

In order to make K8s unaware of users when the application upgrade is deployed, Kubernetes supports a feature called rolling update. This feature allows you to update the pod sequentially, one at a time (proportionally configured), rather than stopping / updating the entire pod at a time. Enable release updates and rollback without service disruption

Kubectl rolling-update uses this command only when deploying applications using Replication Controllers. The latest version of Kubernetes recommends using Deployment to deploy applications. Scrolling update

Create deployment deployment nginx:v1

[root@k8s-master ~] # cat deployment.yaml apiVersion: apps/v1 kind: Deploymentmetadata: name: nginx-dm labels: nginx-dmspec: replicas: 3 minReadySeconds: 10 strategy: type: RollingUpdate rollingUpdate: maxSurge: 1 maxUnavailable: 0 selector: matchLabels: app: nginx-dm template: metadata: labels: app: nginx-dmspec: containers:-name: nginx-dm Image: registry.cn-hangzhou.aliyuncs.com/k8simages_wt/nginx:v1 imagePullPolicy: Always ports:-containerPort: 80---apiVersion: v1kind: Servicemetadata: name: nginx-dm-servicespec: ports:-name: http port: 80 targetPort: 80 selector: app: nginx-dm type: NodePortkubectl apply-f deployment.yaml [root@k8s-master ~] # kubectl get pod-l app=nginx-dmNAME READY STATUS RESTARTS AGEnginx-deployment-7597c9f695-b8qvt 2 Running 0 19snginx-deployment-7597c9f695-l4x6g 2 Running 0 19snginx-deployment-7597c9f695-nr724 2 Running 0 19s main part replicas: 3 minReadySeconds: 10 strategy: type: RollingUpdate rollingUpdate: maxSurge: 1 maxUnavailable: 0spec.replicas

Represents the number of copies of the Pod. I have set up the initial configuration to copy three Pod for rolling update testing

Spec.minReadySeconds

This is the time from pod to Ready phase to Available phase. After 10 seconds of rolling upgrade, it is considered that the pod is ready. It is recommended to set an appropriate time minReadySeconds to consider the initialization time of the pod container.

Spec.strategy

Define the upgrade policy for detailed settings for RollingUpdate

Spec.strategy.type

Can be "Recreate" or "RollingUpdate". "RollingUpdate" is the default. When Recreate, all existing Pod are killed before a new Pod is created.

When RollingUpdate, Deployment updates Pod in the same way as rolling update. You can specify maxUnavailable and maxSurge to control the rolling update process.

Spec.strategy.rollingUpdate

If you set "RollingUpdate" in spec.strategy.type, set up RollingUpdate in detail.

Spec.strategy.rollingUpdate.maxSurge

The maximum number of pod that can be created during a rolling update exceeds the specified number of pod. 1 means that a pod will be deleted only when a new pod is created, and so on. It can be a specific integer, or it can be 100% and the default value is 25%

At most one Pod is not available during the update process. The maximum number of pod that cannot be used during rollgin updates. This value can be set to the absolute number of pod with integers greater than 0, and the percentage representation is also possible, such as "25%". The percentage calculation in maxUnavailable is rounded down, and the default value is 25%. The maxSurge and maxUndeterminable values cannot be zero at the same time. Rolling updates and validation

In the case of application deployment using Deployment, the kubectl set image command is used to update the image version.

Scrolling update progress monitoring view

Kubectl get pod-w

^ C [root@k8s-master ~] # kubectl get pod-w | grep nginx

Nginx-deployment-7597c9f695-b8qvt 2/2 Running 0 11h

Nginx-deployment-7597c9f695-l4x6g 2/2 Running 0 11h

Nginx-deployment-7597c9f695-nr724 2/2 Running 0 11h

Update the nginx:v2 version with the kubectl set image command

[root@k8s-master ~] # kubectl set image deployment/nginx-deployment nginx-dm=registry.cn-hangzhou.aliyuncs.com/k8simages_wt/nginx:v2deployment.extensions/nginx-deployment image updated

View rolling updates

^ C [root@k8s-master ~] # kubectl get pod-w | grep nginxnginx-deployment-7597c9f695-b8qvt 2 Running 2 Running 0 11hnginx-deployment-7597c9f695-l4x6g 2 11hnginx-deployment-7597c9f695-l4x6g 2 Running 0 11hnginx-deployment-7597c9f695-nr724 2 2s28z 2 Running 0 11hnginx-deployment-5f948bdcb8-2s28z 0 Pending 0 0snginx-deployment-5f948bdcb8-2s28z 0 2s28z 0 Pending 0 0snginx-deployment-5f948bdcb8-2s28z 0 / 2 Init:0/1 00 11hnginx-deployment-5f948bdcb8-ljdqz house deploymently5f948bdcb8-2s28z 0 2s28z 2 PodInitializing 0 1snginx-deployment-5f948bdcb8-2s28z 2 Running 0 3snginx-deployment-7597c9f695-l4x6g 2, 2 Terminating 0 snginx 0, 2 Pending 0 11hnginx-deployment-5f948bdcb8-ljdqz 0, 2 Pending 0 0snginx-deployment-5f948bdcb8-ljdqz 0, 2 Pending 0 0snginx-deployment-5f948bdcb8-ljdqz 0, 2 Init:0/1 0 1snginx- Deployment-7597c9f695-l4x6g 0/2 Terminating 0 11hnginx-deployment-7597c9f695-l4x6g 0/2 Terminating 0 11hnginx-deployment-5f948bdcb8-ljdqz 0/2 PodInitializing 0 8snginx-deployment-5f948bdcb8-ljdqz 2/2 Running 0 10snginx-deployment-7597c9f695-l4x6g 0/2 Terminating 0 11hnginx-deployment-7597c9f695-l4x6g 0/2 Terminating 0 11hnginx-deployment-7597c9f695-b8qvt 2/2 Terminating 0 11hnginx-deployment -5f948bdcb8-ksk8w 0Terminating 2 Pending 0 0snginx-deployment-5f948bdcb8-ksk8w 0ta 2 Pending 0 0snginx-deployment-5f948bdcb8-ksk8w 0 Init:0/1 0 0snginx-deployment-7597c9f695-b8qvt 0 0snginx-deployment-7597c9f695-b8qvt 0 0snginx-deployment-7597c9f695-b8qvt 0 Terminating 0 11hnginx-deployment-7597c9f695-b8qvt 0 Unix 2 Terminating 0 11hnginx-deployment-7597c9f695-b8qvt 0 lap 2 Terminating 0 11hnginx-deployment-5f948bdcb8-ksk8w 0 Unix 2 PodInitializing 0 2snginx-deployment-5f948bdcb8-ksk8w 2 Running 0 4s on how to implement rolling updates in Kubernetes, that's all. I hope the above content can be of some help to you and learn more knowledge. If you think the article is good, you can share it for more people to see.

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

Internet Technology

Wechat

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

12
Report