小编Chr*_*aan的帖子

Kubernetes NetworkPolicy允许负载均衡器

我有一个在启用了网络策略支持的Google Kubernetes Engine(GKE)上运行的Kubernetes集群。我为此创建了一个nginx部署和负载均衡器:

kubectl run nginx --image=nginx
kubectl expose deployment nginx --port=80 --type=LoadBalancer
Run Code Online (Sandbox Code Playgroud)

然后,我创建了此网络策略,以确保集群中的其他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
Run Code Online (Sandbox Code Playgroud)

现在,群集中的其他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
Run Code Online (Sandbox Code Playgroud)

但是,令我惊讶的是,使用我的外部浏览器,我也无法再通过负载平衡器连接到它:

open http://$(kubectl get svc nginx --output=jsonpath={.status.loadBalancer.ingress[0].ip})
Run Code Online (Sandbox Code Playgroud)

如果我删除该策略,它将再次开始工作。 …

kubernetes google-kubernetes-engine

5
推荐指数
2
解决办法
863
查看次数