Search code examples
linuxkubernetes

How to enter a pod as root?


Currently I enter the pod as a mysql user using the command:

kubectl exec -it PODNAME -n NAMESPACE bash

I want to enter a container as root. I've tried the following command:

kubectl exec -it PODNAME -n NAMESPACE -u root ID /bin/bash

kubectl exec -it PODNAME -n NAMESPACE -u root ID bash

There must be a way. :-)


Solution

  • I found the answer.

    You cannot log into the pod directly as root via kubectl.

    You can do via the following steps.

    1. find out what node it is running on kubectl get pod -n [NAMESPACE] -o wide

    2. ssh node

    3. find the docker container sudo docker ps | grep [namespace]

    4. log into container as root sudo docker exec -it -u root [DOCKER ID] /bin/bash