GeekIt

crictl命令速查

端点配置、容器查看、日志与 exec、生命周期、镜像与沙箱、节点排障及与 kubectl 对照等 114 条命令

共 114 条命令 · 9 类场景 · 点击右侧图标可复制

命令说明复制
crictl -v查看 crictl 版本,需与运行时 CRI 版本大致匹配
crictl version查看客户端与运行时版本、运行时名称
crictl info查看运行时详细信息:类型、版本、配置与状态
crictl --runtime-endpoint unix:///run/containerd/containerd.sock ps临时指定 containerd 端点
crictl --runtime-endpoint unix:///var/run/crio/crio.sock psCRI-O 环境的默认端点
crictl --image-endpoint unix:///run/containerd/containerd.sock images单独指定镜像服务端点
cat /etc/crictl.yaml查看全局配置,端点写错是最常见的连接失败原因
crictl config --set runtime-endpoint=unix:///run/containerd/containerd.sock写入 /etc/crictl.yaml,免去每次带参数
crictl config --set image-endpoint=unix:///run/containerd/containerd.sock同时配置镜像端点
crictl --timeout 10s ps设置请求超时,运行时卡顿时避免长时间等待
crictl --debug ps打印 CRI 请求与响应,排查协议层问题
crictl completion bash > /etc/bash_completion.d/crictl开启命令补全,提高操作效率
ls -l /run/containerd/containerd.sock确认 socket 文件存在且权限允许访问
命令说明复制
crictl ps列出运行中的容器(含容器 ID、镜像、状态与所属 Pod)
crictl ps -a包含已退出的容器,排查崩溃必用
crictl ps --state exited只看已退出容器,快速定位异常退出
crictl ps -q只输出容器 ID,便于管道处理
crictl ps --name nginx按容器名过滤
crictl ps --label io.kubernetes.pod.name=my-pod按标签过滤,精确找到某个 Pod 的容器
crictl ps --pod <pod-id>按 Pod 沙箱 ID 过滤其下所有容器
crictl inspect <container-id>查看容器完整详情(JSON 格式)
crictl inspect -o yaml <container-id>以 YAML 输出,便于人工阅读
crictl inspect <container-id> | jq .status.state提取容器状态字段
crictl inspect <container-id> | jq .status.logPath查看容器日志文件实际路径
crictl stats查看所有容器 CPU、内存、网络与磁盘实时用量
crictl stats <container-id>只看单个容器资源占用
crictl stats -o jsonJSON 输出,便于采集与脚本分析
crictl ps -o json | jq ".containers[].metadata.name"提取全部容器名
命令说明复制
crictl logs <container-id>查看容器标准输出日志(kubelet 不可用时最直接)
crictl logs -f <container-id>持续跟踪日志输出
crictl logs --tail 100 <container-id>只看最后 100 行
crictl logs --since 10m <container-id>只看最近 10 分钟(也支持 RFC3339 时间戳)
crictl logs -t <container-id>输出时间戳,便于与其他日志对齐
crictl exec -it <container-id> /bin/sh进入容器交互式 shell
crictl exec -it <container-id> sh -c "ls -l /app"容器内执行单条命令
crictl exec <container-id> cat /etc/hosts快速查看容器内文件内容
crictl exec <container-id> env查看容器环境变量,排查配置注入问题
crictl exec <container-id> ip addr查看容器网络配置(镜像内需有 ip 命令)
crictl attach <container-id>附着到容器标准输入输出(与 exec 不同,不新起进程)
crictl port-forward <pod-id> 8080:80把 Pod 端口转发到本机,验证服务是否可用
crictl exec --sync <container-id> ls同步模式执行,避免输出被截断
命令说明复制
crictl stop <container-id>停止容器(默认宽限 0 秒,可加 -t 秒数)
crictl stop -t 30 <container-id>给 30 秒优雅退出时间
crictl start <container-id>启动已停止的容器
crictl rm <container-id>删除容器(需先停止)
crictl rm -f <container-id>强制删除,包括运行中的容器(谨慎)
crictl stopp <pod-id>停止 Pod 沙箱
crictl rmp <pod-id>删除 Pod 沙箱(需先停止)
crictl rmp -f <pod-id>强制删除 Pod 沙箱及其容器
crictl runp sandbox.json按配置创建 Pod 沙箱,手工模拟 kubelet 行为
crictl create <pod-id> container.json pod.json在指定沙箱内创建容器
crictl run container.json pod.json创建并启动容器的组合命令
crictl update --memory 512Mi <container-id>调整容器内存限制(部分运行时支持有限)
crictl status查看运行时状态摘要
命令说明复制
crictl images列出节点上的镜像(含 TAG、IMAGE ID 与大小)
crictl images -q只输出镜像 ID,便于批量清理
crictl images --digests显示 digest,核对镜像是否被意外覆盖
crictl pull nginx:1.25拉取镜像,验证仓库连通性最直接的方式
crictl pull --creds user:密码 registry.example.com/app:v1带认证拉取私有镜像
crictl inspecti nginx:1.25查看镜像详情与分层信息
crictl inspecti -o json registry.example.com/app:v1 | jq .status.repoDigests确认镜像实际 digest
crictl rmi <image-id>删除指定镜像
crictl rmi nginx:1.25按名称删除镜像
crictl rmi --prune清理所有未被使用的镜像,释放磁盘
crictl imagefsinfo查看镜像文件系统用量,定位节点磁盘压力
crictl imagefsinfo -o json | jq .status.imageFilesystems查看各存储层用量详情
crictl images | awk "NR>1 {print $3}" | sort -u | wc -l统计镜像数量(按实际输出列调整)
du -sh /var/lib/containerd宿主机侧查看运行时数据目录占用
命令说明复制
crictl pods列出全部 Pod 沙箱及其状态
crictl pods -q只输出沙箱 ID
crictl pods --state ready只看就绪的沙箱
crictl pods --name my-pod按 Pod 名过滤
crictl pods --label io.kubernetes.pod.namespace=kube-system按命名空间标签过滤
crictl inspectp <pod-id>查看沙箱详情,含网络命名空间与配置
crictl inspectp <pod-id> | jq .status.network查看 Pod IP 与网络配置
crictl ps --pod <pod-id>查看该沙箱内的容器列表
READY 与 NOTREADY 状态NOTREADY 多为 CNI 网络插件未就绪或沙箱创建失败
crictl runp sandbox.json手工创建沙箱用于调试网络
crictl stopp <pod-id> && crictl rmp <pod-id>安全删除沙箱的完整流程
crictl pods -o json | jq ".items[].metadata.name"提取全部 Pod 名,快速核对
命令说明复制
systemctl status containerd确认运行时服务状态,节点 NotReady 常从这里开始查
journalctl -u containerd -n 200 --no-pager查看运行时最近日志
journalctl -u kubelet -f同时观察 kubelet 日志,确认是否调用了运行时
crictl info | jq .config查看运行时配置(镜像仓库、日志上限等)
cat /etc/containerd/config.toml | grep -A5 mirrors检查镜像加速与私有仓库配置
crictl pull registry.example.com/app:v1直接验证节点能否拉取镜像,绕过 kubelet 判断
df -h /var/lib/containerd磁盘写满会导致拉镜像与建容器全部失败
crictl rmi --prune 与 crictl imagefsinfo清理未使用镜像释放空间
crictl ps -a 中 ExitCode 非 0 的容器结合 crictl logs 看崩溃原因
rpc error: code = Unimplementedcrictl 与运行时版本不匹配,升级 crictl 或改用对应版本
kubelet 的 --container-runtime-endpoint 必须与 crictl 配置一致不一致会导致 crictl 看不到 kubelet 管理的容器
crictl --runtime-endpoint 参数优先于 /etc/crictl.yaml多运行时时用参数显式区分
命令说明复制
crictl ps ↔ kubectl get podscrictl 看到的是容器视角,kubectl 是 API 视角
crictl pods ↔ kubectl get pods -o widecrictl 多了沙箱 ID,便于对照运行时
crictl logs <id> ↔ kubectl logs <pod> -c <container>kubelet 异常时 crictl 更可靠
crictl exec -it <id> sh ↔ kubectl exec -it <pod> -- sh无需经过 API Server,适合控制面故障时排障
crictl inspect <id> ↔ kubectl describe podinspect 输出更底层,包含 OCI 配置
crictl stats ↔ kubectl top podcrictl 数据来自运行时,指标口径略有差异
crictl images ↔ 无对应 kubectl 命令节点镜像只能通过运行时工具查看
crictl rmi --prune ↔ kubelet 的 image GC手工清理镜像前确认 kubelet GC 策略
crictl port-forward ↔ kubectl port-forward前者不依赖 API Server,适合单节点验证
节点 NotReady 时优先用 crictl 绕过 kubelet 排查确认容器是否真的在跑,再判断是 kubelet 还是运行时问题
命令说明复制
connect: no such file or directory端点路径错误:确认 containerd 或 CRI-O 的实际 socket 路径
context deadline exceeded运行时无响应:检查 containerd 状态与磁盘、CPU 压力
no such containerID 前缀不唯一或容器已被删除,用 crictl ps -a 核对
failed to pull image仓库不可达、证书不受信或认证缺失,先 crictl pull 复现
pull access denied需要认证:使用 --creds 或配置节点的 registry 凭据
x509: certificate signed by unknown authority私有仓库证书不被信任,把 CA 放到 /etc/containerd/certs.d/<host>/ca.crt
failed to create pod sandbox多为 CNI 插件异常或 IP 池耗尽,检查网络插件日志
container is running, cannot remove先 crictl stop 再 rm,或使用 -f 强制
unable to upgrade connection(exec 失败)运行时 exec 插件异常,重启 containerd 后重试
image is referenced in multiple repositories同一镜像多个 tag,改用镜像 ID 删除
permission denied while connecting to socket需要 root 权限,或调整 socket 权限与用户组
no such image镜像未拉取或被 GC 清理,重新 pull 或检查 imagePullPolicy

