|NO.Z.00144|——————————|CloudNative|——|KuberNetes&资源调度.V14|——|statefulset.v06|更新.V03|分段更新|

一、StatefulSet分段更新:StatefulSet分段更新架构
二、StatefulSet分段更新说明
### --- StatefulSet分段更新说明

~~~     假设我们启动了5个Pod
~~~     假设Partition设置为2,那么他就只会更新web-2,web-3,web-4,而web-0和web-1他就不会更新
~~~     这个就可以实现灰度发布,先更新一部分,切一部分流量过来,看看效果。等待效验没有问题,把这个partition舍得再小一点,最终实现我们的预期。
~~~     若是partition为0的话,它不更新小于0的,没有小于0的,说明他就全部更新。
### --- StatefulSet分段更新实验

~~~     partition: 0 :在使用StatefulSet的时候我们启动了5个副本,
~~~     而把这个partition设置为3,它就会更新大于3的这个pod,不大于3的他就不更新。
~~~     所以说可以利用这个机制来实现简单的分段更新灰度发布。
三、StatefulSet分段更新partition资源准备
### --- 更改partition参数

[root@k8s-master01 ~]# kubectl edit sts web
spec:
  podManagementPolicy: OrderedReady
  replicas: 4                           // 副本数量设置为4个,
  updateStrategy:
    type: RollingUpdate
    rollingUpdate:
       partition: 2                     // 保留小于2的pod不更新。
### --- 查看启动的所有pod

[root@k8s-master01 ~]# kubectl get po   // 所有pod全部或启动
NAME    READY   STATUS    RESTARTS   AGE
web-0   1/1     Running   0          16m
web-1   1/1     Running   0          15m
web-2   1/1     Running   0          20m
web-3   1/1     Running   0          18s 
四、添加触发条件,触发更新
### --- 添加更新条件触发更新

[root@k8s-master01 ~]# kubectl edit sts web                 // 把它的版本设置为1.15.2
    spec:
      containers:
      - image: nginx:1.15.2 
### --- 查看更新后镜像的版本

[root@k8s-master01 ~]# kubectl get po -oyaml |grep image    // 查看镜像更新结果,更新的是web-2和web-3,而web-0和web-1是不会更新的。
              f:image: {}
              f:imagePullPolicy: {}
    - image: nginx:1.15.3
      imagePullPolicy: IfNotPresent
      image: nginx:1.15.3
      imageID: docker-pullable://nginx@sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d3
              f:image: {}
              f:imagePullPolicy: {}
    - image: nginx:1.15.3
      imagePullPolicy: IfNotPresent
      image: nginx:1.15.3
      imageID: docker-pullable://nginx@sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d3
              f:image: {}
              f:imagePullPolicy: {}
    - image: nginx:1.15.2
      imagePullPolicy: IfNotPresent
    - image: nginx:1.15.2
      imageID: ""
              f:image: {}
              f:imagePullPolicy: {}
    - image: nginx:1.15.2
      imagePullPolicy: IfNotPresent
      image: nginx:1.15.2
      imageID: docker-pullable://nginx@sha256:d85914d547a6c92faa39ce7058bd7529baacab7e0cd4255442b04577c4d1f424 
五、查看更新流程
### --- 查看更新流程

[root@k8s-master01 ~]# kubectl get po -l app=nginx -w
NAME    READY   STATUS    RESTARTS   AGE
web-3   1/1     Terminating   0          3m33s
web-3   0/1     Pending       0          0s
web-3   0/1     ContainerCreating   0          1s
web-3   1/1     Running             0          3s
web-2   1/1     Terminating         0          23m
web-2   0/1     Pending             0          0s
web-2   0/1     ContainerCreating   0          0s
web-2   1/1     Running             0          53s

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

 

posted on 2022-03-30 11:58  yanqi_vip  阅读(63)  评论(0)    收藏  举报

导航