5 月 062020
 

滚动更新(Rolling Update)通过策略控制每次更新副本的数量来保障业务连续性。

准备使用httpd:2.4.41版本镜像的配置文件

[root@k8s-01 ~]# vi httpd-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: httpd
spec:
  replicas: 3
  selector:
    matchLabels:
      run: httpd
  template:
    metadata:
      labels:
        run: httpd
    spec:
      containers:
      - name: httpd
        image: httpd:2.4.41
        ports:
        - containerPort: 80

应用配置文件并获取deployment和replicaset及pod列表信息

[root@k8s-01 ~]# kubectl apply -f httpd-deployment.yaml
deployment.apps/httpd created
[root@k8s-01 ~]#
[root@k8s-01 ~]# kubectl get deployments.apps httpd -o wide
NAME    READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS   IMAGES         SELECTOR
httpd   3/3     3            3           20s   httpd        httpd:2.4.41   run=httpd
[root@k8s-01 ~]#
[root@k8s-01 ~]# kubectl get replicasets.apps -o wide
NAME               DESIRED   CURRENT   READY   AGE   CONTAINERS   IMAGES         SELECTOR
httpd-5bb8cdb99c   3         3         3       36s   httpd        httpd:2.4.41   pod-template-hash=5bb8cdb99c,run=httpd
[root@k8s-01 ~]#
[root@k8s-01 ~]# kubectl get pods -o wide
NAME                     READY   STATUS    RESTARTS   AGE   IP           NODE     NOMINATED NODE   READINESS GATES
httpd-5bb8cdb99c-454mz   1/1     Running   0          51s   10.244.2.4   k8s-03   <none>           <none>
httpd-5bb8cdb99c-qlzbh   1/1     Running   0          51s   10.244.1.5   k8s-02   <none>           <none>
httpd-5bb8cdb99c-rpt59   1/1     Running   0          51s   10.244.1.6   k8s-02   <none>           <none>
[root@k8s-01 ~]#

修改配置文件为使用httpd:2.4.43版本镜像

apiVersion: apps/v1
kind: Deployment
metadata:
  name: httpd
spec:
  replicas: 3
  selector:
    matchLabels:
      run: httpd
  template:
    metadata:
      labels:
        run: httpd
    spec:
      containers:
      - name: httpd
        image: httpd:2.4.43
        ports:
        - containerPort: 80

应用配置文件并获取deployment和replicaset列表信息

[root@k8s-01 ~]# kubectl apply -f httpd-deployment.yaml
deployment.apps/httpd configured
[root@k8s-01 ~]# kubectl get deployments.apps httpd -o wide
NAME    READY   UP-TO-DATE   AVAILABLE   AGE    CONTAINERS   IMAGES         SELECTOR
httpd   3/3     3            3           3m2s   httpd        httpd:2.4.43   run=httpd
[root@k8s-01 ~]# kubectl get replicasets.apps -o wide
NAME               DESIRED   CURRENT   READY   AGE     CONTAINERS   IMAGES         SELECTOR
httpd-5bb8cdb99c   0         0         0       3m11s   httpd        httpd:2.4.41   pod-template-hash=5bb8cdb99c,run=httpd
httpd-7c68f97dc5   3         3         3       24s     httpd        httpd:2.4.43   pod-template-hash=7c68f97dc5,run=httpd
[root@k8s-01 ~]#

查看滚动更新详情(每次只更新替换一个低版本镜像Pod)

[root@k8s-01 ~]# kubectl describe deployments.apps httpd
Name:                   httpd
Namespace:              default
CreationTimestamp:      Wed, 06 May 2020 09:20:14 +0000
Labels:                 <none>
Annotations:            deployment.kubernetes.io/revision: 2
                        kubectl.kubernetes.io/last-applied-configuration:
                          {"apiVersion":"apps/v1","kind":"Deployment","metadata":{"annotations":{},"name":"httpd","namespace":"default"},"spec":{"replicas":3,"selec...
Selector:               run=httpd
Replicas:               3 desired | 3 updated | 3 total | 3 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  run=httpd
  Containers:
   httpd:
    Image:        httpd:2.4.43
    Port:         80/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
  Progressing    True    NewReplicaSetAvailable
OldReplicaSets:  <none>
NewReplicaSet:   httpd-7c68f97dc5 (3/3 replicas created)
Events:
  Type    Reason             Age    From                   Message
  ----    ------             ----   ----                   -------
  Normal  ScalingReplicaSet  4m27s  deployment-controller  Scaled up replica set httpd-5bb8cdb99c to 3
  Normal  ScalingReplicaSet  100s   deployment-controller  Scaled up replica set httpd-7c68f97dc5 to 1
  Normal  ScalingReplicaSet  93s    deployment-controller  Scaled down replica set httpd-5bb8cdb99c to 2
  Normal  ScalingReplicaSet  93s    deployment-controller  Scaled up replica set httpd-7c68f97dc5 to 2
  Normal  ScalingReplicaSet  85s    deployment-controller  Scaled down replica set httpd-5bb8cdb99c to 1
  Normal  ScalingReplicaSet  85s    deployment-controller  Scaled up replica set httpd-7c68f97dc5 to 3
  Normal  ScalingReplicaSet  84s    deployment-controller  Scaled down replica set httpd-5bb8cdb99c to 0
[root@k8s-01 ~]#

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据