假设我有一个这样的部署模板
spec:
minReadySeconds: 15
readinessProbe:
failureThreshold: 3
httpGet:
path: /
port: 80
scheme: HTTP
initialDelaySeconds: 20
periodSeconds: 20
successThreshold: 1
timeoutSeconds: 5
这将如何影响我的应用程序的新版本?
minReadySeconds
和 initialDelaySeconds
会同时计数吗? initialDelaySeconds
会先出现然后minReadySeconds
吗?
来自 Kubernetes 部署文档:
是一个可选字段,指定新创建的 Pod 在其任何容器不崩溃的情况下应准备就绪的最小秒数,以便将其视为可用。默认为 0(Pod 一旦准备好就被视为可用)。要了解有关 Pod 何时被视为就绪的更多信息,请参阅容器探针.spec.minReadySeconds
因此,您新创建的应用程序 Pod 必须准备好
.spec.minReadySeconds
秒才能被视为可用。
:容器启动后启动活动或就绪探测之前的秒数。initialDelaySeconds
所以
initialDelaySeconds
出现在 minReadySeconds
之前。
比方说,pod 中的容器已在
t
秒启动。就绪探测将在 t+initialDelaySeconds
秒启动。假设 Pod 在 t1
秒 (t1 > t+initialDelaySeconds
) 时准备就绪。所以这个 Pod 将在 t1+minReadySeconds
秒后可用。
TLDR:没有效果。
doc应该如下所示(粗体是我的编辑)
.spec.minReadySeconds 是一个可选字段,指定新创建的 Pod 在没有任何容器崩溃的情况下应准备就绪的最小秒数,以便将其视为可用对于部署控制器,容器探测机制与这个领域。换句话说,
看起来在这里。默认为 0(Pod 一旦准备好就被视为可用)。要了解有关 Pod 何时被视为就绪的更多信息,请参阅容器探测。k rollout status
应用本答案末尾的清单。
打开三个终端窗口;
kubectl run test --rm -it --image curlimages/curl -- sh -c 'i=0; while true; do echo "$(( i++ )): status=$(curl -s -w "%{http_code}" -o null nginx-svc)"; sleep 1; done'
kubectl get pods -w
k rollout status deployment nginx
它将卡在 Waiting for deployment "nginx" rollout to finish: 0 of 1 updated replicas are available...
10 分钟,因为默认 progressDeadlineSeconds
是 600。现在更新图像:
kubectl set image deployment/nginx nginx=nginx:1.26.2
进入 pods 终端,等待 pod 准备好,可以通过
READY
栏了解。约 30 秒后即可准备好
NAME READY STATUS RESTARTS AGE
nginx-6df949b5cc-ccmdn 0/1 Running 0 6s
nginx-6df949b5cc-ccmdn 1/1 Running 0 44s
转到curl屏幕,您可以看到请求数为200,(服务实际上有pod的端点,因为它已经准备好了)。
但是部署还没有完成。
k rollout status deployment nginx
终端窗口仍在等待(将 exit 0
或 exit 1
取决于推出结果)。您可以在status.conditions
相关文档中查看此信息的详细版本,如下所示kubectl describe deployment nginx
Conditions:
Type Status Reason
---- ------ ------
Available True MinimumReplicasAvailable
Progressing True ReplicaSetUpdate
因为医生说:
当执行以下任务之一时,Kubernetes 将部署标记为正在进行:
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nginx
name: nginx
spec:
minReadySeconds: 300
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- image: nginx:does-not-exists
name: nginx
imagePullPolicy: IfNotPresent
readinessProbe:
initialDelaySeconds: 30
httpGet:
path: /
port: 80
---
apiVersion: v1
kind: Service
metadata:
labels:
app: nginx
name: nginx-svc
spec:
ports:
- port: 80
protocol: TCP
selector:
app: nginx