我无法设置对我来说很好的网络策略。这是同一命名空间中的 2 个 pod
k get po --show-labels
NAME READY STATUS RESTARTS AGE LABELS
nfs-server-ccb8d5ff6-7rtr4 1/1 Running 0 22h role=nfs-server
nginx-jpm-549b69bf68-x5hd7 1/1 Running 0 21h app=nginx-jpm
我正在使用以下网络策略规范限制到 nfs-server pod 的流量:
spec:
podSelector:
matchLabels:
role: nfs-server
policyTypes:
- Ingress
- Egress
ingress:
# Allow inbound from nginx-jpm on all ports
- from:
- podSelector:
matchLabels:
app: nginx-jpm
egress:
# Allow outbound DNS traffic inside the cluster (kube-system namespace is not labelled)
- to:
- namespaceSelector: {}
ports:
- protocol: "UDP"
port: 53
我执行到 nginx pod 并且无法连接到 nfs-server pod
root@nginx-jpm-549b69bf68-x5hd7:/# telnet nfs-server.jenkinsrepo.svc.cluster.local 111
Trying 172.22.117.55...
If I delete the network policy, it works then
root@nginx-jpm-549b69bf68-x5hd7:/# telnet nfs-server.jenkinsrepo.svc.cluster.local 111
Trying 172.22.117.55...
Connected to nfs-server.jenkinsrepo.svc.cluster.local.
Escape character is '^]'.
我的网络策略中是否遗漏了什么?命名空间中没有其他网络策略。