kubernetes - 使用 Readiness Probe 和 RollBack 策略的 Kubernetes 0 停机时间不起作用
问题描述
我已经在 Kubernetes 上设置了一个 Node 应用程序。我正在运行一个副本,并且我希望在更新图像时停机时间为 0。set Image
我在 Kubernetes 上使用更新我的 Pod 。
'set', 'image', 'deployment/dev-web'
这是我的 YAML 文件
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "2"
generation: 2
labels:
io.kompose.service: dev-web
name: dev-web
namespace: default
spec:
replicas: 1
selector:
matchLabels:
io.kompose.service: dev-web
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
io.kompose.service: dev-web
spec:
containers:
- env:
image: gcr.io/my-project-link/my-image-link
imagePullPolicy: Always
name: dev-web-container
ports:
- containerPort: 2000
protocol: TCP
readinessProbe:
failureThreshold: 3
httpGet:
path: /
port: 2000
scheme: HTTP
initialDelaySeconds: 5
periodSeconds: 5
successThreshold: 1
timeoutSeconds: 1
resources:
requests:
cpu: 20m
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
status:
availableReplicas: 1
conditions:
- lastTransitionTime: 2018-12-07T11:13:21Z
lastUpdateTime: 2018-12-07T11:13:21Z
message: Deployment has minimum availability.
reason: MinimumReplicasAvailable
status: "True"
type: Available
observedGeneration: 2
readyReplicas: 1
replicas: 1
updatedReplicas: 1
我的应用程序在 '/' get 上确实给出了 200 响应,因此 Readiness Probe 可以工作,但是当我更新图像并对其进行测试但不断点击 CURL 时,它给了我持续 20-40 秒的停机时间。
解决方案
maxUnavailable
即使您只有一个副本,您也应该设置为 1,您也应该设置maxUnavailable
为 0。
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
maxSurge: 1
它基本上告诉 Kubernetes 在部署时应该有零个不可用的 pod ( maxUnavailable: 0
),并且一次应该有一个新的 pod ( maxSurge: 1
)。
我希望你readiness
像这样设置探头:
readinessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 5
periodSeconds: 5
successThreshold: 1
基本上,这是 Kubernetes 所做的一项检查,以确保您的 pod 已准备好向其发送流量。在它没有准备好之前,Kubernetes 不会使用你的 pod。
推荐阅读
- vb.net - vb.net 消息框单击行为与输入键不同
- magento - Magento 2 将自定义字段添加到销售订单导出 csv 问题
- android - 使用测试凭据从 WebView 获取事务 (Plaid)
- python - 用数字标记轮廓,然后提取任何编号轮廓的坐标
- typo3 - 输入文件只接受typo3 Fluid中的PDF
- ios - 标签视图滚动仅适用于 UITableview 内的固定高度
- reactjs - 我得到模块 `./index.css` 无法从 react-native 找到
- javascript - javascript中的日期时间格式转换
- python - 如何处理特定的未捕获异常?
- php - Laravel 5 常量定义