5.3 执行滚动升级

  对前面的章节中部署的应用进行滚动升级。

第一件事就是更新Deployment清单文件中的镜像的tag。起初版本的应用使用的是tag为nigelpoulton/k8sbook:latest的镜像。现在要将Deployment清单文件中spec.template.spec.containers的内容改为新的nigelpoulton/k8sbook:edge镜像。

  以下就是更新之后的deploy.ynl清单文件,唯一有改动的地方就是spec.template.spec.containers.image一行。

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-deploy
spec:
  replicas: 10
  selector:
    matchLabels:
      app: hello-world
  minReadySeconds: 10
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1
      maxSurge: 1
  template:
    metadata:
      labels:
        app: hello-world
    spec:
      containers:
      - name: hello-pod
        image: nigelpoulton/k8sbook:edge
        ports:
        - containerPort: 8080
  • spec.minReadySeconds:这里值被设为10,也就是告诉Kubernetes每个Pod的更新动作之间间隔10s。
  • spec.strategy.type:这里使用RollingUpdat策略来进行更新。
  • maxUnavailable:不允许出现比期望状态的Pod数量少超过一个的情况
  • maxSurge:不允许出现比期望状态的Pod数量多超过一个的情况
[root@master k8s]# kubectl apply -f deploy.yml --record
deployment.apps/hello-deploy configured

  ※ 在本例中,期望状态是Pod数量为10个副本,那么maxSure:1的意思是在更新过程中,Pod数量不能超过11个,而maxUnavailable:1的意思是不能少于9个。导致的结果就是,在滚动更新的过程中,最多只能同时更新两个Pod(11减9)。

修改好后执行kubectl apply -f deploy.yml --record命令

  ※  kubectl apply -f deploy.yml --record 

            命令允许你应用或更新 Kubernetes 资源,--record表示该操作会被记录在资源的注解中

  查看更新过程

kubectl rollout status deployment hello-deploy

[root@master k8s]# kubectl rollout status deployment hello-deploy
Waiting for deployment "hello-deploy" rollout to finish: 2 out of 10 new replicas have been updated...
Waiting for deployment "hello-deploy" rollout to finish: 2 out of 10 new replicas have been updated...
Waiting for deployment "hello-deploy" rollout to finish: 2 out of 10 new replicas have been updated...
Waiting for deployment "hello-deploy" rollout to finish: 2 out of 10 new replicas have been updated...^C

 

posted @ 2024-06-30 10:35  ~技术小白  阅读(30)  评论(0)    收藏  举报