Interview Prep/DevSecOps/Kubernetes Security

How do you implement a default-deny NetworkPolicy?

IntermediateConceptKubernetes Security
Answer

By default every pod can reach every other pod. A policy with an empty podSelector selects all pods in the namespace; listing both policy types with no rules denies everything.

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata: { name: default-deny, namespace: shop }
spec:
  podSelector: {}
  policyTypes: ["Ingress", "Egress"]

Then add allow policies per flow, and remember to allow egress to CoreDNS on UDP and TCP 53, or every name lookup fails.

All DevSecOps questions Roadmap: Supply chain, secrets & identity

More on Kubernetes Security