运维常用组合

定位异常容器crictl ps -a → crictl logs <id> → crictl inspect <id>
节点排障顺序crictl info → crictl ps -a → journalctl -u containerd -n 200
清理节点空间crictl imagefsinfo → crictl rmi --prune → df -h /var/lib/containerd
验证镜像仓库crictl pull registry.example.com/app:v1 → crictl inspecti ... | jq .status.repoDigests
进入业务容器crictl ps --name app → crictl exec -it <id> sh
多运行时切换crictl --runtime-endpoint unix:///var/run/crio/crio.sock ps

常见问题排查

1. crictl 看不到容器

端点写错或与 kubelet 不一致:对比 /etc/crictl.yaml 与 kubelet 的 --container-runtime-endpoint

2. 节点 NotReady 先看什么

crictl info 是否正常 → crictl ps -a 看容器状态 → journalctl -u containerd / kubelet 找错误

3. 镜像拉不下来

先在节点上用 crictl pull 复现;能拉通再查 kubelet 的 imagePullPolicy 与 secret

4. 磁盘告警

crictl imagefsinfo 看镜像层占用,crictl rmi --prune 清理未使用镜像,同时检查日志文件体积

5. 想重启某个业务容器

crictl stop 后 kubelet 通常会重建;手工 start 可能与期望状态冲突,优先用 kubectl delete pod

