Kubernetes Pods are not Virtual Machines, so you can't typically "log in" to them.
However, you can execute a command in a container using the following syntax:
kubectl exec <pod-name> -- <command>
Make sure the container contains the binary for <command>
, otherwise the command will fail.
For more information, refer to the Kubernetes documentation on Getting a shell to a container.
Additional Notes:
- If you have multiple namespaces, specify the namespace where your pod is located, like this:
- Once you've accessed the pod, you can navigate through the container.
kubectl exec -n <namespace name> <pod-name> -it -- /bin/sh
To directly access the container inside a pod, use this command:
kubectl exec -it < your pod name> -- /bin/bash