Network Policies

Overview

Network policies restrict pod-to-pod communication in Kubernetes using least-privilege traffic rules.

Policy Goals

flowchart LR A[Frontend Pod] -->|allowed| B[API Pod] A -. denied .-> C[Database Pod]

Practical Example

apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: allow-api-only spec: podSelector: matchLabels: app: api ingress: - from: - podSelector: matchLabels: app: frontend

Production Example

Platform teams commonly apply a default deny policy and then grant explicit allow rules for known service dependencies.

Common Pitfalls

Key Takeaways