[英]502 Bad Gateway with Kubernetes Ingress
I have a kubernetes setup with the configuration like below:我有一个 kubernetes 设置,配置如下:
#---
kind: Service
apiVersion: v1
metadata:
name: myservice
spec:
selector:
app: my-service
ports:
- protocol: "TCP"
# Port accessible inside cluster
port: 8080
# Port to forward to inside the pod
targetPort: 80
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: my-service
spec:
replicas: 1
template:
metadata:
labels:
app: my-service
spec:
containers:
- name: my-service
image: my-custom-docker-regisry/my-service:latest
imagePullPolicy: Always
ports:
- containerPort: 8080
imagePullSecrets:
- name: regcred
and my ingress:和我的入口:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: test-ingress
annotations:
nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
rules:
- http:
paths:
- path: /myservice
backend:
serviceName: myservice
servicePort: 80
What I tried to do is pulling the image from my docker registry and run it in the kubernetes.我试图做的是从我的 docker 注册表中提取图像并在 kubernetes 中运行它。 I have configured here one deployment and one service and expose the service to the outside with the ingress.
我在这里配置了一项部署和一项服务,并通过入口将服务暴露给外部。
My minikube is running under ip 192.168.99.100 and when I tried to access my application with address: curl 192.168.99.100:80/myservice, I got 502 Bad Gateway.我的 minikube 在 ip 192.168.99.100 下运行,当我尝试使用地址访问我的应用程序时:curl 192.168.99.100:80/myservice,我得到 502 Bad Gateway。
Does anyone have an idea why it happended or did I do something wrong with the configuration?有没有人知道它为什么会发生,或者我在配置上做错了什么? Thank you in advanced!
先谢谢了!
Your ingress targets this service:您的入口针对此服务:
serviceName: myservice
servicePort: 80
but the service named myservice
exposes port 8080
rather than 80
:但名为
myservice
的服务公开端口8080
而不是80
:
ports:
- protocol: "TCP"
# Port accessible inside cluster
port: 8080
# Port to forward to inside the pod
targetPort: 80
Your ingress should point to one of the ports exposed by the service.您的入口应指向服务公开的端口之一。
Also, the service itself targets port 80, but the pods in your deployment seem to expose port 8080, rather than 80:此外,服务本身以端口 80 为目标,但部署中的 pod 似乎公开了端口 8080,而不是 80:
containers:
- name: my-service
image: my-custom-docker-regisry/my-service:latest
imagePullPolicy: Always
ports:
- containerPort: 8080
So long story short, looks like you could swap port
with targetPort
in your service
so that:长话短说,看起来您可以在
service
targetPort
port
与targetPort
交换,以便:
8080
8080
端口8080
of all the pods under service name myservice
port 80
,myservice
端口80
下所有 pod 的端口8080
,myservice
port 80
.myservice
端口80
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.