background
I want to execute a command (eg. ip a) in the pod, but there is no ip command in the pod, what should I do?
Implementation process
First check the pod information
Enter the pod, execute ip a, and find that there is no ip command in the container,
but what should we do if we want to execute this command?
Advance into the pod, execute lsns -t net, and get the ns where the container is located
Then go to the host where the container is located, execute lsns ns id, you can get the pid of the container
Enter the ns directly on the host, so that you can execute the command you want to execute in the ns of the container on the host
nsenter -n -t 47108 ip addr
It can also be executed like this
You're done~
lsns [参数]
常用参数:
-J 使用 JSON 输出格式
-l 使用列表格式的输出
-n 不打印标题
-r 使用原生输出格式
-u 不截断列中的文本
-t 名字空间类型(mnt, net, ipc, user, pid, uts, cgroup)