【问题标题】:How to tell Kubernetes not to send traffic to a pod right after creation如何告诉 Kubernetes 在创建后不要立即向 Pod 发送流量
【发布时间】:2021-03-30 22:03:41
【问题描述】:

我有一个 Kubernetes nginx 部署,当我再次使用 kubectl apply -f file.yaml 重新部署它时,它的停机时间很短,大约 3 或 5 秒。

我正在使用 readinessProbe 告诉 Kubernetes 在准备就绪之前不应将流量发送到该 pod,但只要部署开始(即使 initialDelaySeconds 尚未完成,我也会收到 502/ 503 错误在准备就绪后立即结束。

所以,我认为,在 readinessProbe 成功之前,Kubernetes 不应该考虑该 pod,但这不是我所看到的。

如果我将initialDelaySeconds 设置为 10,我会遇到大约 10 秒的中断。如果我将它减少到 0,我仍然有一小段停机时间,直到准备就绪。

我正在使用的服务/部署的相关部分是

---
apiVersion: v1
kind: Service
metadata:
  name: 'name'
spec:
  ports:
    - port: 80
      protocol: TCP
      name: http
  selector:
    project: 'project'
    role: bastion
  type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: 'bastion'
spec:
  replicas: 6
  strategy:
    rollingUpdate:
      maxSurge: 6
      maxUnavailable: 0
    type: RollingUpdate
  template:
    metadata:
    spec:
      containers:
        - name: 'bastion'
          image: 'my-image'
          imagePullPolicy: Always
          ports:
            - containerPort: 80
          lifecycle:
            preStop:
              exec:
                command: ['sh', '-c', '/usr/sbin/nginx -s quit;']
          livenessProbe:
            httpGet:
              path: /myendpoint
              port: 80
            periodSeconds: 60
            initialDelaySeconds: 15
            failureThreshold: 15
          readinessProbe:
            httpGet:
              path: /myendpoint
              port: 80
          resources:
            requests:
              cpu: 5m
              memory: 5Mi
            limits:
              cpu: 50m
              memory: 50Mi
      imagePullSecrets:
        - name: 'imagesecrets'

这里有什么我遗漏的吗?我可以尝试进行哪些更改来调试/修复此问题?

【问题讨论】:

  • 您能提供 pod 规格吗?
  • 您是否使用重新创建作为部署策略?
  • 我已经添加了规格@anemyte
  • 我正在使用滚动更新策略@AvinashKumar
  • 我浏览了一下,在我看来 maxUnavailable: 0 是问题所在,将其设为 3 或一些...

标签: nginx kubernetes


【解决方案1】:

你用过

periodSeconds: 60
initialDelaySeconds: 15
failureThreshold: 15

对于livenessProbe,但您没有为就绪探测定义任何内容。我认为这就是您看到错误的原因。尝试为readinessProbe 定义initialDelaySeconds 以及

此外,为了调试它,您可以描述一个新创建的 pod。您将在最后看到所有正在发生的事件,包括就绪探测事件

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-29
    • 2018-07-31
    • 2011-06-17
    • 2012-08-14
    • 1970-01-01
    • 1970-01-01
    • 2021-04-12
    • 2016-11-28
    相关资源
    最近更新 更多