Kubernetes 库伯内特斯';s LoadBalancer yaml不工作,即使CLI`expose`功能工作
这是我的Kubernetes 库伯内特斯';s LoadBalancer yaml不工作,即使CLI`expose`功能工作,kubernetes,minikube,Kubernetes,Minikube,这是我的服务和部署yaml,我在minikube上运行: apiVersion: apps/v1 kind: Deployment metadata: name: node-hello-world labels: app: node-hello-world spec: replicas: 1 selector: matchLabels: app: node-hello-world template: metadata: labe
服务
和部署
yaml,我在minikube
上运行:
apiVersion: apps/v1
kind: Deployment
metadata:
name: node-hello-world
labels:
app: node-hello-world
spec:
replicas: 1
selector:
matchLabels:
app: node-hello-world
template:
metadata:
labels:
app: node-hello-world
spec:
containers:
- name: node-hello-world
image: node-hello-world:latest
imagePullPolicy: Never
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: node-hello-world-load-balancer
spec:
type: LoadBalancer
ports:
- protocol: TCP
port: 9000
targetPort: 8080
nodePort: 30002
selector:
name: node-hello-world
结果:
$ minikube service node-hello-world-load-balancer --url
http://192.168.99.101:30002
$ curl http://192.168.99.101:30002
curl: (7) Failed to connect to 192.168.99.101 port 30002: Connection refused
但是,运行以下CLI仍然有效:
$ kubectl expose deployment node-hello-world --type=LoadBalancer
$ minikube service node-hello-world --url
http://192.168.99.101:30130
$ curl http://192.168.99.101:30130
Hello World!
我的LoadBalancer yaml配置有什么问题?您配置了错误的服务选择器
selector:
name: node-hello-world
应该是:
selector:
app: node-hello-world
您可以通过描述服务并查看端点列表为空来调试它,这样就没有映射到端点服务列表的POD
kubectl describe svc node-hello-world-load-balancer | grep -i endpoints
Endpoints: <none>
kubectl描述svc节点hello world负载平衡器| grep-i端点
端点:
服务选择器应与展开选择器匹配。在您的情况下,对于部署,您将选择器命名为“app”,服务选择器命名为“app”