【问题标题】:Kubernetes updating only 1 pod instead of all ( 2 replicas) on Rolling UpdateKubernetes 在滚动更新时仅更新 1 个 pod 而不是全部(2 个副本)
【发布时间】:2018-12-14 08:50:22
【问题描述】:

我已经设置了 2 个部署副本。

当我使用时

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

当我通过 set Image 更新它时,它只更新 1 个 pod。第二个 pod 不会使用新代码进行更新。这意味着 1 有 2 个 pod 运行不同的图像。

当我设置 maxSurge 25% 和 maxUnavailable 25% 时,pod 根本不会被替换。

这是完整的 yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "89"
  creationTimestamp: 2018-11-26T09:40:48Z
  generation: 94
  labels:
    io.kompose.service: servicing
  name: servicing
  namespace: default
  resourceVersion: "6858872"
  selfLink: /apis/extensions/v1beta1/namespaces/default/deployments/servicing
  uid: 5adb98c8-f15f-11e8-8752-42010a800188
spec:
  replicas: 2
  selector:
    matchLabels:
      io.kompose.service: servicing
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: servicing
    spec:
      containers:
      - env:
        - name: JWT_KEY
          value: ABCD
        - name: PORT
          value: "3001"
        image: gcr.io/something/something
        imagePullPolicy: Always
        name: servicing-container
        ports:
        - containerPort: 3001
          protocol: TCP
        readinessProbe:
          failureThreshold: 3
          httpGet:
            path: /
            port: 3001
            scheme: HTTP
          initialDelaySeconds: 5
          periodSeconds: 5
          successThreshold: 1
          timeoutSeconds: 1
        resources:
          requests:
            cpu: 25m
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
status:
  availableReplicas: 2
  conditions:
  - lastTransitionTime: 2018-12-13T11:55:00Z
    lastUpdateTime: 2018-12-13T11:55:00Z
    message: Deployment has minimum availability.
    reason: MinimumReplicasAvailable
    status: "True"
    type: Available
  observedGeneration: 94
  readyReplicas: 2
  replicas: 2
  updatedReplicas: 2

【问题讨论】:

  • 你能展示你的规范的其余部分吗?
  • 已经用完整的 YAML 更新了答案。

标签: kubernetes


【解决方案1】:

您已将initialDelaySeconds 设置为 5,periodSeconds 设置为 5,failureThreshold 设置为 3,这意味着 kubernetes 将等待最初的 5 秒以首先探测您的应用程序是否准备好,然后定期探测您的应用程序每 5 秒准备好与否,将执行 3 次。因此,您的应用程序将在 10 秒、15 秒和 20 秒时被检查,如果 pod 没有在这段时间内出现,它会在不升级的情况下退出。

您可能需要增加此failureThreshold,以便您的应用有足够的时间启动。

另外,我建议您将 maxUnavailable 设为 0,这样 pod 只会在新 pod 出现替换时被删除。

在这里查看我的答案以获得更好的理解:

Kubernetes 0 Downtime using Readiness Probe and RollBack strategy not working

【讨论】:

    猜你喜欢
    • 2018-03-04
    • 1970-01-01
    • 1970-01-01
    • 2019-05-19
    • 1970-01-01
    • 2020-08-27
    • 1970-01-01
    • 2021-09-21
    相关资源
    最近更新 更多