- Deploy two NGINX apps (
app1&app2) - Verify default connectivity
- Enforce a default-deny posture
- Open selective ingress/egress rules
- Test DNS resolution and direct IP connectivity
Ensure you have a running Kubernetes cluster (v1.8+) with a CNI plugin that supports NetworkPolicies (e.g., Calico, Cilium).
1. Deploying Two Sample Applications
We’ll create two deployments and expose each via a ClusterIP service.1.1 app1 Deployment & Service (app1.deploy.yaml)
1.2 app2 Deployment & Service (app2.deploy.yaml)
2. Verifying Basic Connectivity
By default, all pods can talk to each other. From insideapp1, curl the app2 service:
app2 to app1 to confirm bi-directional access.
3. Applying a Default-Deny NetworkPolicy
Now enforce a zero-trust posture by blocking all ingress and egress in thedefault namespace.
This policy blocks all traffic, including DNS queries. Pods will no longer resolve service names or reach cluster DNS.
4. Allowing Traffic Between app1 and app2
We’ll create two policies to selectively permit pod-to-pod and DNS traffic.4.1 allow-app1 (allow-app1.networkpolicy.yaml)
4.2 allow-app2 (allow-app2.networkpolicy.yaml)
5. Testing Connectivity with NetworkPolicies
- Direct IP
- Service Name (DNS)
Links and References
By following this tutorial, you’ve implemented a default-deny network posture and selectively opened up pod-to-pod and DNS traffic between
app1 and app2. This approach helps you secure microservices communication with fine-grained policies.