本文介绍了使用单个副本时,Kubernetes部署不会执行滚动更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我修改了部署配置(production.yaml),更改了容器映像值.

I modified the deployment config (production.yaml), changing the container image value.

然后我运行:kubectl replace -f production.yaml.

发生这种情况时,我的服务似乎没有响应,此外:

While this occurred, my service did not appear to be responding, in addition:

kubectl get pods:

wordpress-2105335096-dkrvg 3/3 Running 0 47s

过一会儿...:

wordpress-2992233824-l4287 3/3 Running 0 14s

过一会儿...:

wordpress-2992233824-l4287 0/3 ContainerCreating 0 7s

似乎在新Pod为Running之前已经终止了先前的Pod ...为什么?

It seems it has terminated the previous pod before the new pod is Running... Why?

produciton.yaml:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: wordpress
  labels:
    app: wordpress
spec:
  replicas: 1
  selector:
    matchLabels:
      app: wordpress
  template:
    metadata:
      labels:
        app: wordpress
    spec:
      terminationGracePeriodSeconds: 30
      containers:
        - image: eu.gcr.io/abcxyz/wordpress:deploy-1502463532
          name: wordpress
          imagePullPolicy: "Always"
          env:
            - name: WORDPRESS_HOST
              value: localhost
            - name: WORDPRESS_DB_USERNAME
              valueFrom:
                secretKeyRef:
                  name: cloudsql-db-credentials
                  key: username
          volumeMounts:
            - name: wordpress-persistent-storage
              mountPath: /var/www/html
        - image: eu.gcr.io/abcxyz/nginx:deploy-1502463532
          name: nginx
          imagePullPolicy: "Always"
          ports:
            - containerPort: 80
              name: nginx
          volumeMounts:
            - name: wordpress-persistent-storage
              mountPath: /var/www/html
        - image: gcr.io/cloudsql-docker/gce-proxy:1.09
          name: cloudsql-proxy
          command: ["/cloud_sql_proxy", "--dir=/cloudsql",
                    "-instances=abcxyz:europe-west1:wordpressdb2=tcp:3306",
                    "-credential_file=/secrets/cloudsql/credentials.json"]
          volumeMounts:
            - name: cloudsql-instance-credentials
              mountPath: /secrets/cloudsql
              readOnly: true
            - name: ssl-certs
              mountPath: /etc/ssl/certs
            - name: cloudsql
              mountPath: /cloudsql
      volumes:
        - name: wordpress-persistent-storage
          gcePersistentDisk:
            pdName: wordpress-disk
            fsType: ext4

        - name: cloudsql-instance-credentials
          secret:
            secretName: cloudsql-instance-credentials
        - name: ssl-certs
          hostPath:
            path: /etc/ssl/certs
        - name: cloudsql
          emptyDir:

推荐答案

根据Kubernetes文档,我相信这种行为是正确的.假设您为部署指定n副本,那么Kubernetes将在更新部署时采取以下步骤:

I believe this behaviour is correct according to the Kubernetes documentation. Assuming you specify n replicas for a deployment, the following steps will be taken by Kubernetes when updating a deployment:

  1. 终结旧的Pod,同时确保至少n - 1个总Pod可用
  2. 创建新的广告连播,直到最多最多n + 1个广告连播
  3. 一旦安装了新的豆荚,请回到步骤1,直到n新的豆荚起来
  1. Terminate old pods, while ensuring that at least n - 1 total pods are up
  2. Create new pods until a maximum of n + 1 total pods are up
  3. As soon as new pods are up, go back to step 1 until n new pods are up

对于您的情况n = 1,这意味着在第一步中,所有旧的Pod将被终止.

In your case n = 1, which means that in the first step, all old pods will be terminated.

有关更多信息,请参见更新部署信息:

See Updating a Deployment for more information:

这篇关于使用单个副本时,Kubernetes部署不会执行滚动更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 21:05