Lab 01 β Configure Kubernetes Network Policies
Mission Information
Section titled βMission Informationβ| Item | Details |
|---|---|
| Lab ID | K8S-NET-LAB-01 |
| Difficulty | Intermediate |
| Estimated Time | 2β3 Hours |
| Environment | Kubernetes Cluster (Amazon EKS / Azure AKS / Google GKE / kind) |
| Platform | Kubernetes |
| Cost | Free (kind) / Cloud Charges Apply |
| Primary Role | Kubernetes Security Engineer |
| Module | Module 03 β Kubernetes Network Security & Zero Trust |
| Previous Module | Module 02 β Kubernetes Identity & Access Management |
Mission Scenario
Section titled βMission ScenarioβCloudNova Technologies operates a production Kubernetes platform hosting multiple business-critical applications, including:
- Customer Portal
- Inventory API
- Payment Service
- PostgreSQL Database
- Monitoring Platform
A recent penetration test discovered that every Pod could communicate with every other Pod, regardless of application, namespace, or business function. This unrestricted communication creates opportunities for attackers to move laterally through the environment if a single workload is compromised.
The Chief Information Security Officer (CISO) has mandated the implementation of Zero Trust networking using Kubernetes Network Policies.
As the Kubernetes Security Engineer, your mission is to redesign network communication so that workloads can communicate only when explicitly authorised.
Learning Objectives
Section titled βLearning ObjectivesβBy completing this lab, you will learn how to:
- Understand Kubernetes Network Policies
- Implement Zero Trust networking
- Configure default deny policies
- Allow authorised Pod-to-Pod communication
- Restrict east-west traffic
- Secure namespaces
- Configure ingress rules
- Configure egress rules
- Test network segmentation
- Validate policy enforcement
- Perform an enterprise network security assessment
Enterprise Architecture
Section titled βEnterprise Architectureβ CloudNova Kubernetes Cluster
Kubernetes Network
ββββββββββββββββββββββββββββββββββββββ β β β Customer Namespace β β β β Frontend Pod ββββΊ API Pod β β β β ββββββββββββββββββββββββββββββββββββββ β Allowed Communication β βΌ ββββββββββββββββββββββββββββββββββββββ β β β Database Namespace β β β β PostgreSQL Pod β β β ββββββββββββββββββββββββββββββββββββββ
Any other communication:
β DeniedLab Outcomes
Section titled βLab OutcomesβBy the end of this lab, you will have:
- Created multiple namespaces
- Deployed sample applications
- Implemented default deny policies
- Allowed authorised application traffic
- Restricted unauthorised communication
- Validated east-west segmentation
- Tested ingress and egress controls
- Produced an enterprise network security assessment
Prerequisites
Section titled βPrerequisitesβBefore starting:
- Complete Module 01
- Complete Module 02
- kubectl installed
- Kubernetes cluster running
- Basic understanding of Pods and Services
Tools Used
Section titled βTools Usedβ| Tool | Purpose |
|---|---|
| kubectl | Kubernetes administration |
| Docker Desktop | Local runtime |
| kind | Local Kubernetes |
| Visual Studio Code | YAML editing |
| Git Bash / PowerShell | Command execution |
Enterprise Background
Section titled βEnterprise BackgroundβBy default, Kubernetes allows all Pods to communicate with one another.
This model provides excellent flexibility but introduces significant security risks.
Without Network Policies:
- Malware can spread laterally.
- Internal APIs become accessible to every workload.
- Databases are exposed unnecessarily.
- Compromised containers can attack other applications.
- Zero Trust principles cannot be enforced.
Network Policies provide firewall-like controls at the Pod level by defining which traffic is permitted.
Zero Trust Networking Principle
Section titled βZero Trust Networking PrincipleβTraditional Networking
Everything is trusted
Application A ββββββββββΊ Application B
Application B ββββββββββΊ Database
Everything allowed
Zero Trust Networking
Application A ββββββΊ API
API ββββββββββββββββΊ Database
Everything else
DENIEDTask 01 β Verify Cluster Health
Section titled βTask 01 β Verify Cluster HealthβConfirm cluster connectivity.
kubectl cluster-info
kubectl get nodesVerify:
- Cluster accessible
- Nodes Ready
Task 02 β Create Enterprise Namespaces
Section titled βTask 02 β Create Enterprise NamespacesβCreate three namespaces.
kubectl create namespace frontend
kubectl create namespace backend
kubectl create namespace databaseVerify:
kubectl get namespacesTask 03 β Deploy Sample Applications
Section titled βTask 03 β Deploy Sample ApplicationsβDeploy:
Frontend
nginxBackend
httpdDatabase
postgresDeploy one Pod into each namespace.
Verify:
kubectl get pods -ATask 04 β Test Default Communication
Section titled βTask 04 β Test Default CommunicationβFrom the frontend Pod:
kubectl exec -it <frontend-pod> -n frontend -- /bin/shAttempt to communicate with backend.
wget http://backend-serviceAttempt to reach the database.
Observe:
Communication succeeds because no Network Policies exist.
Document findings.
Task 05 β Create a Default Deny Policy
Section titled βTask 05 β Create a Default Deny PolicyβCreate a Network Policy that blocks all ingress traffic.
Example:
apiVersion: networking.k8s.io/v1kind: NetworkPolicymetadata: name: default-denyspec: podSelector: {} policyTypes: - IngressApply:
kubectl apply -f default-deny.yamlTask 06 β Validate Policy Enforcement
Section titled βTask 06 β Validate Policy EnforcementβRepeat connectivity tests.
Expected:
Connection timed out
OR
Connection refusedDocument results.
Task 07 β Allow Frontend to Access Backend
Section titled βTask 07 β Allow Frontend to Access BackendβCreate a policy allowing:
Frontend
β
Backend
Example concepts:
- Namespace Selector
- Pod Selector
- Ingress Rule
Apply policy.
Verify communication.
Expected:
Frontend
β Backend
Database
β Blocked
Task 08 β Allow Backend to Access Database
Section titled βTask 08 β Allow Backend to Access DatabaseβCreate another Network Policy allowing:
Backend
β
Database
Validate:
Backend
β Database
Frontend
β Database
Task 09 β Configure Egress Restrictions
Section titled βTask 09 β Configure Egress RestrictionsβCreate an egress policy limiting outbound traffic.
Allow only:
- Kubernetes DNS
- Backend API
- Database
Everything else:
Denied.
Validate connectivity.
Task 10 β Review Network Policies
Section titled βTask 10 β Review Network PoliciesβList policies.
kubectl get networkpolicies -ADescribe policies.
kubectl describe networkpolicyReview:
- Pod selectors
- Namespace selectors
- Allowed ports
- Allowed protocols
Task 11 β Simulate a Security Incident
Section titled βTask 11 β Simulate a Security IncidentβScenario:
An attacker compromises the frontend application.
Attempt:
Frontend
β
Database
β
Monitoring
β
Other namespaces
Expected:
Blocked by Network Policies.
Discuss:
How Network Policies reduce lateral movement.
Task 12 β Review Traffic Flow
Section titled βTask 12 β Review Traffic FlowβComplete the matrix.
| Source | Destination | Result |
|---|---|---|
| Frontend | Backend | Allowed |
| Frontend | Database | Denied |
| Backend | Database | Allowed |
| Database | Frontend | Denied |
| Backend | Frontend | Denied |
| Random Namespace | Backend | Denied |
Task 13 β Enterprise Security Assessment
Section titled βTask 13 β Enterprise Security AssessmentβReview:
- Default deny implemented
- Namespace isolation
- East-west segmentation
- Egress restrictions
- Policy documentation
- Least privilege networking
Classify findings:
- Compliant
- Requires Improvement
- Non-Compliant
Task 14 β Produce an Assessment Report
Section titled βTask 14 β Produce an Assessment ReportβDocument:
Cluster:
Namespaces Reviewed:
Applications:
Policies Created:
Traffic Allowed:
Traffic Denied:
Security Findings:
Recommendations:
Overall Network Security Rating:Task 15 β Evidence Collection
Section titled βTask 15 β Evidence CollectionβCapture evidence for:
- Namespaces
- Pods
- Network Policies
- Connectivity tests
- Traffic matrix
- Security assessment
- Final report
Task 16 β Clean Up
Section titled βTask 16 β Clean UpβDelete test resources.
kubectl delete namespace frontend
kubectl delete namespace backend
kubectl delete namespace databaseVerify cleanup.
Skills Developed
Section titled βSkills DevelopedβBy completing this lab, you will be able to:
- Implement Kubernetes Network Policies
- Apply Zero Trust networking
- Restrict Pod-to-Pod communication
- Configure ingress rules
- Configure egress rules
- Secure namespaces
- Prevent lateral movement
- Validate network segmentation
- Review enterprise network security
- Troubleshoot policy enforcement
Knowledge Check
Section titled βKnowledge CheckβQuestion 1
Section titled βQuestion 1βWhat is the primary purpose of a Kubernetes Network Policy?
- A. Schedule Pods
- B. Control network traffic between Pods and namespaces
- C. Encrypt Kubernetes Secrets
- D. Create Services
Answer: B
Question 2
Section titled βQuestion 2βWhat happens if a default deny Network Policy is applied without any allow rules?
- A. All traffic is permitted.
- B. All selected ingress traffic is blocked until explicitly allowed.
- C. Pods are deleted automatically.
- D. DNS is permanently disabled.
Answer: B
Question 3
Section titled βQuestion 3βWhich security principle is implemented using Kubernetes Network Policies?
- A. High Availability
- B. Zero Trust Networking
- C. Autoscaling
- D. Infrastructure as Code
Answer: B
Question 4
Section titled βQuestion 4βWhich type of attack do Network Policies primarily help mitigate?
- A. SQL Injection
- B. Lateral movement between workloads
- C. Cross-Site Scripting (XSS)
- D. DNS spoofing
Answer: B
Question 5
Section titled βQuestion 5βWhich traffic should generally be allowed only when required?
- A. All Pod-to-Pod communication
- B. Only explicitly authorised application communication based on business requirements
- C. All outbound internet traffic
- D. All namespace-to-namespace traffic
Answer: B
Lab Summary
Section titled βLab SummaryβIn this lab, you implemented Kubernetes Network Policies to enforce Zero Trust networking within a Kubernetes cluster. You created namespace segmentation, applied default deny policies, configured explicit ingress and egress rules, and validated that only authorised application communication was permitted.
These controls significantly reduced the attack surface by preventing unauthorised east-west traffic and limiting lateral movement between workloads. The techniques practiced in this lab mirror the network segmentation strategies used by enterprise Platform Engineering and Cloud Security teams to secure production Kubernetes environments.
Whatβs Next?
Section titled βWhatβs Next?ββ‘οΈ **Lab 02 β Block Pod-to-Pod Communication
Learn how to prevent lateral movement inside Kubernetes by implementing default deny ingress and egress Network Policies, isolating workloads, and enforcing Zero Trust communication between Pods.