kubens 是命名空间切换工具。
#查看当前所在的命名空间
[root@master ~]# kubens
切换命名空间
[root@master ~]# kubens nsvolume
Context "kubernetes-admin@kubernetes" modified.
Active namespace is "nsvolume".
#退出当前命名空间
[root@master ~]# kubens -
使用crictl ps查看当前node下的容器有哪些时报错如下
[root@worker2 ~]# crictl ps
WARN[0000] runtime connect using default endpoints: [unix:///var/run/dockershim.sock unix:///run/containerd/containerd.sock unix:///run/crio/crio.sock unix:///var/run/cri-dockerd.sock]. As the default settings are now deprecated, you should set the endpoint instead.
ERRO[0000] unable to determine runtime API version: rpc error: code = Unavailable desc = connection error: desc = "transport: Error while dialing dial unix /var/run/dockershim.sock: connect: no such file or directory"
WARN[0000] image connect using default endpoints: [unix:///var/run/dockershim.sock unix:///run/containerd/containerd.sock unix:///run/crio/crio.sock unix:///var/run/cri-dockerd.sock]. As the default settings are now deprecated, you should set the endpoint instead.
ERRO[0000] unable to determine image API version: rpc error: code = Unavailable desc = connection error: desc = "transport: Error while dialing dial unix /var/run/dockershim.sock: connect: no such file or directory"
主要原因是 crictl依次查找容器运行时,当查找第一个 `unix:///var/run/dockershim.sock` 没有找到,所以报错了,需要你手动指定当前kubernetes的容器运行时。
由于container runtime已经是containerd(可以通过kubectl get nodes -o wide查看container runtime),所以可以通过以下方式来修复:
crictl config runtime-endpoint unix:///var/run/containerd/containerd.sock
crictl config image-endpoint unix:///var/run/containerd/containerd.sock
运行以上命令之后会生成一个配置文件/etc/crictl.yaml