Kubernetes rolling updates (uninterrupted smooth publishing)

Keywords: Programming Nginx Kubernetes

Kubernetes supports a feature called Rolling Update, which allows you to continue without interruption.
Nearly seamlessly upgrade and deploy applications, i. e. complete application updates without stopping external services.

What is rolling update?

Kubernetes supports what is known as rolling updates in order to achieve user insensitivity when deploying an application upgrade. This feature allows you to update pods sequentially, one at a time (in proportion to configuration), instead of stopping / updating the entire pod at a time. Make the release update and rollback without interrupting the service

kubectl rolling-update is only used Replication Controllers Use this command only when deploying an application. The latest version of Kubernetes recommends the use of Deployment Deploy the application.

Scroll Update

Create deployment deployment deployment nginx:v1

[root@k8s-master ~]# cat deployment.yaml 
apiVersion: apps/v1 
kind: Deployment
metadata:
  name: nginx-dm
  labels:
    app: nginx-dm
spec:
  replicas: 3
  minReadySeconds: 10
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  selector:
    matchLabels:
      app: nginx-dm
  template:
    metadata:
      labels:
        app: nginx-dm
    spec:
      containers:
      - name: nginx-dm
        image: registry.cn-hangzhou.aliyuncs.com/k8simages_wt/nginx:v1
        imagePullPolicy: Always
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-dm-service
spec:
  ports:
    - name: http
      port: 80
      targetPort: 80
  selector:
    app: nginx-dm
  type: NodePort
kubectl  apply -f deployment.yaml
[root@k8s-master ~]# kubectl  get pod -l app=nginx-dm
NAME                                READY   STATUS    RESTARTS   AGE
nginx-deployment-7597c9f695-b8qvt   2/2     Running   0          19s
nginx-deployment-7597c9f695-l4x6g   2/2     Running   0          19s
nginx-deployment-7597c9f695-nr724   2/2     Running   0          19s
Major parts
 replicas: 3
  minReadySeconds: 10
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
spec.replicas

Represents the number of copies of Pod. I've set up the initial configuration to replicate three Pods for rolling update testing

spec.minReadySeconds

This is the time from pod to Ready to Available. The pod is considered available after 10 seconds of rolling upgrade. It is recommended to set the appropriate time minReadySeconds to take into account the initialization time of the pod container.

spec.strategy

Define upgrade strategy for RollingUpdate

 spec.strategy.type

It could be "Recreate" or "Rolling Update." Rolling Update is the default value. Recreate kills all existing Pod s before creating a new one.
When Rolling Update, Deployment uses rolling update Update Pod in a way. You can specify maxUnavailable and maxSurge to control the rolling update process.

spec.strategy.rollingUpdate

If you set "Rolling Update" in spec.strategy.type, set Rolling Update in detail.

spec.strategy.rollingUpdate.maxSurge

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

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

Rolling update and validation

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

Scroll 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 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:v2
deployment.extensions/nginx-deployment image updated

View scrolling updates

^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


nginx-deployment-5f948bdcb8-2s28z   0/2   Pending   0     0s
nginx-deployment-5f948bdcb8-2s28z   0/2   Pending   0     0s
nginx-deployment-5f948bdcb8-2s28z   0/2   Init:0/1   0     0s
nginx-deployment-5f948bdcb8-2s28z   0/2   PodInitializing   0     1s
nginx-deployment-5f948bdcb8-2s28z   2/2   Running   0     3s
nginx-deployment-7597c9f695-l4x6g   2/2   Terminating   0     11h
nginx-deployment-5f948bdcb8-ljdqz   0/2   Pending   0     0s
nginx-deployment-5f948bdcb8-ljdqz   0/2   Pending   0     0s
nginx-deployment-5f948bdcb8-ljdqz   0/2   Init:0/1   0     1s
nginx-deployment-7597c9f695-l4x6g   0/2   Terminating   0     11h
nginx-deployment-7597c9f695-l4x6g   0/2   Terminating   0     11h
nginx-deployment-5f948bdcb8-ljdqz   0/2   PodInitializing   0     8s
nginx-deployment-5f948bdcb8-ljdqz   2/2   Running   0     10s
nginx-deployment-7597c9f695-l4x6g   0/2   Terminating   0     11h
nginx-deployment-7597c9f695-l4x6g   0/2   Terminating   0     11h
nginx-deployment-7597c9f695-b8qvt   2/2   Terminating   0     11h
nginx-deployment-5f948bdcb8-ksk8w   0/2   Pending   0     0s
nginx-deployment-5f948bdcb8-ksk8w   0/2   Pending   0     0s
nginx-deployment-5f948bdcb8-ksk8w   0/2   Init:0/1   0     0s
nginx-deployment-7597c9f695-b8qvt   0/2   Terminating   0     11h
nginx-deployment-7597c9f695-b8qvt   0/2   Terminating   0     11h
nginx-deployment-7597c9f695-b8qvt   0/2   Terminating   0     11h
nginx-deployment-5f948bdcb8-ksk8w   0/2   PodInitializing   0     2s
nginx-deployment-5f948bdcb8-ksk8w   2/2   Running   0     4s

Posted by mightymouse on Wed, 09 Oct 2019 09:31:08 -0700