首页 文章

kubernetes在GKE超时时进入,在部署期间为502

提问于
浏览
1

我很难弄清楚为什么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应用程序 .

在部署期间,如果我围攻我的应用程序的入口 Health 检查,我注意到:

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

  • 谷歌 Cloud 平台

  • g1-小

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
    

相关问题