获取进程或者容器ID
根据 容器 id 获取进程1
crictl inspect -o go-template --template='{{index .info "pid"}}' ef80e5fd299001c62a1b039797c74cb9cac8bfc88488edd576ea64396c6b93ba
根据进程获取容器信息1
2
3ContainerID=`cat /proc/34056/cgroup | awk -F '/' '{print $NF}' | sed 's/cri-containerd-\(.*\).scope/\1/' |uniq`
podName=crictl inspect -o go-template --template='{{index .status.labels "io.kubernetes.pod.name"}}' $ContainerID
# crictl inspect $ContainerID # 查看容器信息
nsenter 使用
默认都有安装 yum install util-linux -y 自行安装
1 | nsenter --help |
eg: 进入容器的网路空间 pause 容器会共享网络等资源,进入 pause 一样的
1 | [root@test-61 ~]# ps -ef |grep pause |
nsenter -t $PID -m -u -i -n -p /bin/sh 相当于 docker exec -it $container /bin/sh