Infra & Cloud yaml Advanced

Kubernetes Network Policy

Deny all ingress by default and only allow traffic from specific namespaces.

yaml
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: deny-all-ingress
spec:
  podSelector: {}
  policyTypes: [Ingress]
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-from-api
spec:
  podSelector:
    matchLabels: { app: database }
  ingress:
    - from:
        - podSelector:
            matchLabels: { app: api }

Prerequisites

  • Kubernetes >= 1.26
  • CNI with NetworkPolicy support

Pro Tips

  • → Test with kubectl exec + nc before applying to production.

Was this module useful?

Share your experience — it helps the team improve.

Leave Feedback

Commercial Licensing

Acquire a production access token or template license for enterprise deployment.

Module Info

Language
yaml
Level
Advanced
Read time
4 min
Published
Nov 2025
License
Commercial License

Newsletter

New modules every week, directly to your inbox.