Exec as root user in Kubernetes

Hi πŸ‘‹, In this short tutorial I will show you a way of getting a root shell in containers running inside a modern Kubernetes cluster. Prerequisites: Root access to the cluster node in which the container is running. Problem Statement We wan’t root access into a running container, exec gives us non-root user. 1 2 3 4 5 6 7 8 9 10 ➜ Downloads k get pods NAME READY STATUS RESTARTS AGE my-release-cassandra-0 1/1 Running 0 2m9s ➜ Downloads k exec -it pod/my-release-cassandra-0 -- /bin/bash I have no name!@my-release-cassandra-0:/$ whoami whoami: cannot find name for user ID 1001 I have no name!@my-release-cassandra-0:/$ touch test touch: cannot touch 'test': Permission denied I have no name!@my-release-cassandra-0:/$ Solution To obtain root access. First grab the Container ID from inside the pod. ...

November 19, 2022 Β· 2 min Β· Denis NuΘ›iu