K8S中Pod控制器之Deployment(Deploy)控制器

news/2025/1/19 22:14:24/

Deployment(Deploy)控制器

  • 从Kubernetes 1.2版本开始,引入了Deployment控制器,它提供了一种更高级别的抽象来管理应用的生命周期,包括应用的声明式更新、回滚、暂停和恢复等。Deployment的设计目标是简化应用的部署和扩展,同时提供强大的应用更新和版本管理功能。

  • 这种控制器并不直接管理pod,而是通过管理ReplicaSet来间接管理Pod,即:Deployment管理ReplicaSet,ReplicaSet管理Pod。所以Deployment比ReplicaSet功能更加强大。

image-20240511144634082

Deployment主要功能

  • ReplicaSet管理:Deployment控制器会创建一个或多个ReplicaSet对象来管理Pod的副本,确保指定数量的Pod副本始终运行。

  • 声明式更新:用户可以声明他们希望Pod如何更新,Deployment会自动将当前状态变更为用户所期望的状态。

  • 滚动更新:Deployment支持滚动更新(Rolling Update),这意味着在更新过程中,旧版本的Pod会逐个被新版本的Pod替换,直到所有Pod都更新到新版本。

  • 版本控制:Deployment记录了Pod模板的历史版本,允许用户回滚到之前的版本,如果新版本存在问题。

  • 暂停和恢复:用户可以暂停Deployment的更新,进行维护或修改,之后可以恢复更新。

  • 扩展和缩减:用户可以根据需要对Deployment控制的Pod数量进行扩展或缩减。

  • 健康检查:Deployment可以使用liveness和readiness探针来确定Pod的健康状态,并在必要时进行适当的处理。

  • 策略配置:用户可以为Deployment配置更新策略,包括更新的速度和模式。

  • 历史记录:Deployment控制器会保留Pod模板的变更历史,通常保留最近的几次更新,以便于回滚操作。

  • 状态检查:提供了观察Deployment状态的能力,包括它的更新进度和条件。

创建Deployment

# vim pc-deployment.yaml
[root@k8s-master ~]# cat  pc-deployment.yaml
---
apiVersion: apps/v1 # 版本号
kind: Deployment # 类型
metadata: # 元数据name: pc-deployment # rs名称namespace: test # 所属命名空间labels: # 标签controller: deploy
spec: # 详情描述replicas: 3 # 副本数量revisionHistoryLimit: 3 # 保留历史版本paused: false # 暂停部署,默认是falseprogressDeadlineSeconds: 600 # 部署超时时间(s),默认是600strategy: # 策略type: RollingUpdate # 滚动更新策略rollingUpdate: # 滚动更新maxSurge: 30% # 最大额外可以存在的副本数,可以为百分比,也可以为整数maxUnavailable: 30% # 最大不可用状态的 Pod 的最大值,可以为百分比,也可以为整数selector: # 选择器,通过它指定该控制器管理哪些podmatchLabels: # Labels匹配规则app: nginx-podmatchExpressions: # Expressions匹配规则- key: appoperator: Invalues: [nginx-pod]template: # 模板,当副本数量不足时,会根据下面的模板创建pod副本metadata:labels:app: nginx-podspec:containers:- name: nginximage: nginx:1.17.1ports:- containerPort: 80
[root@k8s-master ~]# kubectl apply -f pc-deployment.yaml 
deployment.apps/pc-deployment created
 查看deploy控制器
