在使用crictl ps查看pod中container的时候报错如下,主要是因为container runtime是containerd,可以通过设置runtime-endpoint来解决错误
root@k8sdbaworker1:/etc/containerd# 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.
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.
E0909 06:50:47.877415 1609259 remote_runtime.go:390] "ListContainers with filter from runtime service failed" err="rpc error: code = Unavailable desc = connection error: desc = \"transport: Error while dialing dial unix /var/run/dockershim.sock: connect: no such file or directory\"" filter="&ContainerFilter{Id:,State:&ContainerStateValue{State:CONTAINER_RUNNING,},PodSandboxId:,LabelSelector:map[string]string{},}"
FATA[0000] listing containers: rpc error: code = Unavailable desc = connection error: desc = "transport: Error while dialing dial unix /var/run/dockershim.sock: connect: no such file or directory"
root@k8sdbaworker1:/etc/containerd# crictl config runtime-endpoint unix:///run/containerd/containerd.sock
root@k8sdbaworker1:/etc/containerd# crictl config image-endpoint unix:///run/containerd/containerd.sock
root@k8sdbaworker1:/etc/containerd# crictl ps
CONTAINER IMAGE CREATED STATE NAME ATTEMPT POD ID POD
40fb4b5a86e85 a416a98b71e22 36 minutes ago Running demo2 1 0251ae2f8e542 demo
e5a5b50a8b02b a416a98b71e22 36 minutes ago Running demo 1 0251ae2f8e542 demo
8098783d7b6cf 08616d26b8e74 3 weeks ago Running calico-node 0 209c855a54f4a calico-node-mvmdj
d825ff3e982db ea1030da44aa1 3 weeks ago Running kube-proxy 0 8ec1d67cff036 kube-proxy-lkfhn
root@k8sdbaworker1:/etc/containerd# cat /etc/crictl.yaml
常用命令
显示当前有哪些pod
root@k8sdbamaster:~# crictl pods
显示具体pod的信息
root@k8sdbaworker1:/etc/containerd# crictl pods --name demo
POD ID CREATED STATE NAME NAMESPACE ATTEMPT RUNTIME
0251ae2f8e542 2 hours ago Ready demo nsvolume 0 (default)
打印容器清单
root@k8sdbaworker1:/etc/containerd# crictl ps
CONTAINER IMAGE CREATED STATE NAME ATTEMPT POD ID POD
40fb4b5a86e85 a416a98b71e22 52 minutes ago Running demo2 1 0251ae2f8e542 demo
e5a5b50a8b02b a416a98b71e22 52 minutes ago Running demo 1 0251ae2f8e542 demo
8098783d7b6cf 08616d26b8e74 3 weeks ago Running calico-node 0 209c855a54f4a calico-node-mvmdj
d825ff3e982db ea1030da44aa1 3 weeks ago Running kube-proxy 0 8ec1d67cff036 kube-proxy-lkfhn
查看容器详细信息
root@k8sdbaworker1:/etc/containerd# crictl inspect 40fb4b5a86e85