Asp.net AWS EKS 上 Nginx 入口控制器背后的核心获得“502 Bad Gateway”
Asp.net Core behind a Nginx Ingress Controller on AWS EKS got "502 Bad Gateway"
我按照 aws 中的指南,成功地在 Nginx 入口控制器前面建立了一个带有 NLB 的 EKS 集群。路由工作正常,我可以访问 /banana 和 /apple,对我来说没问题
然后,我尝试添加另一个 ASP.net 应用程序并更新入口
apiVersion: apps/v1
kind: Deployment
metadata:
name: moba-web-portal
labels:
app: moba-web-portal
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: moba-web-portal
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
app: moba-web-portal
spec:
containers:
- image: mcr.microsoft.com/dotnet/samples:aspnetapp
imagePullPolicy: Always
name: moba-web-portal
ports:
- containerPort: 3001
protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
name: moba-web-portal
spec:
selector:
app: moba-web-portal
ports:
- protocol: TCP
port: 3001
targetPort: 3001
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
annotations:
nginx.ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/force-ssl-redirect: "false"
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/proxy-buffering: "on"
nginx.ingress.kubernetes.io/proxy-buffer-size: "128k"
nginx.ingress.kubernetes.io/proxy-buffers-number: "4"
spec:
tls:
- hosts:
- api.kmsmoba.com
secretName: tls-secret
rules:
- host: api.kmsmoba.com
http:
paths:
- pathType: Prefix
path: "/moba"
backend:
service:
name: moba-web-portal
port:
number: 3001
- pathType: Prefix
path: "/apple"
backend:
service:
name: apple-service
port:
number: 5678
- pathType: Prefix
path: "/nodejs"
backend:
service:
name: ecsdemo-nodejs
port:
number: 3000
- pathType: Prefix
path: "/banana"
backend:
service:
name: banana-service
port:
number: 5678
不幸的是,当我尝试访问路径 /moba-web-portal
时,我不明白为什么我只是收到“502 Bad Gateway”
我还尝试将服务名称“moba-web-portal”切换为使用另一个用 nodejs 构建的 docker 图像然后它工作正常,所以我怀疑 asp.net应用程序,但这可能不是问题,因为我使用 Microsoft 的 docker 图像。所以,我想我错过了 Ingress 的一些配置,你能提供一些线索吗?
已编辑:我还尝试在 EC2 工作节点内测试我的 docker 图像,我的 docker 图像在 docker 运行 命令下看起来不错
已编辑以提供更多截屏
asp.net 核心示例侦听端口 80 而不是 3001,更新您的部署:
...
containers:
- image: mcr.microsoft.com/dotnet/samples:aspnetapp
imagePullPolicy: Always
name: moba-web-portal
ports:
- containerPort: 80
...
以及服务规范:
...
kind: Service
metadata:
name: moba-web-portal
spec:
selector:
app: moba-web-portal
ports:
- protocol: TCP
port: 3001
targetPort: 80
...
查看pod的日志:
{"EventId":14,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Now listening on: http://[::]:80","State":{"Message":"Now listening on: http://[::]:80","address":"http://[::]:80","{OriginalFormat}":"Now listening on: {address}"}}
尝试:http://api.kmsmoba.com:3001/moba
将您带到主页“欢迎使用 .NET”
我按照 aws 中的指南,成功地在 Nginx 入口控制器前面建立了一个带有 NLB 的 EKS 集群。路由工作正常,我可以访问 /banana 和 /apple,对我来说没问题
然后,我尝试添加另一个 ASP.net 应用程序并更新入口
apiVersion: apps/v1
kind: Deployment
metadata:
name: moba-web-portal
labels:
app: moba-web-portal
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: moba-web-portal
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
app: moba-web-portal
spec:
containers:
- image: mcr.microsoft.com/dotnet/samples:aspnetapp
imagePullPolicy: Always
name: moba-web-portal
ports:
- containerPort: 3001
protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
name: moba-web-portal
spec:
selector:
app: moba-web-portal
ports:
- protocol: TCP
port: 3001
targetPort: 3001
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
annotations:
nginx.ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/force-ssl-redirect: "false"
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/proxy-buffering: "on"
nginx.ingress.kubernetes.io/proxy-buffer-size: "128k"
nginx.ingress.kubernetes.io/proxy-buffers-number: "4"
spec:
tls:
- hosts:
- api.kmsmoba.com
secretName: tls-secret
rules:
- host: api.kmsmoba.com
http:
paths:
- pathType: Prefix
path: "/moba"
backend:
service:
name: moba-web-portal
port:
number: 3001
- pathType: Prefix
path: "/apple"
backend:
service:
name: apple-service
port:
number: 5678
- pathType: Prefix
path: "/nodejs"
backend:
service:
name: ecsdemo-nodejs
port:
number: 3000
- pathType: Prefix
path: "/banana"
backend:
service:
name: banana-service
port:
number: 5678
不幸的是,当我尝试访问路径 /moba-web-portal
时,我不明白为什么我只是收到“502 Bad Gateway”我还尝试将服务名称“moba-web-portal”切换为使用另一个用 nodejs 构建的 docker 图像然后它工作正常,所以我怀疑 asp.net应用程序,但这可能不是问题,因为我使用 Microsoft 的 docker 图像。所以,我想我错过了 Ingress 的一些配置,你能提供一些线索吗?
已编辑:我还尝试在 EC2 工作节点内测试我的 docker 图像,我的 docker 图像在 docker 运行 命令下看起来不错
已编辑以提供更多截屏
asp.net 核心示例侦听端口 80 而不是 3001,更新您的部署:
...
containers:
- image: mcr.microsoft.com/dotnet/samples:aspnetapp
imagePullPolicy: Always
name: moba-web-portal
ports:
- containerPort: 80
...
以及服务规范:
...
kind: Service
metadata:
name: moba-web-portal
spec:
selector:
app: moba-web-portal
ports:
- protocol: TCP
port: 3001
targetPort: 80
...
查看pod的日志:
{"EventId":14,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Now listening on: http://[::]:80","State":{"Message":"Now listening on: http://[::]:80","address":"http://[::]:80","{OriginalFormat}":"Now listening on: {address}"}}
尝试:http://api.kmsmoba.com:3001/moba
将您带到主页“欢迎使用 .NET”