[root@k8s-master ~]# kubectl get deploy -n test
NAME            READY   UP-TO-DATE   AVAILABLE   AGE
pc-deployment   0/3     3            0           8s
[root@k8s-master ~]# kubectl get deploy -n test -w
NAME            READY   UP-TO-DATE   AVAILABLE   AGE
pc-deployment   0/3     3            0           11s
pc-deployment   1/3     3            1           34s
pc-deployment   2/3     3            2           34s
pc-deployment   3/3     3            3           34s
查看rs控制器
[root@k8s-master ~]# kubectl get rs -n test
NAME                       DESIRED   CURRENT   READY   AGE
pc-deployment-5ffc5bf56c   3         3         3       88s
查看pod
[root@k8s-master ~]# kubectl get pods -n test
NAME                             READY   STATUS    RESTARTS   AGE
pc-deployment-5ffc5bf56c-hj285   1/1     Running   0          80s
pc-deployment-5ffc5bf56c-l5ccs   1/1     Running   0          80s
pc-deployment-5ffc5bf56c-pmg8t   1/1     Running   0          80s

Deployment扩缩容

  • 命令方式

[root@k8s-master ~]# kubectl scale deploy pc-deployment --replicas=5 -n test
deployment.apps/pc-deployment scaled
[root@k8s-master ~]# kubectl get pods -n test
NAME                             READY   STATUS    RESTARTS   AGE
pc-deployment-5ffc5bf56c-hj285   1/1     Running   0          8m7s
pc-deployment-5ffc5bf56c-l5ccs   1/1     Running   0          8m7s
pc-deployment-5ffc5bf56c-pmg8t   1/1     Running   0          8m7s
pc-deployment-5ffc5bf56c-tmmhz   1/1     Running   0          5s
pc-deployment-5ffc5bf56c-tqt7j   1/1     Running   0          5s
  • 编辑副本

#将副本数改为3
[root@k8s-master ~]# kubectl edit deployment.apps pc-deployment -n test
deployment.apps/pc-deployment edited[root@k8s-master ~]# kubectl get pods -n test  -w
NAME                             READY   STATUS    RESTARTS   AGE
pc-deployment-5ffc5bf56c-hj285   1/1     Running   0          10m
pc-deployment-5ffc5bf56c-pmg8t   1/1     Running   0          10m
pc-deployment-5ffc5bf56c-tmmhz   1/1     Running   0          2m13s

Deployment镜像更新

Deployment控制器确实支持两种主要的更新策略:重建更新(Recreate)和滚动更新(RollingUpdate)。这两种策略定义了如何替换Deployment中的Pods以进行更新。可以通过strategy字段指定更新策略类型,并设置相关的属性。以下是两种策略的简要说明:

  • 重建更新(Recreate)

    • 在这种策略下,Deployment控制器会先终止所有正在运行的Pods,然后再创建新的Pods。

    • 这种方法会导致短暂的停机时间,因为旧的Pods全部停止后才进行新的Pods的创建。

    • 这种策略适用于小型应用或对停机时间不敏感的场景。

    • 属性设置示例:

    spec:strategy:   # 策略type: Recreate  # 重建更新
  • 滚动更新(RollingUpdate)

    • 这是默认的更新策略,它允许你指定两个属性:maxUnavailablemaxSurge

    • maxUnavailable定义了在更新过程中可以处于不可用状态的最大Pod数量。这可以设置为绝对数量或是Pod总数的百分比。

    • maxSurge定义了可以超出期望数量创建的新Pod的最大数量。这同样可以设置为绝对数量或是Pod总数的百分比。

    • 滚动更新策略可以确保在更新过程中始终有一定数量的Pod在线,从而减少或避免停机时间。

    • 属性设置示例:

    strategy:type: RollingUpdaterollingUpdate:maxUnavailable: 1   #在更新过程中,可以有一个Pod处于不可用状态maxSurge: 1     #可以有一个额外的Pod在更新完成前被创建
 重建更新(Recreate)
