Configuring Kubernetes Network Policies for pod-to-pod communication means defining rules that control traffic flow between pods. Network Policies are a Kubernetes resource that secures your cluster by limiting communication based on labels, namespaces, and IP blocks. Here’s a step-by-step guide:
1. Prerequisites
- Network plugin: Ensure your cluster uses a CNI plugin that supports Network Policies — Calico, Cilium, Weave Net, or Kube-router, for example. Network Policies require a supported CNI.
- Pod labels: Label your pods appropriately; Network Policies match based on labels.
2. Understand the Default Behavior
- By default, Kubernetes allows all communication between pods.
- Once you apply a NetworkPolicy to a set of pods (via
podSelector), it denies all traffic to and from those pods unless the policy explicitly allows it.
3. Create a NetworkPolicy Resource
Network Policies are defined as YAML manifests. Here’s an example that allows traffic from specific pods:
Example: Allow traffic from specific pods
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-specific-pod-communication
namespace: default
spec:
podSelector:
matchLabels:
app: backend
policyTypes:
- Ingress
ingress:
- from:
- podSelector:
matchLabels:
app: frontend
Explanation:
podSelector: Specifies the pods the policy applies to — here, pods labeledapp: backend.policyTypes: Defines the traffic direction (Ingressfor incoming,Egressfor outgoing).ingress: Defines allowed incoming traffic sources. In this case, only pods labeledapp: frontendcan talk toapp: backend.
4. Apply the NetworkPolicy
Use kubectl to apply the manifest:
kubectl apply -f allow-specific-pod-communication.yaml
5. Verify the NetworkPolicy
Confirm the policy exists and shows the expected rules:
kubectl describe networkpolicy allow-specific-pod-communication
Then test pod-to-pod connectivity from inside the pods using curl, wget, or ping.
6. Advanced Configuration
You can handle more complex scenarios:
Namespace-based policies
Allow traffic between pods in different namespaces:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-namespace-communication
namespace: default
spec:
podSelector:
matchLabels:
app: backend
policyTypes:
- Ingress
ingress:
- from:
- namespaceSelector:
matchLabels:
team: dev
IP Block-based policies
Allow traffic from specific CIDR ranges:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-ip-range
namespace: default
spec:
podSelector:
matchLabels:
app: backend
policyTypes:
- Ingress
ingress:
- from:
- ipBlock:
cidr: 192.168.1.0/24
7. Debugging Tips
- Verify pod labels match the
podSelectorin your policy. - Confirm the CNI plugin is installed and supports Network Policies.
- Use
kubectl logsorkubectl execto troubleshoot connectivity between pods.
8. Best Practices
- Start with restrictive policies and open only what’s necessary.
- Use labels consistently to categorize and identify pods.
- Audit NetworkPolicies regularly for security and compliance.

Ali YAZICI is a Senior IT Infrastructure Manager with 15+ years of enterprise experience. While a recognized expert in datacenter architecture, multi-cloud environments, storage, and advanced data protection and Commvault automation , his current focus is on next-generation datacenter technologies, including NVIDIA GPU architecture, high-performance server virtualization, and implementing AI-driven tools. He shares his practical, hands-on experience and combination of his personal field notes and “Expert-Driven AI.” he use AI tools as an assistant to structure drafts, which he then heavily edit, fact-check, and infuse with my own practical experience, original screenshots , and “in-the-trenches” insights that only a human expert can provide.
If you found this content valuable, [support this ad-free work with a coffee]. Connect with him on [LinkedIn].



