I made deployment with 2 pods:
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: {}
Then exposed it with clusterip, then created a networkpolicy like below:
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
But when i request it via wget using busybox pod which DOES NOT contain the label (role=frontend), i still getting the html page of nginx.
I would like to know why ?
Any help would be really appriciated. Thank you :)
If your k8s cluster is deployed with
Container Network Interface (CNI)
plugin that does not support network policies, it will not have an impact on it. From k8s docs: