|NO.Z.00143|——————————|CloudNative|——|KuberNetes&资源调度.V13|——|statefulset.v05|更新.V02|OnDelete|

三、StatefulSet更新策略二:OnDelete
### --- 添加配置参数,触发更新
~~~     # 更改StatefulSet配置参数镜像版本更改为1.15.3
~~~     使用 OnDelete去更新;它是不会触发更新的,只有把这个Pod删除之后才会触发更新镜像

[root@k8s-master01 ~]# kubectl edit sts web
    spec:
      containers:
      - image: nginx:1.15.3 
   updateStrategy:
    type: OnDelete
~~~     # 查看pod的状态

[root@k8s-master01 ~]# kubectl get po
NAME    READY   STATUS    RESTARTS   AGE
web-0   1/1     Running   0          7m21s
web-1   1/1     Running   0          7m18s
web-2   1/1     Running   0          8m1s
### --- 删除web-2触发更新
~~~     # 删除web-2;触发更新

[root@k8s-master01 ~]# kubectl delete po web-2
pod "web-2" deleted
~~~     # 查看已更新web-2.pod的镜像版本

[root@k8s-master01 ~]# kubectl get po web-2 -oyaml |grep image
            f:image: {}
            f:imagePullPolicy: {}
  - image: nginx:1.15.3                         // 可以查看到它的镜像版本是1.15.3
    imagePullPolicy: IfNotPresent
    image: nginx:1.15.3 
    imageID: docker-pullable://nginx@sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d3
~~~     # 查看未更新web-1.pod的镜像版本

[root@k8s-master01 ~]# kubectl get po web-1 -oyaml |grep image
            f:image: {}
            f:imagePullPolicy: {}
  - image: nginx:1.15.2                         // 而是web-1的镜像是1.15.2,没有更新
    imagePullPolicy: IfNotPresent
    image: nginx:1.15.2
    imageID: docker-pullable://nginx@sha256:d85914d547a6c92faa39ce7058bd7529baacab7e0cd4255442b04577c4d1f424
### --- 查看statefuel.OnDelete更新流程 
~~~     # 查看pod的更新流程   

[root@k8s-master01 ~]# kubectl get po -l app=nginx -w
web-2   1/1     Terminating         0          8m59s                                //删除web-2之后触发更新
web-2   0/1     Terminating         0          9m1s
web-2   0/1     Terminating         0          10m
web-2   0/1     Terminating         0          10m
web-2   0/1     Pending             0          0s
web-2   0/1     Pending             0          0s
web-2   0/1     ContainerCreating   0          1s
web-2   1/1     Running             0          3s   
~~~     # 那么我们同时删除web-0和web-1,让他触发更新

[root@k8s-master01 ~]# kubectl delete po web-0 web-1
pod "web-0" deleted
pod "web-1" deleted
~~~     # 查看对应的镜像版本

[root@k8s-master01 ~]# kubectl get po  -oyaml |grep image                           //可以看到所有的镜像版本都更新为1.15.3
              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.3
      imagePullPolicy: IfNotPresent
      image: nginx:1.15.3
      imageID: docker-pullable://nginx@sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d3
### --- 查看pod的更新流程

[root@k8s-master01 ~]# kubectl get po -l app=nginx -w
web-0   1/1     Terminating         0          12m
web-1   1/1     Terminating         0          12m
web-0   0/1     Terminating         0          12m
web-1   0/1     Terminating         0          12m
web-0   0/1     Terminating         0          13m
web-0   0/1     Pending             0          1s
web-0   0/1     ContainerCreating   0          1s
web-0   1/1     Running             0          3s
web-1   0/1     Pending             0          0s
web-1   0/1     ContainerCreating   0          0s
web-1   1/1     Running             0          2s

 
 
 
 
 
 
 
 
 

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   yanqi_vip  阅读(33)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示