首页 > 解决方案 > 使用 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 秒的停机时间。

标签: kuberneteskubectl

解决方案


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。


推荐阅读