Kubernetes 推出在切换网络时出现 503 错误 pods

Kubernetes rollout give 503 error when switching web pods

我是运行这个命令:

kubectl set image deployment/www-deployment VERSION_www=newImage

工作正常。但是有一个 10 秒 window 网站是 503,我是一个完美主义者。

如何配置kubernetes等待镜像可用再切换入口?

我正在使用此处的 nginx 入口控制器:

gcr.io/google_containers/nginx-ingress-controller:0.8.3

Web 服务器的这个 yaml:

# Service and Deployment
apiVersion: v1
kind: Service
metadata:
  name: www-service
spec:
  ports:
  - name: http-port
    port: 80
    protocol: TCP
    targetPort: http-port
  selector:
    app: www
  sessionAffinity: None
  type: ClusterIP
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: www-deployment
spec:
  replicas: 1
  template:
    metadata:
      labels: 
        app: www
    spec:
      containers:
      - image: myapp/www
        imagePullPolicy: Always
        livenessProbe:
          httpGet:
            path: /healthz
            port: http-port
        name: www
        ports:
        - containerPort: 80
          name: http-port
          protocol: TCP
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
        volumeMounts:
        - mountPath: /etc/env-volume
          name: config
          readOnly: true
      imagePullSecrets:
      - name: cloud.docker.com-pull
      volumes:
      - name: config
        secret:
          defaultMode: 420
          items:
          - key: www.sh
            mode: 256
            path: env.sh
          secretName: env-secret

Docker 图片基于 node.js server image

/healthz 是网络服务器中的一个文件,returns ok 我认为 liveness probe 会确保服务器在切换到新版本之前已启动并准备就绪。

提前致谢!

Pod lifecycle 中定义:

The default state of Liveness before the initial delay is Success.

为确保您不会 运行 遇到问题,最好也为您的 Pods 配置 ReadinessProbe 并考虑为您的 Deployment 配置 .spec.minReadySeconds

您可以在 Deployment 文档中找到详细信息