GKE 超时的 kubernetes 入口和部署期间的 502



我很难弄清楚为什么 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-小

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

您的应用在容器中启动多长时间?您可以添加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

相关内容

  • 没有找到相关文章

最新更新