[root@k8s-master ~]# vim pc-deployment.yaml 
[root@k8s-master ~]# kubectl delete -f pc-deployment.yaml 
deployment.apps "pc-deployment" deleted
[root@k8s-master ~]# kubectl apply -f pc-deployment.yaml 
deployment.apps/pc-deployment created
[root@k8s-master ~]# kubectl get pods -n test  -w
NAME                             READY   STATUS    RESTARTS   AGE
pc-deployment-5ffc5bf56c-cgk2b   1/1     Running   0          5s
pc-deployment-5ffc5bf56c-gvqgr   1/1     Running   0          5s
pc-deployment-5ffc5bf56c-hp7mc   1/1     Running   0          4s
^C[root@k8s-master ~]# kubectl set image deploy pc-deployment nginx=nginx:1.17.4 -n ttdeployment.apps/pc-deployment image updated
[root@k8s-master ~]# kubectl get pods -n test  -w
NAME                             READY   STATUS              RESTARTS   AGE
pc-deployment-5ffc5bf56c-cgk2b   1/1     Running             0          60s
pc-deployment-5ffc5bf56c-gvqgr   1/1     Running             0          60s
pc-deployment-5ffc5bf56c-hp7mc   1/1     Running             0          59s
pc-deployment-d79885fd8-pfxzf    0/1     ContainerCreating   0          2s
pc-deployment-d79885fd8-pfxzf    0/1     ContainerCreating   0          2s
pc-deployment-d79885fd8-pfxzf    1/1     Running             0          37s
pc-deployment-5ffc5bf56c-hp7mc   1/1     Terminating         0          94s
pc-deployment-d79885fd8-2n875    0/1     Pending             0          0s
pc-deployment-d79885fd8-2n875    0/1     Pending             0          0s
pc-deployment-d79885fd8-2n875    0/1     ContainerCreating   0          0s
pc-deployment-5ffc5bf56c-hp7mc   1/1     Terminating         0          95s
pc-deployment-5ffc5bf56c-hp7mc   0/1     Terminating         0          95s
pc-deployment-d79885fd8-2n875    0/1     ContainerCreating   0          2s
pc-deployment-5ffc5bf56c-hp7mc   0/1     Terminating         0          101s
pc-deployment-5ffc5bf56c-hp7mc   0/1     Terminating         0          101s
pc-deployment-d79885fd8-2n875    1/1     Running             0          30s
pc-deployment-5ffc5bf56c-cgk2b   1/1     Terminating         0          2m5s
pc-deployment-d79885fd8-lsjff    0/1     Pending             0          0s
pc-deployment-d79885fd8-lsjff    0/1     Pending             0          0s
pc-deployment-d79885fd8-lsjff    0/1     ContainerCreating   0          0s
pc-deployment-5ffc5bf56c-cgk2b   1/1     Terminating         0          2m6s
pc-deployment-5ffc5bf56c-cgk2b   0/1     Terminating         0          2m6s
pc-deployment-d79885fd8-lsjff    0/1     ContainerCreating   0          2s
pc-deployment-d79885fd8-lsjff    1/1     Running             0          2s
pc-deployment-5ffc5bf56c-gvqgr   1/1     Terminating         0          2m7s
pc-deployment-5ffc5bf56c-gvqgr   1/1     Terminating         0          2m8s
pc-deployment-5ffc5bf56c-gvqgr   0/1     Terminating         0          2m10s
pc-deployment-5ffc5bf56c-gvqgr   0/1     Terminating         0          2m11s
pc-deployment-5ffc5bf56c-gvqgr   0/1     Terminating         0          2m11s
pc-deployment-5ffc5bf56c-cgk2b   0/1     Terminating         0          2m19s
pc-deployment-5ffc5bf56c-cgk2b   0/1     Terminating         0          2m19s
^C[root@k8s-master ~]# kubectl get pods -n test 
NAME                            READY   STATUS    RESTARTS   AGE
pc-deployment-d79885fd8-2n875   1/1     Running   0          92s
pc-deployment-d79885fd8-lsjff   1/1     Running   0          62s
pc-deployment-d79885fd8-pfxzf   1/1     Running   0          2m9s
[root@k8s-master ~]# kubectl get deployment.apps pc-deployment -n test -o wide
NAME            READY   UP-TO-DATE   AVAILABLE   AGE     CONTAINERS   IMAGES         SELECTOR
pc-deployment   3/3     3            3           3m38s   nginx        nginx:1.17.4   app=nginx-pod,app in (nginx-pod)
滚动更新(RollingUpdate)

