gpt4 book ai didi

Kubernetes ingress-nginx 给出 502 错误(坏网关)

转载 作者:行者123 更新时间:2023-12-02 11:37:07 41 4
gpt4 key购买 nike

我有一个我想要的 EKS 集群:
- 每个集群 1 个负载均衡器,
- 指向正确命名空间和正确服务的入口规则。

我一直在关注本指南:https://www.digitalocean.com/community/tutorials/how-to-set-up-an-nginx-ingress-with-cert-manager-on-digitalocean-kubernetes

我的部署:

apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-world
namespace: default
spec:
replicas: 3
selector:
matchLabels:
app: hello-world
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: hello-world
image: IMAGENAME
ports:
- containerPort: 8000
name: hello-world


---

apiVersion: apps/v1
kind: Deployment
metadata:
name: bleble
namespace: default
spec:
replicas: 3
selector:
matchLabels:
app: bleble
template:
metadata:
labels:
app: bleble
spec:
containers:
- name: bleble
image: IMAGENAME
ports:
- containerPort: 8000
name: bleble



这些部署的服务:

apiVersion: v1
kind: Service
metadata:
name: hello-world-svc
spec:
ports:
- port: 8080
protocol: TCP
targetPort: 8000
selector:
app: hello-world
type: NodePort

---

apiVersion: v1
kind: Service
metadata:
name: bleble-svc
spec:
ports:
- port: 8080
protocol: TCP
targetPort: 8000
selector:
app: bleble
type: NodePort


我的负载均衡器:
kind: Service
apiVersion: v1
metadata:
name: ingress-nginx
namespace: ingress-nginx
annotations:
service.beta.kubernetes.io/aws-load-balancer-internal: "true"
labels:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
spec:
externalTrafficPolicy: Local
type: LoadBalancer
selector:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
ports:
- name: http
port: 80
targetPort: http

我的入口:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: simple-fanout-example
namespace : default
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: internal-lb.aws.com
http:
paths:
- path: /bleble
backend:
serviceName: bleble-svc
servicePort: 80
- path: /hello-world
backend:
serviceName: hello-world-svc
servicePort: 80

我已经设置了 Nginx 入口 Controller : kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.24.1/deploy/mandatory.yaml

我不确定为什么我会为一项服务获得 503 服务暂时不可用,而为另一项服务获得 502 服务......我猜这是端口或命名空间的问题?在指南中,他们没有为部署定义命名空间......

每个资源都正确创建,我认为入口实际上正在工作,但对去哪里感到困惑。

谢谢你的帮助!

最佳答案

一般情况下,使用 externalTrafficPolicy: Cluster而不是 Local .您可以通过使用 Local 获得一些性能(延迟)改进但是你需要付出很多努力来配置这些 pod 分配。您将因这些错误配置而遇到 5xx 错误。另外,ClusterexternalTrafficPolicy 的默认选项.

在您的 ingress , 你的路线 /bleble服务bleble ,但您的服务名称实际上是 bleble-svc .请使它们一致。此外,您需要设置您的 servicePort到 8080,因为您在服务配置中公开了 8080。

对于内部服务,如 bleble-svc , Cluster IP在您的情况下已经足够好了,因为它不需要外部访问。

希望这可以帮助。

关于Kubernetes ingress-nginx 给出 502 错误(坏网关),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56474192/

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