Execute Kubernetes Pod Shell Command as Root user

0
14721
Execute Kubernetes Pod Shell Command as Root user
Execute Kubernetes Pod Shell Command as Root user

Usually for security reasons, you will run container image as a regular user, non-superuser. However, sometimes, you want to test or debug something on the go, it requires superuser permission. I will show you how to execute Kubernetes pod shell command as root user.

Execute Kubernetes Pod Shell Command as Root user

As you know, once the pod is running with user privilege, such as nobody, you cannot change into or acquire superuser in anyway.

To do that in Kubernetes, we will need to use krew to install a cool plugin, exec-as, which helps to access the pod as root user.

First, follow the guide on krew homepage to install the plugin manager.

Then issue following commands to install the plugin:

$ kubectl krew install exec-as
$ kubectl krew install prompt

Once it’s done, you can access any pod with root user via following command:

$ kubectl exec-as -u root pod-69bfb5ffc7-kc2bs

Beside root user, it can be used to access as different users as long as user id is registered into container image.

Also, so that’s all about the tip to execute Kubernetes pod shell command as root user

Have fun ~