crictl 命令
清理无用的镜像
# crictl images | grep none | awk '{print $3} '| xargs crictl rmi
获取 pod的IP地址
crictl ps --name $p_name -o yaml | grep " podSandboxId: " | awk '{print $2}'
crictl inspect $pod_id
crictl 不支持导入和导出镜像
https://kubernetes.io/docs/tasks/debug/debug-cluster/crictl/
crictl 默认连接到 unix:///var/run/dockershim.sock
# 通过设置参数 --runtime-endpoint 和 --image-endpoint
# 通过设置环境变量 CONTAINER_RUNTIME_ENDPOINT 和 IMAGE_SERVICE_ENDPOINT
# 通过在配置文件中设置端点 --config=/etc/crictl.yaml
你还可以在连接到服务器并启用或禁用调试时指定超时值,方法是在配置文件中指定 timeout 或 debug 值,或者使用 --timeout 和 --debug 命令行参数。
要查看或编辑当前配置,请查看或编辑 /etc/crictl.yaml 的内容。
# cat /etc/crictl.yaml
runtime-endpoint: unix:///var/run/dockershim.sock
image-endpoint: unix:///var/run/dockershim.sock
timeout: 10
打印所有 Pod 的清单
# crictl pods
根据名称打印 Pod 清单
# crictl pods --name nginx-65899c769f-wv2gp
根据标签打印 Pod 清单
# crictl pods --label run=nginx
打印所有镜像清单
# crictl images
根据仓库打印镜像清单
# crictl images nginx
只打印镜像 ID
# crictl images -q
打印所有容器清单
# crictl ps -a
打印正在运行的容器清单
# crictl ps
在正在运行的容器上执行命令
# crictl exec -i -t 1f73f2d81bf98 ls
# crictl exec -i -t 1f73f2d81bf98 bash
获取容器的所有日志
# crictl logs 87d3992f84f74
获取最近的 N 行日志
# crictl logs --tail=10 87d3992f84f74