This is doable with the ctr
tool instead of kubectl on a modern kubernetes cluster (2024+) that uses containerd. You will need to install ctr
with apt/yum etc.
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