How to login/enter in kubernetes pod

Viewed 17993

I have kubernetes pods running as shown in command "kubectl get all -A" :

enter image description here

and same pods are shown in command "kubectl get pod -A" : enter image description here

I want to enter/login to any of these pod (all are in Running state). How can I do that please let me know the command?

2 Answers

Kubernetes Pods are not Virtual Machines, so not something you typically can "log in" to.

But you might be able to execute a command in a container. e.g. with:

kubectl exec <pod-name> -- <command>

Note that your container need to contain the binary for <command>, otherwise this will fail.

See also Getting a shell to a container.

In addition to Jonas' answer above; If you have more than one namespace, you need to specify the namespace your pod is currently using i.e kubectl exec -n <name space here> <pod-name> -it -- /bin/sh

After successfully accessing your pod, you can go ahead and navigate through your container.

Related