AKS Network Policy: Locking Down Traffic

On this page

By default, all pods in a Kubernetes cluster can talk to each other. This is a security risk. If a frontend pod is compromised, the attacker can scan your database pod. Network Policies act as an internal firewall.

Deny All Ingress

Start by blocking everything.

YAML8 lines
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny-all
spec:
  podSelector: {}
  policyTypes:
  - Ingress

Allow Frontend to Backend

YAML14 lines
kind: NetworkPolicy
metadata:
  name: api-allow-frontend
spec:
  podSelector:
    matchLabels:
      app: api
  ingress:
  - from:
    - podSelector:
        matchLabels:
            app: frontend
    ports:
    - port: 80

Key Takeaways

  • You must enable a Network Plugin (Azure CNI or Kubenet) that supports policies (Calico or Azure Policy).
  • Policies are namespace-scoped.

Discover more from C4: Container, Code, Cloud & Context

Subscribe to get the latest posts sent to your email.

Written by

Nithin Mohan TK

Hello Namaste! 👋🏻 I'm an accomplished Enterprise Solution Architect & Engineering Leader with 20+ years of progressive experience architecting, building, and scaling transformative enterprise solutions. ⚜️ Solution Architect / AI & Cloud 📌 Galway, Ireland

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.