how to login as root to running pod as root in kubernetes

12/7/2021

I tried multiple syntax including one given below , no luck yet

kubectl exec  -u root -it testpod -- bash
Error: unknown shorthand flag: 'u' in -u
See 'kubectl exec --help' for usage.

it is version 1.22

-- Krish Singh
kubernetes

1 Answer

12/8/2021
  • There is no option available in kubectl exec to mention the user
  • Because it is decided at either in the container image or in the pod.spec.containers.securityContext.runAsUser field
  • so to achieve what youy want is on a running container then do just kubectl exec -it testpod -- bash and then issue su - root from inside the container
-- confused genius
Source: StackOverflow