gpt4 book ai didi

Kubernetes Ingress (GCE) 不断返回 502 错误

转载 作者:行者123 更新时间:2023-12-03 11:38:45 26 4
gpt4 key购买 nike

我正在尝试在 GCE Kubernetes 中设置一个入口。但是当我访问 Ingress 中定义的 IP 地址和路径组合时,我不断收到以下 502 错误:

Ingress 502 error

这是我运行时得到的结果:kubectl describe ing --namespace dpl-staging

Name:           dpl-identity
Namespace: dpl-staging
Address: 35.186.221.153
Default backend: default-http-backend:80 (10.0.8.5:8080)
TLS:
dpl-identity terminates
Rules:
Host Path Backends
---- ---- --------
*
/api/identity/* dpl-identity:4000 (<none>)
Annotations:
https-forwarding-rule: k8s-fws-dpl-staging-dpl-identity--5fc40252fadea594
https-target-proxy: k8s-tps-dpl-staging-dpl-identity--5fc40252fadea594
url-map: k8s-um-dpl-staging-dpl-identity--5fc40252fadea594
backends: {"k8s-be-31962--5fc40252fadea594":"HEALTHY","k8s-be-32396--5fc40252fadea594":"UNHEALTHY"}
Events:
FirstSeen LastSeen Count From SubObjectPath Type Reason Message
--------- -------- ----- ---- ------------- -------- ------ -------
15m 15m 1 {loadbalancer-controller } Normal ADD dpl-staging/dpl-identity
15m 15m 1 {loadbalancer-controller } Normal CREATE ip: 35.186.221.153
15m 6m 4 {loadbalancer-controller } Normal Service no user specified default backend, using system default

我认为问题是 dpl-identity:4000 (<none>) .我不应该看到 dpl-identity的IP地址吗?服务而不是 <none> ?

这是我的服务描述: kubectl describe svc --namespace dpl-staging
Name:           dpl-identity
Namespace: dpl-staging
Labels: app=dpl-identity
Selector: app=dpl-identity
Type: NodePort
IP: 10.3.254.194
Port: http 4000/TCP
NodePort: http 32396/TCP
Endpoints: 10.0.2.29:8000,10.0.2.30:8000
Session Affinity: None
No events.

另外,这是执行的结果: kubectl describe ep -n dpl-staging dpl-identity
Name:       dpl-identity
Namespace: dpl-staging
Labels: app=dpl-identity
Subsets:
Addresses: 10.0.2.29,10.0.2.30
NotReadyAddresses: <none>
Ports:
Name Port Protocol
---- ---- --------
http 8000 TCP

No events.

这是我的 deployment.yaml:
apiVersion: v1
kind: Secret
metadata:
namespace: dpl-staging
name: dpl-identity
type: Opaque
data:
tls.key: <base64 key>
tls.crt: <base64 crt>
---
apiVersion: v1
kind: Service
metadata:
namespace: dpl-staging
name: dpl-identity
labels:
app: dpl-identity
spec:
type: NodePort
ports:
- port: 4000
targetPort: 8000
protocol: TCP
name: http
selector:
app: dpl-identity
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
namespace: dpl-staging
name: dpl-identity
labels:
app: dpl-identity
annotations:
kubernetes.io/ingress.allow-http: "false"
spec:
tls:
- secretName: dpl-identity
rules:
- http:
paths:
- path: /api/identity/*
backend:
serviceName: dpl-identity
servicePort: 4000
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
namespace: dpl-staging
name: dpl-identity
kind: Ingress
metadata:
namespace: dpl-staging
name: dpl-identity
labels:
app: dpl-identity
annotations:
kubernetes.io/ingress.allow-http: "false"
spec:
tls:
- secretName: dpl-identity
rules:
- http:
paths:
- path: /api/identity/*
backend:
serviceName: dpl-identity
servicePort: 4000
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
namespace: dpl-staging
name: dpl-identity
labels:
app: dpl-identity
spec:
replicas: 2
strategy:
type: RollingUpdate
template:
metadata:
labels:
app: dpl-identity
spec:
containers:
- image: gcr.io/munpat-container-engine/dpl/identity:0.4.9
name: dpl-identity
ports:
- containerPort: 8000
name: http
volumeMounts:
- name: dpl-identity
mountPath: /data
volumes:
- name: dpl-identity
secret:
secretName: dpl-identity

最佳答案

您的后台 k8s-be-32396--5fc40252fadea594显示为 "UNHEALTHY" .

如果后端不健康,Ingress 将不会转发流量,这将导致您看到 502 错误。

它将被标记为不健康,因为它没有通过健康检查,您可以检查 k8s-be-32396--5fc40252fadea594 的健康检查设置以查看它们是否适合您的 pod,它可能正在轮询 URI 或端口这不会返回 200 响应。您可以在 Compute Engine > Health Checks 下找到这些设置。

如果它们是正确的,那么您的浏览器和容器之间有很多步骤可能会错误地传递流量,您可以尝试 kubectl exec -it PODID -- bash (或 ash,如果您使用的是 Alpine),然后尝试 curl-ing localhost 以查看容器是否按预期响应,如果是并且健康检查也配置正确,那么这将缩小问题的范围,可能与您的服务有关,然后您可以尝试将服务从 NodePort 类型更改为 LoadBalancer 并查看直接从浏览器访问服务 IP 是否有效。

关于Kubernetes Ingress (GCE) 不断返回 502 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42967763/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com