Just in case you come across to look for an answer for minikube, the minikube ssh command can actually work with docker command together here, which makes it fairly easy:
Find the container ID:
$ minikube ssh docker container ls
Add the -u 0 option to docker command (quote is necessary for the whole docker command):
NOTE: this is NOT for Kubernetes in general, it works for minikube only. While I feel we need the root access quit a lot in local development environment, it's worth to mention it in this thread.
To login as different i use exec-as plugin in kubernetes here are the steps you can follow
Make sure git is installed
Step : 1 Install Krew plugin
begin
set -x; set temp_dir (mktemp -d); cd "$temp_dir" &&
set OS (uname | tr '[:upper:]' '[:lower:]') &&
set ARCH (uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/') &&
set KREW krew-$OS"_"$ARCH &&
curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/$KREW.tar.gz" &&
tar zxvf $KREW.tar.gz &&
./$KREW install krew &&
set -e KREW; set -e temp_dir
end
WARNING: You installed plugin "prompt" from the krew-index plugin repository.
These plugins are not audited for security by the Krew maintainers.
Run them at your own risk.
That's all well and good, but what about new versions of kubernetes that use containerd?
using nerdctl exec -uroot -ti 817d52766254 sh
there is no full-fledged root, part of the system in this read-only mode