【发布时间】:2021-04-04 07:19:46
【问题描述】:
我正在修复现有 Kubernetes 多容器一 pod 部署中的一些错误。我已经修复了一部分;我只是缺少将流量从“前端”容器路由到“后端”容器的语法。
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 时,我得到了网页本身,但后端服务没有正确连接,Nginx 反而显示 502 Bad Gateway 错误。
我已经深入研究了 Kubenetes 文档,并尝试了 hostPort 各个地方,但我仍然不正确。
任何帮助将不胜感激!
【问题讨论】:
-
两个容器在同一个 80 端口?我认为不可能,尝试将另一个容器暴露在不同的端口并在服务中映射。
标签: nginx kubernetes minikube