Key Concepts
podSelector: {}Selects all pods in the namespace.
policyTypes: [Ingress]Only restricts incoming traffic.
policyTypes: [Egress]Only restricts outgoing traffic.
ingress: []Empty ingress list means deny all ingress.
namespaceSelectorAllow traffic from pods in specific namespaces.
ipBlockAllow or deny traffic from a specific CIDR range.
Common Patterns
Default deny allpodSelector: {} with empty ingress rules. Blocks everything.
Allow same namespaceUse namespaceSelector with the namespace's own labels.
Allow specific portAdd ports section to the ingress rule.
Multi-rule AND logicpodSelector and namespaceSelector in the same rule element mean AND.
Multi-rule OR logicSeparate elements in the from array mean OR.
kubectl Commands
get networkpoliciesList all network policies in current namespace.
describe netpol <name>Show full policy spec and affected pods.
delete netpol <name>Remove a policy. Traffic immediately flows again.
get pods --show-labelsSee pod labels. Policies match on labels.