1.Deployment The details of the controller contain the relevant configuration of its update strategy .kubectl describe Output in command StrategyType、RollingUpdateStrategy Field etc. ;
[email protected]:~# kubectl describe deploy sleep
Name: sleep
Namespace: default
CreationTimestamp: Wed, 25 May 2022 15:03:14 +0800
Labels: <none>
Annotations: deployment.kubernetes.io/revision: 1
Selector: app=sleep
Replicas: 1 desired | 1 updated | 1 total | 1 available | 0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 25% max unavailable, 25% max surge
# The default update strategy is 25%
1.Deployment Update strategy :
Deployment The controller supports two update strategies : Scroll to update (roolling update) And rebuild creation (recreate) Also known as single batch update .
1. The reconstruction (Recreate), When the update policy is set to Recreate, When updating the image , It will first delete the currently running Pod, After being completely killed , Re create a new RS(ReplicaSet) Then start the corresponding Pod, During the whole update process , The service will not be available for a period of time . Also known as single batch update .
2. Scroll to update (Rolling Update) Rolling update is the default update strategy , Update only one batch at a time Pod, When updated Pod Update another batch after it is ready , Until all updates are completed ; This strategy achieves the goal of uninterrupted service , But in the update process , The response content obtained by different clients may come from different versions of applications . New and old versions will coexist .
2.ReCreate practice ;
Recreate There are three steps :
1. Kill all the old versions Pod, here Pod Unable to provide external services normally ;
2. Create a new RS, Start a new Pod;
3. wait for Pod be ready , External services ;
2.1 Application configuration example
# Must be in Spec Clearly defined in the field strategy Rolling update strategy and type type
[email protected]:~# cat nginx-deployment-test.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: deployment-nginx-test
namespace: default
spec:
strategy: # Rolling update strategy
type: Recreate # Recreate It means single batch update .
replicas: 2
selector:
matchLabels:
app: nginx-deployment
template:
metadata:
labels:
app: nginx-deployment
spec:
containers:
- name: nginx
image: nginx:1.16
#imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 80
[email protected]:~# kubectl apply -f nginx-deployment-test.yaml
2.2 Access test , At the same time, the configuration file is modified Nginx Will the version testing service of be interrupted ;
# Following any symbol will report an error Nginx The error page of , The current version is 1.16. Of course, to prove nginx edition .
[email protected]:~# curl 10.107.246.117/v
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.16.1</center>
</body>
</html>
2.3 The current version is 1.16, Now test rolling update ;
1. modify yaml Configuration file modification edit configuration file spec.containers.image Field modification Nginx Version of
2. adopt set image To modify the
I'm through set image To modify the .
[email protected]:~# kubectl set image deployment/deployment-nginx-test nginx=nginx:latest
deployment.apps/deployment-nginx-test image updated
2.4 Access test , Indeed, there is business access interruption in the middle , Therefore, this method is not recommended in the production environment . Old in the process of updating Pod Is in Terminating state .
[email protected]:~# while sleep 0.5; do curl http://10.107.246.117/version;done
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.16.1</center>
</body>
</html>
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.16.1</center>
</body>
</html>
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.16.1</center>
</body>
</html>
<html>
curl: (7) Failed to connect to 10.107.246.117 port 80: Connection refused
curl: (7) Failed to connect to 10.107.246.117 port 80: Connection refused
curl: (7) Failed to connect to 10.107.246.117 port 80: Connection refused
curl: (7) Failed to connect to 10.107.246.117 port 80: Connection refused
curl: (7) Failed to connect to 10.107.246.117 port 80: Connection refused
curl: (7) Failed to connect to 10.107.246.117 port 80: Connection refused
curl: (7) Failed to connect to 10.107.246.117 port 80: Connection refused
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.21.5</center>
</body>
</html>
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.21.5</center>
</body>
</html>
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.21.5</center>
</body>
</html>
3.RollingUpdate practice
Rolling update , During the application upgrade, it is also necessary to ensure the availability Pod The number of objects is not lower than the threshold to ensure that the service requests of clients can be continuously processed , The way of change and Pod The number of objects will range through spec.strategy.rollingUpdate.maxSurge and spec.strategy.rollingPudate.maxUnavailable Two attributes are defined at the same time ;
Scroll to update (RollingUpdate) Update only one batch at a time Pod, When updated Pod When ready , Update another batch , Until all updates are completed , This strategy achieves the goal of uninterrupted service , During the update process, different application versions may appear and coexist , Service provision at the same time .
1. Create a new RS, Then run the new... According to the new image Pod.
2. Delete the old Pod, Start a new Pod, When new Pod When ready , Continue deleting old Pod, Start new Pod.
3. Continue the second step , All the way to Pod Have been updated successfully .
3.1 Prepare application profile
# This field needs to be configured as RollingUpdate
spec:
strategy:
type: RollingUpdate
# Application profile , The current version Nginx yes 1.16 edition , To scroll to 1.21.5
[email protected]:~# cat nginx-deployment-test.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: deployment-nginx-test
namespace: default
spec:
strategy:
type: RollingUpdate
replicas: 2
selector:
matchLabels:
app: nginx-deployment
template:
metadata:
labels:
app: nginx-deployment
spec:
containers:
- name: nginx
image: nginx:1.16
#imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 80
[email protected]:~# kubectl apply -f nginx-deployment-test.yaml
deployment.apps/deployment-nginx-test created
# Pod It also works normally .
[email protected]:~# kubectl get pods -l app=nginx-deployment
NAME READY STATUS RESTARTS AGE
deployment-nginx-test-65b579f8d5-gdpd5 1/1 Running 0 3m14s
deployment-nginx-test-65b579f8d5-spq9w 1/1 Running 0 3m14s
3.2, We now visit the front end Service;OK The version has always been 1.16;
[email protected]:~# while sleep 0.5; do curl http://10.103.162.78/v;done
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.16.1</center>
</body>
</html>
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.16.1</center>
</body>
</html>
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.16.1</center>
3.3 modify yaml Profile upgrade ; And observe whether the business is interrupted ;
# Pod state ;1.16 Version of Pod yes 65b579f8d5, Now it is 76f7b87b7c
[email protected]:~# kubectl get pods
deployment-nginx-test-76f7b87b7c-n2jmm 1/1 Running 0 35s
deployment-nginx-test-76f7b87b7c-qvxhg 0/1 ContainerCreating 0 11s
# Rolling upgrade status ;
[email protected]:~# kubectl apply -f nginx-deployment-test.yaml && kubectl rollout status deploy deployment-nginx-test
deployment.apps/deployment-nginx-test configured
Waiting for deployment "deployment-nginx-test" rollout to finish: 1 out of 2 new replicas have been updated...
Waiting for deployment "deployment-nginx-test" rollout to finish: 1 out of 2 new replicas have been updated...
Waiting for deployment "deployment-nginx-test" rollout to finish: 1 out of 2 new replicas have been updated...
Waiting for deployment "deployment-nginx-test" rollout to finish: 1 old replicas are pending termination...
Waiting for deployment "deployment-nginx-test" rollout to finish: 1 old replicas are pending termination...
deployment "deployment-nginx-test" successfully rolled out
# see Replicaset; Now? 65b579 Of Pod The quantity is placed in 0
[email protected]:~# kubectl get replicaset
deployment-nginx-test-577977f4b6 2 2 2 7m
deployment-nginx-test-65b579f8d5 0 0 0 17m
3.4 Observation visit
# Business access is normal , Without interruption , But there will be coexistence of new and old versions for a period of time ;
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.21.5</center>
</body>
</html>
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.16.1</center>
</body>
</html>
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.21.5</center>
</body>
</html>
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.16.1</center>
</body>
</html>
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.21.5</center>
</body>
</html>
^C
4. Rollback of application
4.1. We can view the updated historical version through the command ;
[email protected]:~# kubectl rollout history deployment deployment-nginx-test
deployment.apps/deployment-nginx-test
REVISION CHANGE-CAUSE
1 <none>
2 <none>
4.2. You can also view the specific image details , Keep up with serial number ;
[email protected]:~# kubectl rollout history deploy deployment-nginx-test --revision=2
deployment.apps/deployment-nginx-test with revision #2
Pod Template:
Labels: app=nginx-deployment
pod-template-hash=76f7b87b7c
Containers:
nginx:
Image: nginx:1.16
Port: 80/TCP
Host Port: 0/TCP
Environment: <none>
Mounts: <none>
Volumes: <none>
4.3. Now I want to rollback to 1.16 This version ;
[email protected]:~# kubectl rollout undo deploy deployment-nginx-test --to-revision=2 && kubectl rollout status deploy deployment-nginx-test
deployment.apps/deployment-nginx-test rolled back
Waiting for deployment "deployment-nginx-test" rollout to finish: 1 out of 2 new replicas have been updated...
Waiting for deployment "deployment-nginx-test" rollout to finish: 1 out of 2 new replicas have been updated...
Waiting for deployment "deployment-nginx-test" rollout to finish: 1 out of 2 new replicas have been updated...
Waiting for deployment "deployment-nginx-test" rollout to finish: 1 old replicas are pending termination...
Waiting for deployment "deployment-nginx-test" rollout to finish: 1 old replicas are pending termination...
deployment "deployment-nginx-test" successfully rolled out
4.4. Observe the access status ; There will also be the alternation of new and old versions
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.21.5</center>
</body>
</html>
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.16.1</center>
</body>
</html>
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.21.5</center>
</body>
</html>
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.16.1</center>
</body>
</html>
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.21.5</center>
</body>
</html>
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.16.1</center>
</body>
</html>
^C
4.5. see Pod and Replicaset
[email protected]:~/cloud-Native/deployment/replicas# kubectl get pods -l app=nginx-deployment
NAME READY STATUS RESTARTS AGE
deployment-nginx-test-76f7b87b7c-5tx7z 1/1 Running 0 2m34s
deployment-nginx-test-76f7b87b7c-t9ld2 1/1 Running 0 2m57s
# There's no problem .
[email protected]:~/cloud-Native/deployment/replicas# kubectl get replicaset -l app=nginx-deployment
NAME DESIRED CURRENT READY AGE
deployment-nginx-test-577977f4b6 0 0 0 20m
deployment-nginx-test-65b579f8d5 0 0 0 31m
deployment-nginx-test-76f7b87b7c 2 2 2 24m
Deployment Rolling update strategy . More articles about
- Let's talk about it in detail k8s deployment The rolling update of ( Two )
One . Knowledge preparation ● This article explores in detail deployment Behavior while scrolling updates ● Related parameters are introduced : livenessProbe: Viability detection . Judge pod Has it stopped readinessProbe: be ready ...
- Let's talk about it in detail k8s deployment The rolling update of ( One )
One . Knowledge preparation ● This article explores in detail deployment Behavior while scrolling updates Two . Environmental preparation Components edition OS Ubuntu 18.04.1 LTS docker 18.06.0-ce 3、 ... and . Prepare the mirror First of all to prepare ...
- deployment control pod Rolling updates and rollback
to update pod There are two ways to mirror : Mode one :kubectl set image deployment/${deployment name} ${container name}=${image} example : kubec ...
- Log4j2 in RollingFile File rolling update mechanism
One . What is? RollingFile RollingFileAppender yes Log4j2 One of them can realize the rolling update of log files (rollover) Of Appender. rollover When certain conditions are met ( ...
- Kubernetes In the cluster Service The rolling update of
Kubernetes In the cluster Service The rolling update of February 9, 2017 0 comments In the era of mobile Internet , Consumer behavior has been “ All weather ”, So , The business system of businesses should also be maintained 7×24 Provide services 24 hours a day to meet ...
- k8s Survival probe , Scroll to update
The original article Survival probe Kubelet Use liveness probe( Survival probe ) To determine when to restart the container . for example , When the application is running but can't do anything further ,liveness The probe will capture deadlock, Restart in ...
- k8s The way to the pit (14)scheduler Dispatch kubelet Management and health examination Update strategy
kubelet The main function Pod management stay kubernetes In the design of , The most basic management unit is pod, instead of container.pod yes kubernetes A layer of packaging on the container , Run by a group in the same ...
- 《 Front end operation and maintenance 》 5、 ... and 、k8s--3 Grayscale Publishing 、 Rolling updates with probes
One . Grayscale Publishing Grayscale publishing is a publishing method , It's also called the canary , The origin is that miners put a canary into the well before going down , If the Canary stops calling , It means high gas concentration . The reason is that canaries are very sensitive to gas . Grayscale publishing is : Will be based on existing old applications ...
- k8s Scroll to update ( 6、 ... and )-- Technology flow ken
practice Rolling update is to update only a small number of copies at a time , After success , Update more copies , Finally complete the update of all copies . The biggest benefit of rolling update is zero downtime , There is always a copy running throughout the update process , This ensures business continuity . Let's deploy the three copy application , ...
- docker swarm Cluster building and rolling update
Based on the environment , Three virtual machines 172.17.3.70 172.17.3.71 172.17.3.72 The system configuration :centos 7, close selinux Need to optimize the basic configuration : [[email protected] ~]# vim ...
Random recommendation
- 【 Tool use 】sublime text3
import urllib.request,os,hashlib; h = 'df21e130d211cfc94d9b0905775a7c0f' + '1e3d39e33b79698005270310 ...
- android studio Use SVN Lock file , Prevent others from modifying ( be based on Android studio 1.4 )
First, suppose you develop A , and Development B , In the use of SVN Project management . that A How to A locked file , prevent B modify . 1. First step , Lock this file Complete this step , Don't lock this file . 2. The second step , If ...
- asterisk
http://www.asterisk.org/ asterisk is the world's most widely adopted open source commnuctions platfo ...
- ngx_cdecl
ngx_cdecl As a cross platform , Now understanding is limited , Add later _cdecl yes C Declaration Abbreviation (declaration, Statement ), Express C Language default function call method : All the parameters are put on the stack from right to left , these ...
- iOS Development Notes be based on wsdl2objc call asp.net WebService
1. Get ready First download the tools to be used later WSDL2ObjC-0.6.zip WSDL2ObjC-0.7-pre1.zip I use it WSDL2ObjC-0.6.zip 1.1 build asp.net WebServ ...
- Linux-hexdump Command debugging event drive — Detailed explanation (13)
hexdump: Check the contents of the file , For example, some strings contained in binary files , Usually used to debug the driver 1. debugging Keyboard drive Explain When we insmod After mounting the keyboard driver , Find the keyboard driver is placed in the event1 In the device , No press at this time ...
- Design patterns C++ Learning notes 12 (Command Command mode )
Command mode , Encapsulate a request as an object , This allows you to parameterize customers with different requests : Queues or logs requests , And support undo operations . It should be a relatively simple mode . 12.1. explain main(), Customer CIn ...
- msp430 Learning notes -TA
Timer ,CCR2,CCR1 The three share an interrupt vector Timer A It's a 16 Bit timing / Counter . It has 3 Capture / Compare register : It can support multiple timing control . Multiple captures / Compare features and multiple PWM Output : It has a wide range of interrupt functions , Interrupts can be overflowed by the counter ...
- WebRTC Source code analysis ( One ): Analysis of Android camera acquisition implementation
WebRTC The amount of code is not small , It's not realistic to see it at one time , In this series , I will try to figure out three questions : How to establish a connection between clients ? How to realize data transmission between clients ? Audio and video data acquisition . preview . code . transmission . decode . Render the whole process . ...
- 【LOJ】#2340. 「WC2018」 State division
Answer key Learn something that people all over the world can't do except me Subset transformation ! Do I want to talk about this problem as a board ? Wait, this question seems to be a board ...WC It's exciting to write board questions = = Pretend we've all done HAOI2015 Of FMT topic , We all know something FMT How to solve or ...









