List of Commands troubleshoot networking in Kubernetes

Troubleshooting networking in Kubernetes can sometimes be complex due to the distributed nature of containerized applications. Below is a list of commands with explanations to help troubleshoot networking issues in a Kubernetes cluster:

  1. kubectl get pods:
    • This command lists all the pods running in your cluster. It’s a good starting point to check if your pods are in a running state.
  2. kubectl describe pod <pod-name>:
    • Use this command to get detailed information about a specific pod, including its networking configuration, IP addresses, and events.
  3. kubectl get svc:
    • List all services in the cluster. This helps you verify that your services are correctly configured and running.
  4. kubectl describe svc <service-name>:
    • Get detailed information about a specific service, including its endpoints and selectors.
  5. kubectl exec -it <pod-name> — /bin/sh:
    • This command allows you to open a shell inside a container within a pod. You can use it to debug networking from within the container.
  6. kubectl logs <pod-name>:
    • Retrieve the logs from a specific pod to check for any network-related error messages or issues.
  7. kubectl port-forward <pod-name> <local-port>:<remote-port>:
    • Forward network traffic from your local machine to a specific pod’s port. This can be helpful for testing network connectivity to a pod.
  8. kubectl run -it –rm busybox –image=busybox — sh:
    • Launch a temporary BusyBox container for network troubleshooting. This is useful for running networking diagnostic commands like ping, nslookup, or curl.
  9. kubectl get endpoints <service-name>:
    • Check the endpoints associated with a service. Ensure that the endpoints are correctly pointing to the desired pods.
  10. kubectl get networkpolicies:
    • List network policies in your cluster. Ensure that network policies are not inadvertently blocking traffic between pods.
  11. kubectl get nodes -o wide:
    • Check the node IP addresses to verify the node where a particular pod is scheduled. This can help identify if pods are running on the expected nodes.
  12. kubectl describe node <node-name>:
    • Get detailed information about a specific node, including its networking configuration and allocated resources.
  13. kubectl get configmap kube-proxy -n kube-system -o yaml:
    • Inspect the kube-proxy configuration to ensure that it is correctly set up and functioning. Misconfigurations here can lead to network issues.
  14. kubectl get serviceaccount <service-account-name> -o yaml:
    • Check the service account’s configuration, especially if your pods need specific permissions for network-related operations.
  15. kubectl get events -n <namespace>:
    • View events related to a specific namespace. Look for any network-related events or errors that might provide clues to the issue.
  16. kubectl logs -n kube-system -l k8s-app=kube-dns:
    • Check the logs of the Kubernetes DNS (kube-dns or CoreDNS) service. DNS resolution issues can often lead to networking problems.
  17. kubectl apply -f <network-policy-file.yaml>:
    • If you suspect network policies are causing issues, apply a diagnostic network policy that allows all traffic for testing purposes. Be cautious when using this in a production environment.
  • kubectl get pods: This command will list all of the pods in your Kubernetes cluster. You can use this command to check the status of your pods and to identify any pods that are not running.
  • kubectl get services: This command will list all of the services in your Kubernetes cluster. You can use this command to check the status of your services and to identify any services that are not working.
  • kubectl describe pod <pod-name>: This command will display detailed information about the specified pod. You can use this command to troubleshoot problems with your pods, such as networking problems.
  • kubectl describe service <service-name>: This command will display detailed information about the specified service. You can use this command to troubleshoot problems with your services, such as networking problems.
  • kubectl exec <pod-name> — ping <endpoint-ip>: This command will ping the specified endpoint from inside the specified pod. You can use this command to test network connectivity between your pods and your endpoints.
  • kubectl logs <pod-name>: This command will display the logs for the specified pod. You can use this command to look for errors in your pod logs that may be causing networking problems.
  • tcpdump -i any host <pod-ip>: This command will capture all TCP/IP traffic to and from the specified pod. You can use this command to analyze network traffic to identify problems with your pod’s network connectivity.

Here are some additional tips for troubleshooting networking in Kubernetes:

  • Check your Kubernetes cluster’s network configuration: Make sure that your Kubernetes cluster is configured correctly for networking. You can check your Kubernetes cluster’s network configuration by running the following command:
kubectl get configmap -n kube-system kube-proxy-config -o yaml
  • Check your Kubernetes cluster’s network connectivity: Make sure that your Kubernetes cluster has network connectivity to the internet and to your other Kubernetes resources. You can check your Kubernetes cluster’s network connectivity by running the following command:

kubectl exec -it kube-proxy-$(kubectl get pods -n kube-system -l k8s-app=kube-proxy -o jsonpath='{.items[0].metadata.name}’) — ping 8.8.8.8

  • Check your Kubernetes cluster’s services: Make sure that your Kubernetes cluster’s services are configured correctly. You can check your Kubernetes cluster’s services by running the following command:
kubectl get services
  • Check your Kubernetes cluster’s pods: Make sure that your Kubernetes cluster’s pods are running and that they have network connectivity. You can check your Kubernetes cluster’s pods by running the following command:
kubectl get pods

$ kubectl get pod -o wide

$ kubectl get pod -o wide --all-namespaces

$ kubectl get service --all-namespaces

$ docker inspect --format '{{ .State.Pid }}' container-id-or-name

$ sudo nsenter -t container-pid -n ip addr

$ sudo nsenter -t container-pid -n ip addr

$ ip addr

$ iptables-save

$ sudo iptables -t nat -L KUBE-SERVICES

$ sudo apt install ipvsadm

$ sudo ipvsadm -Ln

$ ipvsadm -Ln -t 10.244.1.255

$ sudo apt install dnsutils

$ kubectl get service -n kube-system kube-dns

$ sudo nsenter -t 27168 -n dig kubernetes.default.svc.cluster.local @10.96.0.10

$ sudo conntrack -L

$ sudo conntrack -E

$ sudo conntrack -L -d 80.45.6.4

$ sysctl net.netfilter.nf_conntrack_max

$ sudo ipvsadm -Ln

$ sudo sysctl -w net.netfilter.nf_conntrack_max=231074

Rajesh Kumar
Follow me
Latest posts by Rajesh Kumar (see all)
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x