Executing commands inside a Kubernetes Pod
In a normal situation, we do not need to log in to a Pod or container, as the application is exposed on some ports and Services are talking over these exposed ports. However, when there are issues, we need to access the containers and check what is happening inside, by checking logs, accessing other Pods, or running any necessary troubleshooting commands.
Use the kubectl exec
command if you are doing this troubleshooting or information gathering manually:
Figure 11.36 – Execute commands inside a Pod using the kubectl utility
However, when we automate Kubernetes operations using Ansible, use the k8s_exec
module and automate the verification tasks or validation tasks as well.
For such scenarios, we can deploy debug Pods using suitable images (for example, images with required utilities, such as ping
, curl
, or netstat
) and execute validation commands from these Pods. A typical deployment scenario with test...