โ˜ธ๏ธKubernetes Network Policies Labs

๐Ÿšง Under Construction!! Does not work with training environment due to missing CNI support.

๐ŸŽฏ Objective

Learn how to secure pod-to-pod communication using Kubernetes Network Policies.


๐Ÿงฐ Prerequisites

  • Kubernetes cluster (Minikube, kind, etc.)

  • kubectl configured

  • A CNI that supports NetworkPolicies (e.g., Calico, Cilium, or Weave)

Test for a suitable CNI

kubectl get pods -n kube-system -o wide | grep -E 'calico|cilium|weave|flannel'

Note: The Kubernetes inside Docker Desktop does not enforce Network Policies!


๐Ÿ”น Lab 1: Set Up Test Environment in Current Namespace

Step 1: Create two deployments

โœ… Two pods: client and nginx.

Step 2: Expose nginx as a service

โœ… Service: nginx-service.


๐Ÿ”น Lab 2: Verify Open Communication

โœ… Should return the nginx default HTML page.


๐Ÿ”น Lab 3: Apply a Default-Deny Policy

โœ… All ingress traffic is now blocked in the current namespace.


๐Ÿ”น Lab 4: Allow Traffic to Nginx Only from Client Pod

โœ… Only client can now reach nginx.


๐Ÿ”น Lab 5: Test Access Again

โœ… Should work.

Test from another pod:

โŒ Should fail due to policy.


๐Ÿ”น Lab 6: Clean Up


โœ… Wrap-Up

  • โœ… Created a default-deny NetworkPolicy

  • โœ… Allowed access to a pod from a specific source

  • โœ… Verified restricted and allowed traffic

  • โœ… Practiced Kubernetes network security in the default namespace


Last updated