使用 Readiness Probe 和 RollBack 策略的 Kubernetes 0 停机时间不起作用

Kubernetes 0 Downtime using Readiness Probe and RollBack strategy not working

我已经在 Kubernetes 上设置了一个 Node 应用程序。我是 运行 单个副本,我希望在更新图像时停机时间为 0。我在 Kubernetes 上使用 set Image 更新我的 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

我的应用程序确实在“/”获取上给出了 200 个响应,因此就绪探测工作正常,但是当我更新图像并对其进行测试但持续点击 CURL 时,它让我停机,持续大约 20-40 秒。

您将 maxUnavailable 设置为 1,即使您只有一个副本,您也应该将 maxUnavailable 设置为 0。

strategy:
 type: RollingUpdate
 rollingUpdate:
   maxUnavailable: 0
   maxSurge: 1

它基本上告诉 Kubernetes 在部署时应该有零个不可用 pods (maxUnavailable: 0) 并且一次应该有一个新的 pod (maxSurge: 1)。

我希望你像这样设置 readiness 探测器:

readinessProbe:
  httpGet:
    path: /
    port: 80
  initialDelaySeconds: 5
  periodSeconds: 5
  successThreshold: 1

基本上,这是 Kubernetes 执行的一项检查,以确保您的 pod 已准备好向其发送流量。在未准备好之前,Kubernetes 不会使用您的 pod。