![](/img/trans.png)
[英]How to route all traffic from a container through another container in the same Kubernetes pod?
[英]Kubernetes multi-container pod: how to get network traffic between pods … 502 error?
我正在修復現有 Kubernetes 多容器一吊艙部署中的一些錯誤。 我已經修復了一部分; 我只是缺少將流量從“前端”容器路由到“后端”容器的語法。
YAML 文件:
apiVersion: apps/v1
kind: Deployment
metadata:
name: minikube-hello-world
labels:
app: hello-world
spec:
replicas: 1
selector:
matchLabels:
app: hello-world
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: hello-world-frontend
image: frontend:latest
imagePullPolicy: Never
ports:
- containerPort: 80
- name: hello-world-backend
image: backend:latest
imagePullPolicy: Never
ports:
- containerPort: 80
---
kind: Service
apiVersion: v1
metadata:
name: hello-world-service
spec:
selector:
app: hello-world
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 31443
type: LoadBalancer
當我運行minikube service hello-world-service時,我得到 web 頁面本身,但后端服務沒有正確連接,Nginx 而是顯示502 Bad Gateway錯誤。
我已經深入研究了 Kubenetes 文檔,並且在不同的地方嘗試了hostPort ,但我仍然不正確。
任何幫助將非常感激!
正如克里斯蒂安·阿爾塔米拉諾·阿亞拉在上面評論的那樣,
兩個容器不能在同一個端口上。 (我應該想到這一點。)
我將前端更改為端口 8080:
spec:
containers:
- name: hello-world-frontend
image: frontend:latest
imagePullPolicy: Never
ports:
- containerPort: 8080
- name: hello-world-backend
image: backend:latest
imagePullPolicy: Never
ports:
- containerPort: 80
並且 NodePort 到 8080 的映射也:
kind: Service
apiVersion: v1
metadata:
name: hello-world-service
spec:
selector:
app: hello-world
ports:
- protocol: TCP
nodePort: 31443
port: 8080
type: LoadBalancer
這有效。 謝謝!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.