【问题标题】:kubernetes ingress on GKE timeout and 502 during deployment部署期间 GKE 超时和 502 上的 kubernetes 入口
【发布时间】:2018-05-04 16:20:05
【问题描述】:

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

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

这是完整的清单:

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-小

【问题讨论】:

    标签: kubernetes google-cloud-platform kubernetes-ingress


    【解决方案1】:

    您的配置一切正常。看起来您在启动 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
    

    【讨论】:

    • 谢谢你的回答,我会试试initialDelaySeconds。该应用程序启动得非常快(因为它只是一个用 Go 编写的 hello world)。我注意到的另一件事是,如果我直接将服务公开为LoadBalancer,我在部署期间没有502 错误,这似乎与入口中的问题确实相关。
    • 如果您想使用 Ingress,请尝试使用类型 Cluster IP 为您服务。当您使用NodePort 时,由于防火墙问题,某些请求无法继续。
    • 仍然无法使其正常工作,即使服务无法使用 type: LoadBalancer 完成工作,我已使用 rollingUpdate 策略更新了 manifest
    • 您能否检查节点之间的防火墙,可能您的某个节点无法响应请求?
    • 如何检查防火墙?
    猜你喜欢
    • 2019-03-24
    • 2021-05-12
    • 1970-01-01
    • 1970-01-01
    • 2020-06-21
    • 2020-07-24
    • 1970-01-01
    • 2020-06-19
    • 2021-09-13
    相关资源
    最近更新 更多