With a modern (2024+) Kubernetes cluster that is using containerd as the container platform, you can do this with ctr
tool.
First locate the container ID in the list of containers:
ctr c ls
Then once you have the ID, login as root:
ctr -n k8s.io task exec --user 0 --exec-id 0 -t <container id> /bin/sh