【发布时间】:2017-11-16 10:43:29
【问题描述】:
我有一个在 Google Kubernetes Engine (GKE) 上运行并启用了网络策略支持的 Kubernetes 集群。 我为它创建了一个 nginx 部署和负载均衡器:
kubectl run nginx --image=nginx
kubectl expose deployment nginx --port=80 --type=LoadBalancer
然后我创建了这个网络策略来确保集群中的其他 pod 将无法再连接到它:
kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
name: access-nginx
spec:
podSelector:
matchLabels:
run: nginx
ingress:
- from:
- namespaceSelector:
matchLabels:
name: kube-system
ports:
- protocol: TCP
port: 80
现在我集群中的其他 pod 无法访问它(如预期的那样):
kubectl run busybox --rm -ti --image=busybox /bin/sh
If you don't see a command prompt, try pressing enter.
/ # wget --spider --timeout=1 nginx
Connecting to nginx (10.63.254.50:80)
wget: download timed out
然而,令我惊讶的是,使用我的外部浏览器我也无法通过负载平衡器连接到它:
open http://$(kubectl get svc nginx --output=jsonpath={.status.loadBalancer.ingress[0].ip})
如果我删除该策略,它会再次开始工作。
所以,我的问题是:如何阻止其他 pod 访问 nginx,但保持通过负载均衡器的访问处于打开状态?
【问题讨论】:
标签: kubernetes google-kubernetes-engine