Kubernetes 部署在使用单个副本时不执行滚动更新
Kubernetes deployment does not perform a rolling update when using a single replica
我修改了部署配置 (production.yaml),更改了容器映像值。
然后我运行这个:kubectl replace -f production.yaml
.
发生这种情况时,我的服务似乎没有响应,此外:
kubectl get pods
:
wordpress-2105335096-dkrvg 3/3 Running 0 47s
稍后...:[=17=]
wordpress-2992233824-l4287 3/3 Running 0 14s
稍后...:[=17=]
wordpress-2992233824-l4287 0/3 ContainerCreating 0 7s
它似乎在新 pod 出现之前终止了前一个 pod Running
... 为什么?
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 在更新部署时将执行以下步骤:
- 终止旧 pods,同时确保至少
n - 1
总数 pods 启动
- 创建新的 pods 直到最多
n + 1
总数 pods 可用
- 一旦新 pods 上线,返回第 1 步,直到
n
个新 pods 上线
在你的情况下 n = 1
,这意味着在第一步中,所有旧的 pods 将被终止。
有关详细信息,请参阅 Updating a Deployment:
Deployment can ensure that only a certain number of Pods may be down while they are being updated. By default, it ensures that at least 1 less than the desired number of Pods are up (1 max unavailable).
Deployment can also ensure that only a certain number of Pods may be created above the desired number of Pods. By default, it ensures that at most 1 more than the desired number of Pods are up (1 max surge).
In a future version of Kubernetes, the defaults will change from 1-1 to 25%-25%.
我修改了部署配置 (production.yaml),更改了容器映像值。
然后我运行这个:kubectl replace -f production.yaml
.
发生这种情况时,我的服务似乎没有响应,此外:
kubectl get pods
:
wordpress-2105335096-dkrvg 3/3 Running 0 47s
稍后...:[=17=]
wordpress-2992233824-l4287 3/3 Running 0 14s
稍后...:[=17=]
wordpress-2992233824-l4287 0/3 ContainerCreating 0 7s
它似乎在新 pod 出现之前终止了前一个 pod Running
... 为什么?
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 在更新部署时将执行以下步骤:
- 终止旧 pods,同时确保至少
n - 1
总数 pods 启动 - 创建新的 pods 直到最多
n + 1
总数 pods 可用 - 一旦新 pods 上线,返回第 1 步,直到
n
个新 pods 上线
在你的情况下 n = 1
,这意味着在第一步中,所有旧的 pods 将被终止。
有关详细信息,请参阅 Updating a Deployment:
Deployment can ensure that only a certain number of Pods may be down while they are being updated. By default, it ensures that at least 1 less than the desired number of Pods are up (1 max unavailable). Deployment can also ensure that only a certain number of Pods may be created above the desired number of Pods. By default, it ensures that at most 1 more than the desired number of Pods are up (1 max surge). In a future version of Kubernetes, the defaults will change from 1-1 to 25%-25%.