我使用 2 个 pod 进行了部署:
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: nginx
name: nginx
spec:
replicas: 2
selector:
matchLabels:
app: nginx1
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: nginx1
spec:
containers:
- image: nginx
name: nginx
resources: {}
ports:
- containerPort: 80
status: {}
然后用 clusterip 公开它,然后创建一个如下所示的网络策略:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: test-network-policy
namespace: default
spec:
podSelector:
matchLabels:
app: nginx1
policyTypes:
- Ingress
ingress:
- from:
- podSelector:
matchLabels:
role: frontend
但是当我使用不包含标签(角色=前端)的busybox pod通过wget请求它时,我仍然得到nginx的html页面。
我想知道为什么 ?
任何帮助都会非常感激。谢谢 :)