2

我很难弄清楚为什么 GKE 上的入口在项目部署期间返回 502 错误和超时。

为了更好地理解这个问题,我设置了一个基本的hello 应用程序,它采用相同的工作流程。

这是完整的清单:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: helloapp
  labels:
    app: helloapp
spec:
  replicas: 3
  template:
    metadata:
      labels:
        app: helloapp
    spec:
      containers:
      - name: helloapp
        image: gcr.io/${GCLOUD_PROJECT_ID}/helloapp:${HELLOAPP_VERSION}
        imagePullPolicy: Always
        ports:
        - name: http-server
          containerPort: 8080

        readinessProbe:
          httpGet:
            path: /sys/health
            port: 8080

        livenessProbe:
          httpGet:
            path: /sys/health
            port: 8080

---

apiVersion: v1
kind: Service
metadata:
  name: helloapp
  labels:
    app: helloapp
spec:
  type: NodePort
  externalTrafficPolicy: Local
  ports:
    - port: 80
      targetPort: http-server
  selector:
    app: helloapp

---

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: helloapp-http
spec:
  backend:
    serviceName: helloapp
    servicePort: 80

其中包含一个入口、一个服务和针对 Pod 的定制探针。

该应用程序是用Go编写的简单的 hello world 应用程序。

在部署期间,如果我围攻我的应用程序的入口运行状况检查并且我注意到:

HTTP/1.1 502     9.02 secs:     332 bytes ==> GET  /sys/health
HTTP/1.1 502     9.10 secs:     332 bytes ==> GET  /sys/health
HTTP/1.1 200     4.70 secs:     473 bytes ==> GET  /sys/health
HTTP/1.1 200     4.56 secs:     475 bytes ==> GET  /sys/health
HTTP/1.1 200     0.01 secs:     475 bytes ==> GET  /sys/health
HTTP/1.1 200     0.01 secs:     476 bytes ==> GET  /sys/health
HTTP/1.1 200     0.03 secs:     475 bytes ==> GET  /sys/health
HTTP/1.1 200     0.01 secs:     474 bytes ==> GET  /sys/health
HTTP/1.1 200     4.58 secs:     475 bytes ==> GET  /sys/health
HTTP/1.1 200     4.51 secs:     474 bytes ==> GET  /sys/health
HTTP/1.1 200     0.01 secs:     475 bytes ==> GET  /sys/health
HTTP/1.1 200     0.01 secs:     475 bytes ==> GET  /sys/health
HTTP/1.1 200     4.83 secs:     474 bytes ==> GET  /sys/health
HTTP/1.1 502     9.07 secs:     332 bytes ==> GET  /sys/health
HTTP/1.1 200     0.02 secs:     475 bytes ==> GET  /sys/health

几分钟后(通常是 5-10 分钟),它会停止并正确转发请求。

集群信息:

  • Kubernetes 版本:1.8.8
  • 谷歌云平台
  • g1-小
4

1 回答 1

0

你的配置一切都很好。看起来您在 go-app 启动期间遇到了问题:对您的服务的循环正在向 pod 中未启动的应用程序发送一些请求,这会导致代码 502 错误。

您的应用程序在 pod 中启动多长时间?您可以添加 initialDelaySeconds 以修复您的错误。

spec:
  replicas: 3
  template:
    metadata:
      labels:
        app: helloapp
    spec:
      containers:
      - name: helloapp
        image: gcr.io/${GCLOUD_PROJECT_ID}/helloapp:${HELLOAPP_VERSION}
        imagePullPolicy: Always
        ports:
        - name: http-server
          containerPort: 8080

        readinessProbe:
          httpGet:
            path: /sys/health
            port: 8080
            initialDelaySeconds: 60

        livenessProbe:
          httpGet:
            path: /sys/health
            port: 8080
            initialDelaySeconds: 120
于 2018-05-08T12:34:20.613 回答