先启动一个新pod,然后停一个旧pod,再起一个新pod......

[root@k8s-master ~]# vim pc-deployment.yaml 
[root@k8s-master ~]# kubectl apply -f pc-deployment.yaml 
deployment.apps/pc-deployment created
[root@k8s-master ~]# kubectl get pods -n test -w
NAME                             READY   STATUS    RESTARTS   AGE
pc-deployment-5ffc5bf56c-6d9nk   1/1     Running   0          5s
pc-deployment-5ffc5bf56c-m2mgv   1/1     Running   0          5s
pc-deployment-5ffc5bf56c-tfzx2   1/1     Running   0          5s
^C[root@k8s-master ~]kubectl set image deploy pc-deployment nginx=nginx:1.17.2 -n test 
deployment.apps/pc-deployment image updated
[root@k8s-master ~]# kubectl get pods -n test -w
NAME                             READY   STATUS              RESTARTS   AGE
pc-deployment-574bcdf54b-9m25z   0/1     ContainerCreating   0          2s
pc-deployment-5ffc5bf56c-6d9nk   1/1     Running             0          19s
pc-deployment-5ffc5bf56c-m2mgv   1/1     Running             0          19s
pc-deployment-5ffc5bf56c-tfzx2   1/1     Running             0          19s
pc-deployment-574bcdf54b-9m25z   0/1     ContainerCreating   0          2s
pc-deployment-574bcdf54b-9m25z   1/1     Running             0          36s
pc-deployment-5ffc5bf56c-tfzx2   1/1     Terminating         0          53s
pc-deployment-574bcdf54b-wlcpz   0/1     Pending             0          0s
pc-deployment-574bcdf54b-wlcpz   0/1     Pending             0          0s
pc-deployment-574bcdf54b-wlcpz   0/1     ContainerCreating   0          0s
pc-deployment-5ffc5bf56c-tfzx2   1/1     Terminating         0          53s
pc-deployment-574bcdf54b-wlcpz   0/1     ContainerCreating   0          2s
pc-deployment-5ffc5bf56c-tfzx2   0/1     Terminating         0          55s
pc-deployment-5ffc5bf56c-tfzx2   0/1     Terminating         0          57s
pc-deployment-5ffc5bf56c-tfzx2   0/1     Terminating         0          58s
pc-deployment-574bcdf54b-wlcpz   1/1     Running             0          26s
pc-deployment-5ffc5bf56c-m2mgv   1/1     Terminating         0          79s
pc-deployment-574bcdf54b-b9lbf   0/1     Pending             0          0s
pc-deployment-574bcdf54b-b9lbf   0/1     Pending             0          0s
pc-deployment-574bcdf54b-b9lbf   0/1     ContainerCreating   0          0s
pc-deployment-5ffc5bf56c-m2mgv   1/1     Terminating         0          79s
pc-deployment-5ffc5bf56c-m2mgv   0/1     Terminating         0          80s
pc-deployment-574bcdf54b-b9lbf   0/1     ContainerCreating   0          1s
pc-deployment-574bcdf54b-b9lbf   1/1     Running             0          2s
pc-deployment-5ffc5bf56c-6d9nk   1/1     Terminating         0          81s
pc-deployment-5ffc5bf56c-6d9nk   1/1     Terminating         0          81s
pc-deployment-5ffc5bf56c-6d9nk   0/1     Terminating         0          83s
pc-deployment-5ffc5bf56c-m2mgv   0/1     Terminating         0          87s
pc-deployment-5ffc5bf56c-m2mgv   0/1     Terminating         0          87s
pc-deployment-5ffc5bf56c-6d9nk   0/1     Terminating         0          94s
pc-deployment-5ffc5bf56c-6d9nk   0/1     Terminating         0          94s
^C[root@k8s-master ~]# kubectl get pods -n test 
NAME                             READY   STATUS    RESTARTS   AGE
pc-deployment-574bcdf54b-9m25z   1/1     Running   0          2m4s
pc-deployment-574bcdf54b-b9lbf   1/1     Running   0          62s
pc-deployment-574bcdf54b-wlcpz   1/1     Running   0          88s
[root@k8s-master ~]# kubectl get pods -n test  -o wide
NAME                             READY   STATUS    RESTARTS   AGE     IP               NODE        NOMINATED NODE   READINESS GATES
pc-deployment-574bcdf54b-9m25z   1/1     Running   0          2m19s   10.244.36.80     k8s-node1   <none>           <none>
pc-deployment-574bcdf54b-b9lbf   1/1     Running   0          77s     10.244.36.81     k8s-node1   <none>           <none>
pc-deployment-574bcdf54b-wlcpz   1/1     Running   0          103s    10.244.169.134   k8s-node2   <none>           <none>
版本回退
  • deployment支持版本升级过程中的暂停、继续功能以及版本回退等诸多功能

  • kubectl rollout: 版本升级相关功能,支持下面的选项:

    • status 显示当前升级状态

    • history 显示 升级历史记录

    • pause 暂停版本升级过程

    • resume 继续已经暂停的版本升级过程

    • restart 重启版本升级过程

    • undo 回滚到上一级版本(可以使用--to-revision回滚到指定版本)

  • 查看当前升级版本的状态

