Network Policy

Network Policies in AWS EKS (Real-Time Example)

Scenario: In XYZ Corp, different teams work on multiple applications inside Kubernetes. They want to restrict communication between workloads using Network Policies.

Namespace
Workloads
Access Requirement

dev-team

Frontend, Backend

Frontend ↔ Backend only

qa-team

Test Apps, DB

No external access

security-team

Monitoring, Logging Apps

Read logs only


Step 1: Enable Network Policies on AWS EKS

πŸ”Ή AWS VPC CNI Plugin does not support Network Policies by default. πŸ”Ή Use Calico CNI for Network Policy Support.

kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml

βœ… Calico is now enabled!


Step 2: Restrict Traffic Between Namespaces

By default, all pods in Kubernetes can talk to each other.

Deny All Traffic in the Cluster (Default Policy)

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

βœ… Now, all pods in default namespace are isolated.


Step 3: Allow Only Frontend β†’ Backend Communication (Dev Team)

πŸ”Ή Frontend can talk to Backend, but not to DB.

βœ… Now, only Frontend can talk to Backend on port 8080.


Step 4: Block External Access to QA Apps

πŸ”Ή QA applications should not be accessed from outside.

βœ… Now, all pods in qa-team are blocked from external traffic.


Step 5: Allow Security Team to Monitor Logs

πŸ”Ή Security Team should access logs but not modify anything.

βœ… Only security-team namespace can access logs over port 9200.


Step 6: Test the Network Policies

πŸ”Ή Check if frontend can access backend:

βœ… Should work.

πŸ”Ή Check if frontend can access DB (which should fail):

❌ Should fail.

πŸ”Ή Check if external access to QA is blocked:

❌ Should fail.


Conclusion: Securing EKS with Network Policies

βœ” Pods are isolated unless allowed βœ” Frontend can talk to backend, but not to DB βœ” QA apps are protected from external access βœ” Security team can access logs, nothing else


πŸš€ NEXT: Do you want to implement AWS WAF for more security?

Last updated