Sobes.tech
Senior

How to check network connectivity between pods in Kubernetes if the application receives a connection timeout?

sobes.tech AI

Answer from AI

To check network connectivity between pods in Kubernetes when encountering a connection timeout, you can follow these steps:

  1. Check DNS and addressing:

    • Ensure that pods can resolve each other's names (if DNS is used).
  2. Use kubectl exec to verify from inside the pod:

    • Access the source pod:
      kubectl exec -it <source-pod> -- /bin/sh
      
    • Try pinging the IP or hostname of the target pod:
      ping <target-pod-ip>
      
    • Check port accessibility with curl or nc (netcat):
      nc -zv <target-pod-ip> <port>
      
  3. Check NetworkPolicy:

    • Ensure that network policies do not block traffic between pods.
  4. Check CNI plugin settings:

    • Sometimes issues are related to the network plugin (Calico, Flannel, etc.).
  5. View pod logs and Kubernetes events:

    • kubectl logs <pod>
    • kubectl describe pod <pod>
  6. Check routes and iptables rules on nodes:

    • For diagnostics at the host level.

Thus, a sequential check from the application layer to the network and infrastructure can help identify the cause of the timeout.