[root@k8s-master ~]# kubectl rollout status deployment pc-deployment -n test
deployment "pc-deployment" successfully rolled out
[root@k8s-master ~]# kubectl set image deploy pc-deployment nginx=nginx:1.17.5 -n testdeployment.apps/pc-deployment image updated
[root@k8s-master ~]# kubectl set image deploy pc-deployment nginx=nginx:1.17.6 -n test 
deployment.apps/pc-deployment image updated[root@k8s-master ~]# kubectl get pod -n test -o wide
NAME                             READY   STATUS              RESTARTS   AGE     IP               NODE        NOMINATED NODE   READINESS GATES
pc-deployment-574bcdf54b-9m25z   1/1     Running             0          10m     10.244.36.80     k8s-node1   <none>           <none>
pc-deployment-574bcdf54b-b9lbf   1/1     Running             0          9m44s   10.244.36.81     k8s-node1   <none>           <none>
pc-deployment-574bcdf54b-wlcpz   1/1     Running             0          10m     10.244.169.134   k8s-node2   <none>           <none>
pc-deployment-768755cc6b-dbzh2   0/1     ContainerCreating   0          18s     <none>           k8s-node2   <none>           <none>^C[root@k8s-master ~]# kubectl get pods -n test  -o wide  
NAME                             READY   STATUS    RESTARTS   AGE   IP               NO
pc-deployment-768755cc6b-9xrmz   1/1     Running   0          36s   10.244.36.83     k8
pc-deployment-768755cc6b-ctlw9   1/1     Running   0          10s   10.244.36.84     k8
pc-deployment-768755cc6b-dbzh2   1/1     Running   0          63s   10.244.169.135   k8
[root@k8s-master ~]# 
[root@k8s-master ~]# kubectl get deployment.apps pc-deployment -n test -o wideNAME            READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS   IMAGES         SELE
pc-deployment   3/3     3            3           12m   nginx        nginx:1.17.6   app=
[root@k8s-master ~]# 
[root@k8s-master ~]# kubectl rollout status deployment pc-deployment -n test
deployment "pc-deployment" successfully rolled out#查看历史版本升级
[root@k8s-master ~]# kubectl rollout history deploy pc-deployment -n test
deployment.apps/pc-deployment 
REVISION  CHANGE-CAUSE
1         <none>
2         <none>
3         <none>
4         <none>
  • 版本回退

