How to switch roles in container in k8s

    At work, you need to debug the container in k8s, but there may be many things in the container that are missing, such as vim, etc. If you don't have it, you can't modify the code. If you want to use su to change to the root user without knowing the password. The following methods can be used.

    Modify pod yaml file directly

containers:
  - name: ...
    image: ...
    securityContext:
      runAsUser: 0

So logging in is the root role, and 0 refers to the uid of the root user . Inside, you can install the tools you want to install for debugging.

For example, I installed vim after going in for debugging

apt update
apt install vim

 

Guess you like

Origin blog.csdn.net/banfushen007/article/details/111469990