6. exec 进不去容器

镜像无 shell 时改用 crictl exec <id> 直接执行命令,或用 nsenter 进入命名空间

共 114 条 crictl 命令 · 端点默认 unix:///run/containerd/containerd.sock,请按实际运行时调整

关于crictl命令速查

在线 crictl 命令速查手册,按安装版本与端点配置、容器查看与状态、日志与进入容器、容器生命周期操作、镜像管理、Pod 沙箱管理、运行时与节点排查、与 kubectl 命令对照、常见报错处理等 9 类场景整理 120+ 条常用命令,每条附中文说明与可直接复制的写法,支持关键词搜索、分类折叠和一键复制,打开网页即可查阅。涵盖 crictl -v 与 version 与 info、--runtime-endpoint 指定 containerd 或 CRI-O socket、--image-endpoint 与 --timeout 与 --debug、/etc/crictl.yaml 与 crictl config --set、ps 与 -a 与 --state exited 与 --name 与 --label 与 --pod 与 -q、inspect 与 -o json/yaml 与 jq 提取 state 与 logPath、stats 与 -o json、logs 的 -f/--tail/--since/-t、exec -it 与 --sync 与 sh -c、attach、port-forward、stop -t 与 start 与 rm -f 与 stopp 与 rmp -f、runp 与 create 与 run 与 update、images 与 --digests 与 pull --creds 与 inspecti 与 rmi 与 rmi --prune 与 imagefsinfo、pods 与 --state ready 与 inspectp 与网络命名空间、systemctl status containerd 与 journalctl 与 config.toml mirrors、df -h /var/lib/containerd 与磁盘清理、crictl 与 kubectl get pods/logs/exec/describe/top 的对应关系、connect: no such file or directory 与 context deadline exceeded 与 failed to pull image 与 x509 与 failed to create pod sandbox 与 container is running 与 rpc error Unimplemented 等报错排查。适用于 Kubernetes 节点容器运行时排障、节点 NotReady 定位、镜像拉取与仓库认证验证、Pod 沙箱与网络异常排查、节点磁盘清理,以及运维与 DevOps 面试复习。

