20

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?

David Maze
  • 130,717
  • 29
  • 175
  • 215
solveit
  • 869
  • 2
  • 12
  • 32
  • you cannot login to a pod. it is not a process. it is a kind of 'environment'. it doesn't have port numbers. only IP. but as mentioned by others, you can exec binaries present on the node, which run as a container. – Apurva Singh Dec 23 '22 at 21:20

2 Answers2

17

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.

Umar Kayondo
  • 405
  • 4
  • 9
15

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.

Jonas
  • 121,568
  • 97
  • 310
  • 388