Pod Connectivity (CNI, DNS)
Pod connectivity in Kubernetes involves how pods get network addresses, communicate with each other, and discover services. This is handled by two key components: the Container Network Interface (CNI) for network setup and CoreDNS for service discovery. Understanding pod connectivity is essential for troubleshooting networking issues and designing network architectures.
How Pods Connect
When a pod is created, several things happen to enable network connectivity:
- CNI Plugin - Assigns IP address and configures networking
- Network Namespace - Pod gets isolated network namespace
- DNS Configuration - Pod is configured to use CoreDNS
- Service Discovery - Pod can discover Services via DNS
CNI (Container Network Interface)
CNI is the standard interface between Kubernetes and network plugins. When a pod is created:
- kubelet calls CNI plugin - Requests network setup
- CNI plugin assigns IP - From configured IP pool
- CNI plugin configures network - Sets up routes, bridges, etc.
- Pod gets network connectivity - Can communicate with other pods
DNS Integration
Kubernetes automatically configures pods to use CoreDNS for DNS resolution:
- Service discovery - Pods can find Services by DNS name
- Automatic configuration - DNS is configured in every pod
- Namespace-aware - DNS resolution is namespace-aware
Network Namespaces
Each pod gets its own network namespace, providing network isolation:
- Isolated network stack - Pod has its own network interfaces
- Independent routing - Pod has its own routing table
- Isolated from host - Pod network is separate from node network
Pod-to-Pod Communication
Pods communicate with each other using their assigned IP addresses:
Same Node
Pods on the same node communicate via the node’s network bridge:
Different Nodes
Pods on different nodes communicate via the cluster network:
Service Discovery
Pods discover Services via DNS:
DNS Names
- Short name:
my-service(same namespace) - FQDN:
my-service.default.svc.cluster.local - Cross-namespace:
my-service.production.svc.cluster.local
DNS Resolution Flow
Network Policies Impact
Network Policies can restrict pod connectivity:
- Ingress rules - Control incoming traffic
- Egress rules - Control outgoing traffic
- CNI enforcement - Policies enforced by CNI plugin
Common Connectivity Scenarios
Pod to Service
Pod to Pod (Direct)
Pod to External
Troubleshooting Connectivity
Pod Cannot Reach Service
- Check Service exists:
kubectl get service <name> - Verify DNS resolution:
kubectl run -it --rm debug --image=busybox --restart=Never -- nslookup <service-name> - Check Endpoints:
kubectl get endpoints <service-name> - Test Service directly:
kubectl port-forward service/<name> <port> - Check Network Policies:
kubectl get networkpolicies
Pod Cannot Reach Other Pods
- Check pod IPs:
kubectl get pods -o wide - Test connectivity:
kubectl exec <pod> -- ping <other-pod-ip> - Check Network Policies: Verify policies allow communication
- Check CNI plugin: Ensure CNI plugin is working
- Review node network: Check node network configuration
DNS Not Working
- Check CoreDNS:
kubectl get pods -n kube-system -l k8s-app=kube-dns - Test DNS:
kubectl run -it --rm debug --image=busybox --restart=Never -- nslookup kubernetes.default - Check DNS config:
kubectl get configmap coredns -n kube-system -o yaml - Verify Network Policies: Ensure DNS egress is allowed
- Check CoreDNS logs:
kubectl logs -n kube-system -l k8s-app=kube-dns
Best Practices
- Use Services for discovery - Don’t rely on pod IPs directly
- Use DNS names - Use Service DNS names instead of IPs
- Test connectivity - Regularly test pod-to-pod and pod-to-service connectivity
- Monitor DNS - Monitor CoreDNS health and performance
- Document network architecture - Document how pods connect
- Use Network Policies - Implement network isolation
- Choose CNI wisely - Select CNI plugin that meets your needs
- Plan IP ranges - Plan pod and service IP ranges carefully
- Monitor network performance - Track network latency and throughput
- Keep CNI updated - Keep CNI plugin updated
Topics
- CNI Basics - Understanding Container Network Interface
- DNS & CoreDNS - Service discovery via DNS
See Also
- Services - How Services enable pod discovery
- Network Policies - Network isolation
- CNI Plugins - Available CNI plugins