[root@k8s-master ~]# kubectl rollout undo deployment pc-deployment --to-revision=1 -n test
deployment.apps/pc-deployment rolled back
[root@k8s-master ~]# kubectl get deployment.apps pc-deployment -n test -o wide
NAME            READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS   IMAGES         SELECTOR
pc-deployment   3/3     3            3           15m   nginx        nginx:1.17.1   app=nginx-pod,app in (nginx-pod)
[root@k8s-master ~]# kubectl rollout history deploy pc-deployment -n test
deployment.apps/pc-deployment 
REVISION  CHANGE-CAUSE
2         <none>
3         <none>
4         <none>
5         <none>[root@k8s-master ~]# kubectl get rs -n test
NAME                       DESIRED   CURRENT   READY   AGE
pc-deployment-574bcdf54b   0         0         0       15m
pc-deployment-5ffc5bf56c   3         3         3       15m
pc-deployment-768755cc6b   0         0         0       4m49s
pc-deployment-84756ff8f5   0         0         0       4m59s
# 其实deployment之所以可是实现版本的回滚,就是通过记录下历史rs来实现的,
# 一旦想回滚到哪个版本,只需要将当前版本pod数量降为0,然后将回滚版本的pod提升为目标数量就可以了

 

金丝雀发布
  • 金丝雀发布(Canary Release)是一种渐进式的部署策略,用于逐步将新版本的应用程序或服务部署到生产环境中。这种方法允许开发者在全面推广之前,先在一小部分用户或服务器上测试新版本,以确保新版本在实际使用中的表现符合预期。

  • 金丝雀发布的关键步骤包括:

    • 准备新版本:开发并测试新版本的应用程序。

    • 部署新版本:将新版本的应用程序部署到生产环境,但只对一小部分用户或服务器可见。

    • 监控和测试:密切监控新版本的性能和用户反馈,确保它按预期工作。

    • 逐步扩展:如果新版本表现良好,逐步增加访问新版本的用户比例,直到完全替换旧版本。

    • 回滚:如果在测试过程中发现问题,可以立即回滚到旧版本,以避免影响所有用户。

  • 在Kubernetes环境中,金丝雀发布可以通过Deployment控制器来实现。Deployment控制器允许你定义应用的期望状态,包括应用的版本和运行的副本数量。通过使用Deployment,你可以控制更新过程,包括暂停和恢复更新,以及设置滚动更新的策略。

  • 例如,你可以创建一个新的Deployment来部署新版本的Pod,然后使用Kubernetes的服务(如Service或Ingress)将一部分流量路由到新版本的Pod上。如果一切顺利,你可以继续更新,逐步增加新版本Pod的数量,直到完全替换旧版本。如果出现问题,可以暂停更新,甚至回滚到旧版本。

  • 金丝雀发布是一种有效的风险管理策略,可以帮助减少新版本部署可能导致的负面影响。


