Kubernetes network debugging pod
Recently I ran into an issue where we had to do some tests on the network communication between pods and from a pod to a resource outside the Kubernetes cluster.
When dealing with Kubernetes and networking, it can be difficult to diagnose a pod or the network within the cluster. Sometimes, you’re using a base image with root access disabled – as it should – which is common when deploying a Helm chart. This can make it difficult, during the development phase, to get enough information about what is going on inside your deployment.
kubectl run my-pod --rm -i -tty --image debian -- bash
YAMLLet’s break down what is happening here in this command.
kubectl
run Create and run a particular image in a pod.my-pod
will be the name of the pod we run.--rm
deletes the pod after it exits. In this case, when you disconnect from it.-i
starts an interactive shell, so you can type your commands.-tty
teleprompter command, to pass commands from stdin to the shell-- image debian
the image we want to start up. In this example, a simple debian image.-- bash
is sending the bash command through -tty to the interactie shell to open a bash prompt upon login
The combination of flags, allows you to run a shell in a pod, that cleans itself up when you exit the shell. Since we use a standard Debian base image, you will log in as root user and you can setup all the tools you will need.