# 命令运行完毕,立即查看,发现已经有4个开始准备退出了 [root@master ~]# kubectl get pods -n dev NAME READY STATUS RESTARTS AGE pc-replicaset-5fnt7 0/1 Terminating 0 2m22s pc-replicaset-gs59p 0/1 Terminating 0 2m22s pc-replicaset-j8jd7 0/1 Terminating 0 4m49s pc-replicaset-qbbzj 0/1 Terminating 0 2m22s pc-replicaset-rds28 1/1 Running 0 4m49s pc-replicaset-w2xhs 1/1 Running 0 4m49s
# 稍等片刻,就只剩下2个了 [root@master ~]# kubectl get pods -n dev NAME READY STATUS RESTARTS AGE pc-replicaset-rds28 1/1 Running 0 5m2s pc-replicaset-w2xhs 1/1 Running 0 5m2s
# 再次查看,发现镜像版本已经变更了 [root@master ~]# kubectl get rs -n dev -o wide NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR pc-replicaset 2 2 2 7m47s nginx nginx:1.17.2 app=nginx-pod
# 同样的道理,也可以使用命令完成这个工作 # kubectl set image rs rs名称 容器=镜像版本 -n namespace [root@master ~]# kubectl set image rs pc-replicaset nginx=nginx:1.17.1 -n dev replicaset.apps/pc-replicaset image updated
# 再次查看,发现镜像版本已经变更了 [root@master ~]# kubectl get rs -n dev -o wide NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR pc-replicaset 2 2 2 8m46s nginx nginx:1.17.1 app=nginx-pod
删除ReplicaSet
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# 使用kubectl delete命令会删除此RS以及它管理的Pod # 在kubernetes删除RS前,会将RS的replicas调整为0,等待所有的Pod被删除后,再执行RS对象的删除 [root@master ~]# kubectl delete rs pc-replicaset -n dev replicaset.apps "pc-replicaset" deleted [root@master ~]# kubectl get pod -n dev -o wide No resources found in dev namespace.
# 如果希望仅仅删除RS对象(保留Pod),可以使用kubectl delete命令时添加--cascade=false选项(不推荐,控制器都不要了留着Pod干嘛呢) [root@master ~]# kubectl delete rs pc-replicaset -n dev --cascade=false replicaset.apps "pc-replicaset" deleted [root@master ~]# kubectl get pods -n dev NAME READY STATUS RESTARTS AGE pc-replicaset-cl82j 1/1 Running 0 75s pc-replicaset-dslhb 1/1 Running 0 75s