[root@k8s-master ~]# kubectl set image deploy pc-deployment nginx=nginx:1.17.4 -n test && kubectl rollout pause deployment pc-deployment -n test 
deployment.apps/pc-deployment paused
[root@k8s-master ~]# kubectl set image deploy pc-deployment nginx=nginx:1.17.5 -n test && kubectl rollout pause deployment pc-deployment -n test 
deployment.apps/pc-deployment image updated
error: deployments.apps "pc-deployment" is already paused
[root@k8s-master ~]# kubectl get rs -n test -o wide
NAME                       DESIRED   CURRENT   READY   AGE     CONTAINERS   IMAGES         SELECTOR
pc-deployment-5ffc5bf56c   0         0         0       20m     nginx        nginx:1.17.1   app=nginx-pod,app in (nginx-pod),pod-template-hash=5ffc5bf56c
pc-deployment-768755cc6b   0         0         0       9m39s   nginx        nginx:1.17.6   app=nginx-pod,app in (nginx-pod),pod-template-hash=768755cc6b
pc-deployment-84756ff8f5   0         0         0       9m49s   nginx        nginx:1.17.5   app=nginx-pod,app in (nginx-pod),pod-template-hash=84756ff8f5
pc-deployment-d79885fd8    3         3         3       68s     nginx        nginx:1.17.4   app=nginx-pod,app in (nginx-pod),pod-template-hash=d79885fd8
[root@k8s-master ~]# kubectl get rs -n test -o wide
NAME                       DESIRED   CURRENT   READY   AGE     CONTAINERS   IMAGES         SELECTOR
pc-deployment-5ffc5bf56c   0         0         0       20m     nginx        nginx:1.17.1   app=nginx-pod,app in (nginx-pod),pod-template-hash=5ffc5bf56c
pc-deployment-768755cc6b   0         0         0       9m42s   nginx        nginx:1.17.6   app=nginx-pod,app in (nginx-pod),pod-template-hash=768755cc6b
pc-deployment-84756ff8f5   0         0         0       9m52s   nginx        nginx:1.17.5   app=nginx-pod,app in (nginx-pod),pod-template-hash=84756ff8f5
pc-deployment-d79885fd8    3         3         3       71s     nginx        nginx:1.17.4   app=nginx-pod,app in (nginx-pod),pod-template-hash=d79885fd8
[root@k8s-master ~]# kubectl get rs -n test -o wide
NAME                       DESIRED   CURRENT   READY   AGE    CONTAINERS   IMAGES         SELECTOR
pc-deployment-5ffc5bf56c   0         0         0       20m    nginx        nginx:1.17.1   app=nginx-pod,app in (nginx-pod),pod-template-hash=5ffc5bf56c
pc-deployment-768755cc6b   0         0         0       10m    nginx        nginx:1.17.6   app=nginx-pod,app in (nginx-pod),pod-template-hash=768755cc6b
pc-deployment-84756ff8f5   0         0         0       10m    nginx        nginx:1.17.5   app=nginx-pod,app in (nginx-pod),pod-template-hash=84756ff8f5
pc-deployment-d79885fd8    3         3         3       100s   nginx        nginx:1.17.4   app=nginx-pod,app in (nginx-pod),pod-template-hash=d79885fd8
[root@k8s-master ~]# kubectl get pod -n test -o wide
NAME                            READY   STATUS    RESTARTS   AGE     IP               NODE        NOMINATED NODE   READINESS GATES
pc-deployment-d79885fd8-2dps9   1/1     Running   0          2m6s    10.244.36.88     k8s-node1   <none>           <none>
pc-deployment-d79885fd8-6zddq   1/1     Running   0          2m8s    10.244.169.137   k8s-node2   <none>           <none>
pc-deployment-d79885fd8-ccz9b   1/1     Running   0          2m12s   10.244.36.87     k8s-node1   <none>           <none>#当前pod暂停更新,UP-TO-DATE为0,已更新到最新版本的副本数为0
[root@k8s-master ~]# kubectl get deployment.apps pc-deployment -n test -o wide
NAME            READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS   IMAGES         SELECTOR
pc-deployment   3/3     0            3           21m   nginx        nginx:1.17.5   app=nginx-pod,app in (nginx-pod)#继续更新操作
[root@k8s-master ~]# kubectl rollout resume deploy pc-deployment -n test
deployment.apps/pc-deployment resumed
[root@k8s-master ~]# kubectl get pod -n test -o wide
NAME                             READY   STATUS              RESTARTS   AGE     IP               NODE        NOMINATED NODE   READINESS GATES
pc-deployment-84756ff8f5-b5gzk   0/1     ContainerCreating   0          0s      <none>           k8s-node1   <none>           <none>
pc-deployment-84756ff8f5-gp97h   1/1     Running             0          17s     10.244.169.138   k8s-node2   <none>           <none>
pc-deployment-84756ff8f5-zw85b   1/1     Running             0          19s     10.244.36.89     k8s-node1   <none>           <none>
pc-deployment-d79885fd8-6zddq    1/1     Terminating         0          3m14s   10.244.169.137   k8s-node2   <none>           <none>
pc-deployment-d79885fd8-ccz9b    1/1     Running             0          3m18s   10.244.36.87     k8s-node1   <none>           <none>#已更新最新版本的副本为3
[root@k8s-master ~]# kubectl get deployment.apps pc-deployment -n test -o wide
NAME            READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS   IMAGES         SELECTOR
pc-deployment   3/3     3            3           22m   nginx        nginx:1.17.5   app=nginx-pod,app in (nginx-pod)


