In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Scrolling update
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.
Next, we deploy three copies of the application, the initial image is httpd:2.2.31, and then update it to httpd:2.2.32.
The configuration file for httpd:2.2.31 is as follows:
ApiVersion: apps/v1beta1kind: Deploymentmetadata: name: httpdspec: replicas: 3 template: metadata: labels: run: httpdspec: containers:-name: httpd image: httpd:2.2.31 ports:-containerPort: 80
Deployed through kubectl apply.
[root@k8s-master ~] # kubectl apply-f httpd.yml deployment.apps/httpd created [root@k8s-master ~] # [root@k8s-master ~] # kubectl get deployments httpd-o wideNAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTORhttpd 0There 3 3014s httpd httpd:2.2.31 run=httpd [root@k8s-master ~] # kubectl get replicasets-o wideNAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTORhttpd-56df754d56 3 3 3 37s httpd httpd:2.2.31 pod-template-hash=56df754d56 Run=httpd [root@k8s-master ~] # kubectl get podNAME READY STATUS RESTARTS AGEhttpd-56df754d56-5hjt6 1 to 1 Running 0 52shttpd-56df754d56-ngw9l 1 to 1 Running 0 52shttpd-56df754d56-qtgbt 1 to 1 Running 0 52s
The deployment process is as follows:
Create Deployment httpd, create ReplicaSet httpd-551879778, create three Pod, the current image is httpd:2.2.31
Replace httpd:2.2.31 with httpd:2.2.32 in the configuration file and execute kubectl apply again.
ApiVersion: apps/v1beta1kind: Deploymentmetadata: name: httpdspec: replicas: 3 template: metadata: labels: run: httpdspec: containers:-name: httpd image: httpd:2.2.32 ports:-containerPort: 80 [root@k8s-master ~] # kubectl apply-f httpd.yml deployment.apps/httpd configured [root@k8s-master ~] # [root@k8s-master ~] # kubectl get deployments httpd -o wideNAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTORhttpd 3 + 3 1 3 3m54s httpd httpd:2.2.32 run=httpd [root@k8s-master] # kubectl get replicasets-o wideNAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTORhttpd-56df754d56 2 2 2 4m8s httpd httpd : 2.2.31 pod-template-hash=56df754d56 Run=httpdhttpd-77896d99b5 2 2 1 28s httpdhttpd: 2.2.32 pod-template-hash=77896d99b5,run=httpd [root@k8s-master ~] # [root@k8s-master ~] # kubectl get podNAME READY STATUS RESTARTS AGEhttpd-77896d99b5-pk52m 1 Running 0 24shttpd-77896d99b5-pmlr9 1 24shttpd-77896d99b5-pmlr9 1 Running 0 40shttpd-77896d99b5-spn96 1 Running 0 9s
We found the following changes:
The image update for Deployment httpd creates a new ReplicaSet httpd-1276601241 for httpd:2.2.32, the image is httpd:2.2.32, and manages three new Pod. There is no Pod in the previous ReplicaSet httpd-551879778.
The conclusion is that the three httpd:2.2.31 Pod of ReplicaSet httpd-551879778 has been replaced by the three httpd:2.2.32 Pod of ReplicaSet httpd-1276601241.
The specific process can be viewed through kubectl describe deployment httpd.
Events: Type Reason Age From Message-Normal ScalingReplicaSet 6m4s deployment-controller Scaled up replica set httpd-56df754d56 to 3 Normal ScalingReplicaSet 2m23s deployment-controller Scaled up replica set httpd-77896d99b5 to 1 Normal ScalingReplicaSet 2m7s deployment-controller Scaled down replica set httpd-56df754d56 to 2 Normal ScalingReplicaSet 2m7s deployment-controller Scaled up replica set httpd-77896d99b5 to 2 Normal ScalingReplicaSet 112s deployment-controller Scaled down replica set httpd-56df754d56 to 1 Normal ScalingReplicaSet 112s deployment-controller Scaled up replica set httpd-77896d99b5 to 3 Normal ScalingReplicaSet 110s deployment-controller Scaled down replica set httpd-56df754d56 to 0
Update and replace only one Pod at a time:
ReplicaSet httpd-1276601241 adds one Pod to the total of 1. ReplicaSet httpd-551879778 decreases by one Pod, with a total of 2. ReplicaSet httpd-1276601241 adds one Pod to the total of 2. ReplicaSet httpd-551879778 decreases by one Pod, with a total of 1. ReplicaSet httpd-1276601241 adds one Pod to the total of 3. ReplicaSet httpd-551879778 decreases by one Pod, with a total of 0.
The number of Pod replaced each time can be customized. Kubernetes provides two parameters, maxSurge and maxUnavailable, to finely control the number of Pod replacements, which we will discuss later in conjunction with the Health Check feature.
Roll back
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.
Let's practice the rollback feature. The application has the following three configuration files, httpd.v1.yml,httpd.v2.yml and httpd.v3.yml, corresponding to different httpd images 2.4.16, 2.4.17 and 2.4.18:
ApiVersion: apps/v1beta1kind: Deploymentmetadata: name: httpdspec: revisionHistoryLimit: 10 replicas: 3 template: metadata: labels: run: httpdspec: containers:-name: httpd image: httpd:2.4.16 ports:-containerPort: 80apiVersion: apps/v1beta1kind: Deploymentmetadata: name: httpdspec: revisionHistoryLimit: 10 replicas: 3 template: metadata: labels: run: httpdspec: Containers:-name: httpd image: httpd:2.4.17 ports:-containerPort: 80apiVersion: apps/v1beta1kind: Deploymentmetadata: name: httpdspec: revisionHistoryLimit: 10 replicas: 3 template: metadata: labels: run: httpdspec: containers:-name: httpd image: httpd:2.4.18 ports:-containerPort: 80
Deploy and update applications through kubectl apply:
[root@k8s-master] # kubectl apply-f httpd.v1.yml-- record deployment.apps/httpd created [root@k8s-master] # kubectl get deployments httpd-o wideNAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTORhttpd 3max httpd httpd:2.4.16 run=httpd [root@k8s-master] # kubectl apply-f httpd.v2.yml-- record deployment. Apps/httpd configured [root@k8s-master] # kubectl get deployments httpd-o wide NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTORhttpd 3 + 3 1 3 2m24s httpd httpd:2.4.17 run=httpd [root@k8s-master] # kubectl apply-f httpd.v3.yml-- record deployment.apps/httpd configured [root@k8s-master ~] # kubectl get deployments httpd-o wide NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTORhttpd 3/3 1 3 2m43s httpd httpd:2.4.18 run=httpd
The role of record is to record the current command in the revision record so that we can know which configuration file each revison corresponds to. View revison history through kubectl rollout history deployment httpd.
[root@k8s-master] # kubectl rollout history deployment httpd deployment.extensions/httpd REVISION CHANGE-CAUSE1 kubectl apply-filename=httpd.v1.yml-record=true2 kubectl apply-filename=httpd.v2.yml-record=true3 kubectl apply-filename=httpd.v3.yml-record=true
CHANGE-CAUSE is the result of-- record. If you want to roll back to a version, such as revision 1, you can execute the command kubectl rollout undo deployment httpd-- to-revision=1:
[root@k8s-master] # kubectl rollout undo deployment httpd-- to-revision=1deployment.extensions/httpd rolled back [root@k8s-master ~] # kubectl get deployments. Httpd-o wideNAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTORhttpd 3 bat 3 3 6m50s httpd httpd:2.4.16 run=httpd
At this point, the revison history changes accordingly.
[root@k8s-master] # kubectl rollout history deployment httpd deployment.extensions/httpd REVISION CHANGE-CAUSE2 kubectl apply-filename=httpd.v2.yml-record=true3 kubectl apply-filename=httpd.v3.yml-record=true4 kubectl apply-filename=httpd.v1.yml-record=true
Revison 1 becomes revison 4. However, we can know the specific meaning of each revison through CHANGE-CAUSE. So be sure to add the-- record parameter to the kubectl apply.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.