[英]Kubernetes ingress returning a 502 bad gateway
So, I am trying to deploy a personal website app and expose it to a local domain (for now) but I am always getting a 502 Bad Gateway from my nginx-ingress-controller .因此,我正在尝试部署一个个人网站应用程序并将其公开给本地域(目前),但我总是从我的 nginx-ingress-controller 获得 502 Bad Gateway 。 So, for such task I have built 3 files:
deployment.yaml
, service.yaml
and ingress.yaml
:因此,对于这样的任务,我构建了 3 个文件:
deployment.yaml
、 service.yaml
和ingress.yaml
:
apiVersion: apps/v1
kind: Deployment
metadata:
name: website-deployment
labels:
app: website
spec:
replicas: 1
selector:
matchLabels:
app: website
template:
metadata:
labels:
app: website
spec:
containers:
- name: website
image: jotinha2014/private
ports:
- containerPort: 55004
apiVersion: v1
kind: Service
metadata:
name: website-service
spec:
selector:
app: website
ports:
- protocol: TCP
port: 80
targetPort: 55004
type: ClusterIP
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: website-ingress
namespace: default
annotations:
nginx.ingress.kubernetes.io/service-upstream: "true"
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: rabanadas.eu
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: website-service
port:
number: 80
Here are some logs from my nginx-ingress-controller:以下是来自我的 nginx-ingress-controller 的一些日志:
2021/01/03 01:13:31 [error] 1371#1371: *34677 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.64.1, server: rabanadas.eu, request: "GET / HTTP/1.1", upstream: "http://10.106.8.10:80/", host: "rabanadas.eu"
2021/01/03 01:13:31 [error] 1371#1371: *34677 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.64.1, server: rabanadas.eu, request: "GET / HTTP/1.1", upstream: "http://10.106.8.10:80/", host: "rabanadas.eu"
2021/01/03 01:13:31 [error] 1371#1371: *34677 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.64.1, server: rabanadas.eu, request: "GET / HTTP/1.1", upstream: "http://10.106.8.10:80/", host: "rabanadas.eu"
192.168.64.1 - - [03/Jan/2021:01:13:31 +0000] "GET / HTTP/1.1" 502 552 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" 474 0.000 [default-website-service-80] [] 10.106.8.10:80, 10.106.8.10:80, 10.106.8.10:80 0, 0, 0 0.000, 0.000, 0.000 502, 502, 502 dff7944bbbc17be35584fee465d047d2
W0103 01:15:52.298006 8 warnings.go:67] networking.k8s.io/v1beta1 Ingress is deprecated in v1.19+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
Right now I am using minikube and, as such, my nginx-ingress-controller was configure just by adding it as addon .现在我正在使用 minikube,因此,我的 nginx-ingress-controller 只是通过将其添加为addon来配置。 I suspect that the problem is with my ingress configuration because I've already port-forwarded the pod deployed and the website is showing as it is supposed on the right port.
我怀疑问题出在我的入口配置上,因为我已经对部署的 pod 进行了端口转发,并且网站正在正确的端口上显示。
As requested, here are my website pod details:根据要求,这是我的网站 pod 详细信息:
Name: website-deployment-69f57fc45-l4th9
Namespace: default
Priority: 0
Node: minikube/192.168.64.5
Start Time: Sun, 03 Jan 2021 00:53:16 +0000
Labels: app=website
pod-template-hash=69f57fc45
Annotations: <none>
Status: Running
IP: 172.17.0.2
IPs:
IP: 172.17.0.2
Controlled By: ReplicaSet/website-deployment-69f57fc45
Containers:
website:
Container ID: docker://eae48617da80f3ac4832695535432581746d925fc497066a5fd8a707b3020a88
Image: jotinha2014/private
Image ID: docker-pullable://jotinha2014/private@sha256:0a9573429315745eae0a33339021c82db2e92e0ba35ca652aa20482af31f1219
Port: 55004/TCP
Host Port: 0/TCP
State: Running
Started: Sun, 03 Jan 2021 00:53:18 +0000
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-j8pzx (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
default-token-j8pzx:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-j8pzx
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events: <none>
Thanks in advance fo any help.提前感谢任何帮助。
As per the comments;根据评论; The
targetPort
in the Service
manifest, and the containerPort
in the Deployment
manifest need to match the port that the server inside the container is listening on. Service
清单中的targetPort
和Deployment
清单中的containerPort
需要匹配容器内的服务器正在侦听的端口。
As nginx by default listens on port 80, these should be changed to port 80. Otherwise, the server in the container should be changed to listen on a different port.由于 nginx 默认侦听端口 80,因此应将其更改为端口 80。否则,应将容器中的服务器更改为侦听不同的端口。 For nginx this can be done with an nginx.conf file, or by setting an
NGINX_PORT
environment variable.对于 nginx,这可以通过 nginx.conf 文件或通过设置
NGINX_PORT
环境变量来完成。 See https://hub.docker.com/_/nginx for details.有关详细信息,请参阅https://hub.docker.com/_/nginx 。
Usually, you'll run one container per pod, so changing the port to something other than 80 is rarely needed.通常,每个 pod 运行一个容器,因此很少需要将端口更改为 80 以外的端口。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.