http://www.ppmy.cn/news/1564511.html

相关文章

JS宏进阶: 工厂函数与构造函数

一、构造函数 在JavaScript中&#xff0c;构造函数是一种用于创建和初始化对象的特殊函数。构造函数的名字通常以大写字母开头&#xff0c;以区分于普通函数。通过new关键字调用构造函数&#xff0c;可以创建一个新的实例对象&#xff0c;并自动执行构造函数内部的代码来初始化…

【硬件介绍】Type-C接口详解

一、Type-C接口概述 Type-C接口特点&#xff1a;以其独特的扁头设计和无需区分正反两面的便捷性而广受欢迎。这种设计大大提高了用户的使用体验&#xff0c;避免了传统USB接口需要多次尝试才能正确插入的问题。Type-C接口内部结构&#xff1a;内部上下两排引脚的设计虽然可能不…

深入理解 SQL 中的 DATEDIFF 函数

深入理解 SQL 中的 DATEDIFF 函数 DATEDIFF 函数在 SQL 中是一个用于计算两个日期之间差值的重要工具。不同数据库实现了不同版本的 DATEDIFF&#xff0c;它们在功能和语法上有所不同。本文将详细解析 DATEDIFF 的用法、数据库间差异、复杂场景中的应用&#xff0c;以及替代方…

从零到一:Spring Boot 与 RocketMQ 的完美集成指南

1.Rocket的概念与原理 RocketMQ 是一款由阿里巴巴开源的分布式消息中间件&#xff0c;最初用于支持阿里巴巴的海量业务。它基于发布-订阅模型&#xff0c;具备高吞吐、低延迟、高可用和强一致性的特点&#xff0c;适用于消息队列、大规模数据流处理等场景。以下是对 RocketMQ …

Ubuntu创建AndroidStudio快捷启动图标

一、下载linux环境的Anroid studio软件包 下载连接地址&#xff1a; 下载 Android Studio 和应用工具 - Android 开发者 | Android Developers 下载的文件为压缩包。进行解压后进入到bin目录下面&#xff0c;显示下面的文件列表 二、创建快捷启动图标 2.1 打开studio 如…

用 Python 自动化处理日常任务

&#x1f496; 欢迎来到我的博客&#xff01; 非常高兴能在这里与您相遇。在这里&#xff0c;您不仅能获得有趣的技术分享&#xff0c;还能感受到轻松愉快的氛围。无论您是编程新手&#xff0c;还是资深开发者&#xff0c;都能在这里找到属于您的知识宝藏&#xff0c;学习和成长…

脚本工具:PYTHON

Python 是一种高级编程语言&#xff0c;以其简洁清晰的语法和强大的功能被广泛应用于各种领域&#xff0c;包括自动化脚本编写、数据分析、机器学习、Web开发等。以下是一些关于使用 Python 编写脚本工具的基本介绍、常用库以及一些实用技巧总结。 这里写目录标题 基础知识安装…