核心能力

  • 涵盖 crictl -v 与 version 与 info、--runtime-endpoint 指定 containerd 或 CRI-O socket、--image-endpoint 与 --timeout 与 --debug、/etc/crictl.yaml 与 crictl config --set、ps 与 -a 与 --state exited 与 --name 与 --label 与 --pod 与 -q、inspect 与 -o json/yaml 与 jq 提取 state 与 logPath、stats 与 -o json、logs 的 -f/--tail/--since/-t、exec -it 与 --sync 与 sh -c、attach、port-forward、stop -t 与 start 与 rm -f 与 stopp 与 rmp -f、runp 与 create 与 run 与 update、images 与 --digests 与 pull --creds 与 inspecti 与 rmi 与 rmi --prune 与 imagefsinfo、pods 与 --state ready 与 inspectp 与网络命名空间、systemctl status containerd 与 journalctl 与 config.toml mirrors、df -h /var/lib/containerd 与磁盘清理、crictl 与 kubectl get pods/logs/exec/describe/top 的对应关系、connect: no such file or directory 与 context deadline exceeded 与 failed to pull image 与 x509 与 failed to create pod sandbox 与 container is running 与 rpc error Unimplemented 等报错排查

适用场景

适用于 Kubernetes 节点容器运行时排障、节点 NotReady 定位、镜像拉取与仓库认证验证、Pod 沙箱与网络异常排查、节点磁盘清理,以及运维与 DevOps 面试复习。crictl命令速查全程在浏览器中完成,无需安装插件,可放心用于日常办公与排障。

常见问题

crictl命令速查是免费的吗?需要注册或安装吗?
crictl命令速查完全免费,无需注册、无需下载安装任何软件,用浏览器打开网页即可直接使用,也不限制使用次数。
crictl命令速查支持哪些功能?
涵盖 crictl -v 与 version 与 info、--runtime-endpoint 指定 containerd 或 CRI-O socket、--image-endpoint 与 --timeout 与 --debug、/etc/crictl.yaml 与 crictl config --set、ps 与 -a 与 --state exited 与 --name 与 --label 与 --pod 与 -q、inspect 与 -o json/yaml 与 jq 提取 state 与 logPath、stats 与 -o json、logs 的 -f/--tail/--since/-t、exec -it 与 --sync 与 sh -c、attach、port-forward、stop -t 与 start 与 rm -f 与 stopp 与 rmp -f、runp 与 create 与 run 与 update、images 与 --digests 与 pull --creds 与 inspecti 与 rmi 与 rmi --prune 与 imagefsinfo、pods 与 --state ready 与 inspectp 与网络命名空间、systemctl status containerd 与 journalctl 与 config.toml mirrors、df -h /var/lib/containerd 与磁盘清理、crictl 与 kubectl get pods/logs/exec/describe/top 的对应关系、connect: no such file or directory 与 context deadline exceeded 与 failed to pull image 与 x509 与 failed to create pod sandbox 与 container is running 与 rpc error Unimplemented 等报错排查。
crictl命令速查适合哪些场景使用?
适用于 Kubernetes 节点容器运行时排障、节点 NotReady 定位、镜像拉取与仓库认证验证、Pod 沙箱与网络异常排查、节点磁盘清理,以及运维与 DevOps 面试复习。