gpt4 book ai didi

kubernetes - Nginx Ingress 在 Kubernetes 上返回 502 Bad Gateway

转载 作者:行者123 更新时间:2023-12-02 11:32:52 26 4
gpt4 key购买 nike

我在 AWS (EKS) 上部署了一个 Kubernetes 集群。我使用“eksctl”命令行工具部署了集群。我试图在集群上部署 Dash python 应用程序但没有成功。 Dash 的默认端口是 8050。对于部署,我使用了以下资源:

  • pod
  • 服务(ClusterIP 类型)
  • 入口

您可以查看下面的资源配置文件:

pod-configuration-file.yml

kind: Pod
apiVersion: v1
metadata:
name: dashboard-app
labels:
app: dashboard
spec:
containers:
- name: dashboard
image: my_image_from_ecr
ports:
- containerPort: 8050

服务配置文件.yml

kind: Service
apiVersion: v1
metadata:
name: dashboard-service
spec:
selector:
app: dashboard
ports:
- port: 8050 # exposed port
targetPort: 8050

ingress-configuration-file.yml(基于主机的路由)

kind: Ingress
metadata:
name: dashboard-ingress
annotations:
nginx.ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/force-ssl-redirect: "false"
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: dashboard.my_domain
http:
paths:
- backend:
serviceName: dashboard-service
servicePort: 8050
path: /

我按照以下步骤操作:

kubectl apply -f pod-configuration-file.yml
kubectl apply -f service-configuration-file.yml
kubectl apply -f ingress-confguration-file.yml

我还注意到 pod 部署按预期工作:

kubectl logs my_pod:

输出是:

Dash is running on http://127.0.0.1:8050/

Warning: This is a development server. Do not use app.run_server
in production, use a production WSGI server like gunicorn instead.

* Serving Flask app "annotation_analysis" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on

您可以从入口配置文件中看到我想使用我的域进行基于主机的路由。为此,我还部署了一个 nginx-ingress。我还使用 Route53 创建了一个“A”记录集将“dashboard.my_domain”映射到 nginx-ingress:

kubectl get ingress

输出是:

NAME                           HOSTS                                            ADDRESS.           PORTS.   AGE                                                            
dashboard-ingress dashboard.my_domain nginx-ingress.elb.aws-region.amazonaws.com 80 93s

此外,

kubectl describe ingress dashboard-ingress

输出是:

Name:             dashboard-ingress
Namespace: default
Address: nginx-ingress.elb.aws-region.amazonaws.com
Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
Host Path Backends
---- ---- --------
host.my-domain
/ dashboard-service:8050 (192.168.36.42:8050)
Annotations:
nginx.ingress.kubernetes.io/force-ssl-redirect: false

nginx.ingress.kubernetes.io/rewrite-target: /

nginx.ingress.kubernetes.io/ssl-redirect: false
Events: <none>

不幸的是,当我尝试在浏览器上访问 Dash 应用程序时,我得到了一个来自 nginx 的 502 Bad Gateway 错误。你能帮帮我吗,因为我的 Kubernetes 知识有限。提前致谢。

最佳答案

它与 Kubernetes 或 AWS 设置无关。我不得不更改我的 python Dash 代码:

if __name__ == "__main__":
app.run_server(debug=True)

到:

if __name__ == "__main__":
app.run_server(host='0.0.0.0',debug=True).

添加 host='0.0.0.0' 成功了!

关于kubernetes - Nginx Ingress 在 Kubernetes 上返回 502 Bad Gateway,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63113931/

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