[英]Nginx Ingress returns 502 Bad Gateway on Kubernetes
I have a Kubernetes cluster deployed on AWS (EKS).我在 AWS (EKS) 上部署了一个 Kubernetes 集群。 I deployed the cluster using the “eksctl” command line tool.
我使用“eksctl”命令行工具部署了集群。 I'm trying to deploy a Dash python app on the cluster without success.
我正在尝试在集群上部署 Dash python 应用程序但没有成功。 The default port for Dash is 8050. For the deployment I used the following resources:
Dash 的默认端口是 8050。对于部署,我使用了以下资源:
You can check the resource configuration files below:您可以检查以下资源配置文件:
pod-configuration-file.yml吊舱配置文件.yml
kind: Pod
apiVersion: v1
metadata:
name: dashboard-app
labels:
app: dashboard
spec:
containers:
- name: dashboard
image: my_image_from_ecr
ports:
- containerPort: 8050
service-configuration-file.yml服务配置文件.yml
kind: Service
apiVersion: v1
metadata:
name: dashboard-service
spec:
selector:
app: dashboard
ports:
- port: 8050 # exposed port
targetPort: 8050
ingress-configuration-file.yml (host based routing) 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: /
I followed the steps below:我按照以下步骤操作:
kubectl apply -f pod-configuration-file.yml
kubectl apply -f service-configuration-file.yml
kubectl apply -f ingress-confguration-file.yml
I also noticed that the pod deployment works as expected:我还注意到 pod 部署按预期工作:
kubectl logs my_pod:
and the output is: output 是:
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
You can see from the ingress configuration file that I want to do host based routing using my domain.您可以从入口配置文件中看到我想使用我的域进行基于主机的路由。 For this to work, I have also deployed an nginx-ingress.
为此,我还部署了一个 nginx-ingress。 I have also created an “A” record set using Route53 that maps the “dashboard.my_domain” to the nginx-ingress:
我还使用 Route53 创建了一个“A”记录集,将“dashboard.my_domain”映射到 nginx-ingress:
kubectl get ingress
and the output is: output 是:
NAME HOSTS ADDRESS. PORTS. AGE
dashboard-ingress dashboard.my_domain nginx-ingress.elb.aws-region.amazonaws.com 80 93s
Moreover,而且,
kubectl describe ingress dashboard-ingress
and the output is: output 是:
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>
Unfortunately, when I try to access the Dash app on the browser, I get a 502 Bad Gateway error from the nginx.不幸的是,当我尝试在浏览器上访问 Dash 应用程序时,我从 nginx 收到502 Bad Gateway错误。 Could you please help me because my Kubernetes knowledge is limited.
你能帮我吗,因为我的 Kubernetes 知识有限。 Thanks in advance.
提前致谢。
It had nothing to do with Kubernetes or AWS settings.它与 Kubernetes 或 AWS 设置无关。 I had to change my python Dash code from:
我不得不从以下位置更改我的 python Dash 代码:
if __name__ == "__main__":
app.run_server(debug=True)
to:至:
if __name__ == "__main__":
app.run_server(host='0.0.0.0',debug=True).
The addition of host='0.0.0.0' did the trick!添加host='0.0.0.0'就成功了!
I think you'll need to check whether any other service is exposed at path /
on the same host.我认为您需要检查是否在同一主机上的路径
/
上公开了任何其他服务。
Secondly, try removing rewrite-target
annotation.其次,尝试删除
rewrite-target
注释。 Also can you please update your question with output of kubectl describe ingress <ingress_Name>
您还可以使用 kubectl
kubectl describe ingress <ingress_Name>
的 output 更新您的问题吗
I would also suggest you to use backend-protocol
annotation with value as HTTP
(default value, you can avoid using this if dashboard application is not SSL Configured, and only this application is served at the said host.) But, you may need to add this if multiple applications are served at this host, and create one Ingress with backend-protocol: HTTP
for non SSL services, and another with backend-protocol: HTTPS
to serve traffic to SSL enabled services.我还建议您使用值为
HTTP
backend-protocol
注释(默认值,如果仪表板应用程序未配置 SSL,则可以避免使用此功能,并且只有此应用程序在所述主机上提供服务。)但是,您可能需要add this if multiple applications are served at this host, and create one Ingress with backend-protocol: HTTP
for non SSL services, and another with backend-protocol: HTTPS
to serve traffic to SSL enabled services.
For more information on backend-protocol
annotation, kindly refer this link.有关
backend-protocol
注释的更多信息,请参阅此链接。
I have often faced this issue in my Ingress Setup and these steps have helped me resolve it.我在 Ingress Setup 中经常遇到这个问题,这些步骤帮助我解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.