dcorneschi@devops:~/kubernetes$

crictl Cheatsheet

Kubernetes 2937 words ~15 min read

crictl Cheatsheet crictl Cheatsheet: Debugging Kubernetes nodes at the CRI level. pods, ps, logs, exec, stats, images, runp. Icons: pods, ps, logs, exec, stats, images, kubelet. crictl Cheatsheet Debugging Kubernetes nodes at the CRI level pods · ps · logs · exec · stats · images · runp pods ps logs exec stats images kubelet

crictl is the command-line client for the Kubernetes Container Runtime Interface (CRI), the gRPC API the kubelet uses to run pods. It works with any CRI runtime (containerd, CRI-O, cri-dockerd) and shows what the node is actually running: pod sandboxes, containers, images, logs and stats, by pod name and namespace. It is a debugging tool for when kubectl can’t help, for example when the API server is down or a node is NotReady.

Everything below was run as root on a kind v0.33.0 node with crictl 1.36.0, containerd 2.3.4 and runc 1.4.3 (Kubernetes 1.37.0).

Where crictl Sits

The kubelet and crictl both talk to the same CRI socket (unix:///run/containerd/containerd.sock for containerd, unix:///run/crio/crio.sock for CRI-O). Behind the socket the runtime's CRI service keeps pod sandboxes, containers and images, and starts the processes with runc. kubectl never talks to the node's runtime: it goes through the API server, which the kubelet watches. ctr skips the CRI and talks to containerd's own API, so it sees no pods.

  • Pod (sandbox): the pod’s shared network namespace, held open by a pause container. crictl pods lists sandboxes.
  • Container: an app container inside a sandbox. crictl ps lists them, with the pod name and namespace.
  • Image: what the containers run. crictl images lists the node’s images.

The kubelet decides what should run; crictl only shows it and pokes at it. What you stop or remove behind the kubelet’s back gets recreated (see The Kubelet Fights Back).

Configuration

crictl reads /etc/crictl.yaml (or --config, $CRI_CONFIG_FILE). On kind, kubeadm and EKS nodes it is usually there already:

crictl config --list
crictl config --get runtime-endpoint
Runtime runtime-endpoint
containerd unix:///run/containerd/containerd.sock
CRI-O unix:///run/crio/crio.sock
Docker Engine via cri-dockerd unix:///var/run/cri-dockerd.sock
# Write it to /etc/crictl.yaml (creates the file if missing, with a warning)
crictl config --set runtime-endpoint=unix:///run/containerd/containerd.sock

# Several keys at once, into another file (the file must already exist)
crictl -c ./crictl.yaml config --set runtime-endpoint=unix:///run/crio/crio.sock --set timeout=10

# One command, no config file
crictl -r unix:///run/crio/crio.sock ps

dockershim.sock is gone: dockershim was removed in Kubernetes 1.24. Docker Engine nodes need cri-dockerd.

Without a config file crictl still works, but tries the three sockets in turn and warns:

WARN runtime connect using default endpoints: [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.

The socket is srw-rw---- root root, so crictl needs root (sudo crictl ...). As another user every command fails with connect: permission denied.

crictl version          # runtime name and version, CRI API version
crictl info             # runtime status (RuntimeReady, NetworkReady) and its full config as JSON
crictl runtime-config   # cgroup driver (SYSTEMD or CGROUPFS)

crictl info | jq '.status.conditions' is the quickest check for a NotReady node: NetworkReady: false means the CNI plugin isn’t working.

Pods

crictl pods                          # all sandboxes, Ready and NotReady
crictl pods --name web               # name regex
crictl pods --namespace kube-sys     # namespace regex (matches kube-system)
crictl pods --label app=web          # pod labels from the manifest
crictl pods --state notready         # ready | notready (any case)
crictl pods -q                       # IDs only (full length)
crictl pods -v                       # verbose, with labels and annotations

A NotReady sandbox is a pod whose containers have all exited (a completed Job pod, a pod being deleted).

crictl inspectp <pod-id>             # full status and runtime spec, JSON
crictl inspectp -o go-template --template '{{.status.network.ip}}' <pod-id>
crictl statsp                        # CPU and memory per pod
crictl statsp --label app=web

inspectp returns status (state, IP, labels, annotations) and info (the sandbox PID, CNI result, runtime spec).

Containers

List

crictl ps                            # running containers
crictl ps -a                         # running and exited
crictl ps --name '^nginx$'           # container name regex
crictl ps --namespace default        # pod namespace regex
crictl ps -p <pod-id>                # containers of one pod (an ID prefix works)
crictl ps --label io.kubernetes.pod.name=web-689b9bdbdd-tgfpf
crictl ps -a --state exited          # created | running | exited | unknown
crictl ps --image nginx:1.29         # image name with tag, or image ID (plain nginx matches nothing)
crictl ps -l                         # the newest container, any state
crictl ps -n 3                       # the 3 newest, any state
crictl ps -q                         # IDs only
crictl ps --no-trunc                 # full IDs
crictl ps -r                         # image name instead of image ID
$ crictl ps -a --name '^flaky$'
CONTAINER           IMAGE               CREATED             STATE               NAME                ATTEMPT             POD ID              POD                 NAMESPACE
3eb5f8e4cc700       d2482869a6b83       7 seconds ago       Running             flaky               2                   b32e65a8d2233       flaky               default
f85a7149aeaed       d2482869a6b83       44 seconds ago      Exited              flaky               1                   b32e65a8d2233       flaky               default
  • ATTEMPT is the restart count. Each restart is a new container with a new ID, so an ID from five minutes ago may be gone.
  • Only one dead container per container is kept. The kubelet garbage-collects older attempts (flaky attempt 0 is gone above), and their log files with them.
  • IMAGE is the image ID, not the name. -r or crictl inspect give the name.

There is no “pod name” flag on ps: use --name (the container name), --label io.kubernetes.pod.name=<pod>, or get the pod ID first:

crictl ps -p $(crictl pods -q --name '^web-')

Inspect

crictl inspect <container-id>        # status + info, JSON
crictl inspect -o go-template --template '{{.status.exitCode}} {{.status.reason}}' <container-id>
crictl inspect <id> | jq -r '.status.logPath'
crictl inspect <id> | jq -r '.info.pid'
Field What it is
.status.state CONTAINER_CREATED, CONTAINER_RUNNING, CONTAINER_EXITED
.status.exitCode, .status.reason Why it stopped (137 Error = SIGKILL, 0 Completed)
.status.image.image, .status.imageRef Image name and its digest
.status.logPath /var/log/pods/<ns>_<pod>_<uid>/<container>/<attempt>.log
.status.mounts Volumes, with host paths
.info.pid The container’s main process on the host
.info.runtimeSpec The full OCI spec (cgroups, capabilities, env)

IDs can be shortened to any unique prefix: crictl inspect be1b works.

Logs

crictl logs <container-id>
crictl logs -f <container-id>              # follow
crictl logs --tail 100 <container-id>
crictl logs --since 10m <container-id>     # relative, or a timestamp: 2026-12-02T10:30:00
crictl logs -t <container-id>              # RFC3339 timestamps
crictl logs -s stderr <container-id>       # one stream only (not together with --tail)
crictl logs -p <container-id>              # the previous attempt

Logs of a crashed container: list with -a and read the exited container directly. That is the previous instance, and it is the only one left:

crictl logs $(crictl ps -aq --name '^crash$' --state exited | head -1)

-p reads the log of attempt N-1. It works while a new attempt exists, but on the exited container itself it looks for a file the kubelet has already deleted:

$ crictl logs -p df83c21eed5d6
FATA failed to try resolving symlinks in path "/var/log/pods/default_crash_b17148e7-1391-4714-96ef-ea21827fc51f/crash/2.log": lstat /var/log/pods/default_crash_b17148e7-1391-4714-96ef-ea21827fc51f/crash/2.log: no such file or directory

The files are plain text under /var/log/pods/, with symlinks in /var/log/containers/, so tail -f and grep work on them directly.

Exec and Attach

crictl exec <container-id> ls /             # no TTY, output only
crictl exec -it <container-id> sh           # interactive shell
crictl exec -s <container-id> id            # synchronous, no streaming
crictl exec --name '^coredns$' hostname     # every container matching the name
crictl attach <container-id>                # stdout of PID 1, Ctrl-C to stop
  • -it needs a terminal. From a script or docker exec without -t it fails with input is not a terminal.
  • Images often have no bash. Busybox and Alpine have sh; distroless images (coredns, many controllers) have no shell and not even cat:
exec failed: unable to start container process: exec: "/bin/bash": stat /bin/bash: no such file or directory
exec failed: unable to start container process: exec: "cat": executable file not found in $PATH

For a distroless container use the host’s tools in its namespaces, from the PID that inspect gives:

PID=$(crictl inspect -o go-template --template '{{.info.pid}}' <container-id>)
cat /proc/$PID/root/etc/resolv.conf      # its filesystem
nsenter -t $PID -n ip -br addr           # its network namespace
nsenter -t $PID -n ss -ltn               # what it listens on

Stats

crictl stats                       # CPU %, memory, writable layer disk and inodes, running containers
crictl stats -a                    # include exited
crictl stats <container-id>
crictl stats --label io.kubernetes.pod.namespace=kube-system
crictl stats -w                    # refresh until Ctrl-C
crictl stats -s 5                  # sample CPU over 5 s (default 1)
crictl stats -o json <id>          # raw counters

stats clears the screen before printing; use -o json or -o yaml in scripts. It has its own -w, so watch crictl stats isn’t needed.

Stop, Start, Remove

crictl stop <container-id>               # SIGKILL now (default timeout 0)
crictl stop -t 30 <container-id>         # stop signal, SIGKILL after 30 s
crictl rm <container-id>                 # exited containers only
crictl rm -f <container-id>              # running too
crictl rm -k <container-id>              # keep the log file
crictl start <container-id>              # CREATED containers only
  • stop kills by default. With -t 0 nginx exited 137 Error; with -t 10 it got its stop signal and exited 0 Completed.
  • rm refuses running containers: container "18cd2a89..." is running, please stop it first.
  • start only works on a container in CONTAINER_CREATED, the step between crictl create and running. An exited container can’t be started again: container is in CONTAINER_EXITED state.
  • rm deletes the logs. After crictl rm on a completed pod’s container, kubectl logs once returned unable to retrieve container logs. The pod still shows Completed.

Images

crictl images                              # IMAGE, TAG, IMAGE ID, SIZE
crictl images -f reference=nginx           # filter by name (regex)
crictl images -f dangling=true             # untagged
crictl images --digests
crictl images --pinned                     # PINNED column; pinned images are never garbage-collected (kind pins pause and the control plane)
crictl images -q                           # IDs only
crictl inspecti nginx:1.29                 # repo tags, digests, size, full image config
crictl inspecti -o go-template --template '{{.info.imageSpec.config.Cmd}}' alpine:3.23
crictl imagefsinfo                         # bytes and inodes used by the image filesystem

crictl images nginx does not filter: the argument is ignored and every image is listed. Use -f reference=nginx.

crictl pull nginx:1.29                     # short names work (docker.io/library/ is added)
crictl pull --creds user:pass registry.example.com/app:1.0
crictl rmi nginx:1.29                      # by name or ID
crictl rmi --prune                         # every image no container is using right now
crictl rmi -a                              # every image
  • rmi doesn’t check running containers. crictl rmi nginx:1.29 succeeded with nginx running from it. On the container’s next restart the kubelet pulled it again (Pulling image "nginx:1.29"). On a node without registry access that restart ends in ErrImagePull.
  • --prune removes images that are only used now and then: kind’s local-path-helper (used by short-lived volume helper pods) went with it. The kubelet’s image GC already frees disk when the image filesystem passes 85 % (imageGCHighThresholdPercent).

The Kubelet Fights Back

What happens after each crictl action on a kubelet-managed node. crictl stop on a container: the kubelet starts a new container in the same pod (ATTEMPT and RESTARTS go up by one). crictl rm on an exited container: it stays gone, and so do its logs (kubectl logs fails). crictl stopp and rmp on a pod: the kubelet creates a new sandbox and new containers for the pod. crictl rmi on an image in use: the next container start pulls it again. crictl runp and create for a pod the API server doesn't know: the kubelet removes the container within a second and stops the sandbox. Fix things with kubectl; use crictl to look.

The kubelet compares the node with the pods the API server assigned to it, every few seconds:

  • crictl stop on a container: a new container starts in the same pod, RESTARTS goes up by one.
  • crictl stopp / crictl rmp on a pod: a new sandbox and new containers. The pod name stays, the pod ID changes.
  • crictl runp on a kubelet node: the kubelet doesn’t know the pod, so it removed its container within a second ("RemoveContainer" in the kubelet log) and the sandbox went NotReady.

Use crictl to look. Restart pods with kubectl delete pod or kubectl rollout restart, which go through the API server.

Standalone Pods (No Kubelet)

runp, create and start run a pod without Kubernetes: useful for testing a runtime or a node before it joins a cluster. Stop the kubelet first (systemctl stop kubelet), or it removes the container as described above.

pod-config.json:

{
  "metadata": { "name": "test-sandbox", "namespace": "default", "attempt": 1, "uid": "hdishd83djaidwnduwk28bcsb" },
  "log_directory": "/tmp",
  "linux": { "cgroup_parent": "crictl-test.slice" }
}

container-config.json:

{
  "metadata": { "name": "busybox" },
  "image": { "image": "busybox:1.38" },
  "command": ["sh", "-c", "echo hi from crictl; sleep 3600"],
  "log_path": "busybox.0.log",
  "linux": {}
}
POD=$(crictl runp pod-config.json)
CTR=$(crictl create $POD container-config.json pod-config.json)
crictl start $CTR
crictl logs $CTR

crictl stopp $POD && crictl rmp $POD     # or crictl rmp -f $POD

crictl run container-config.json pod-config.json does all three in one step.

cgroup_parent must match the cgroup driver. With the systemd driver (crictl runtime-config prints cgroup driver: SYSTEMD, the default on kind, kubeadm and EKS) a config without a .slice parent fails:

runc create failed: expected cgroupsPath to be of format "slice:prefix:name" for systemd cgroups, got "/k8s.io/ad6df3d75de08c7b8542dfd1ce58186df72c33b33d5bd2d0ff81b5b1d3d47d55" instead

Port Forwarding and Events

crictl port-forward <pod-id> 8080:80     # node's 127.0.0.1:8080 -> pod port 80
crictl events                            # container created/started/stopped/deleted, as JSON

port-forward listens on the node’s loopback (127.0.0.1 and [::1]), not on your laptop; it is for curl on the node. From outside use kubectl port-forward.

Output Formats

crictl ps -o json | jq -r '.containers[] | [.metadata.name, .state] | @tsv'
crictl pods -o yaml
crictl images -o json
crictl inspect -o go-template --template '{{.status.state}}' <id>
crictl ps -v                              # human-readable, with labels and annotations

ps, pods and images take json, yaml and table; inspect, inspectp and inspecti take json, yaml, go-template and table.

Common Debugging Tasks

# What is crash-looping on this node?
crictl ps -a --state exited

# Why did it exit?
ID=$(crictl ps -aq --name '^crash$' --state exited | head -1)
crictl inspect -o go-template --template '{{.status.exitCode}} {{.status.reason}}' $ID
crictl logs $ID

# Control plane down (kubeadm, kind): are the static pods running?
crictl ps -a --namespace kube-system --name 'kube-apiserver|etcd'
crictl logs --tail 50 $(crictl ps -aq --name '^kube-apiserver$' | head -1)

# Node NotReady: runtime and CNI status
crictl info | jq '.status.conditions'

# Which container eats the memory?
crictl stats -o json | jq -r '.stats[] | [.attributes.metadata.name, .memory.workingSetBytes.value] | @tsv' | sort -k2 -n

# Pod IP and network namespace
crictl inspectp -o go-template --template '{{.status.network.ip}}' $(crictl pods -q --name '^web-')

Batch Operations

# Remove exited containers (and their logs; the kubelet does this itself)
crictl rm $(crictl ps -aq --state exited)

# Stop everything in one namespace
crictl stop $(crictl ps -q --namespace '^demo$')

crictl stop -a, crictl rm -a and crictl ps -q | xargs crictl stop hit every container on the node, including kube-apiserver, etcd, kube-proxy and the CNI. Always filter.

crictl vs ctr vs docker vs kubectl

  crictl ctr docker kubectl
Talks to CRI socket on the node containerd’s own API Docker daemon API server
Runs on the node, as root the node, as root the node anywhere
Sees pods Yes (sandboxes, by name) No (containers in k8s.io) Only with cri-dockerd Yes (API objects)
Logs crictl logs (node files) No docker logs kubectl logs (via kubelet)
Works when the API server is down Yes Yes Yes No
Changes stick No, the kubelet reconciles No No Yes

Quick Reference

# Setup
crictl config --set runtime-endpoint=unix:///run/containerd/containerd.sock
crictl version && crictl info | jq '.status.conditions'

# Pods
crictl pods [--name <re>] [--namespace <re>] [--label k=v] [--state ready|notready] [-q]
crictl inspectp <pod-id>
crictl statsp

# Containers
crictl ps [-a] [--name <re>] [--namespace <re>] [-p <pod-id>] [--state exited] [-q]
crictl inspect <id>
crictl logs [-f] [--tail N] [--since 10m] [-p] <id>
crictl exec -it <id> sh
crictl stats [-a] [-w]
crictl stop [-t 30] <id>
crictl rm [-f] <id>

# Images
crictl images [-f reference=<re>] [--digests]
crictl pull <image>
crictl inspecti <image>
crictl rmi <image> | --prune

# Without a kubelet
crictl runp pod.json; crictl create <pod-id> ctr.json pod.json; crictl start <id>
crictl stopp <pod-id>; crictl rmp <pod-id>

Important Notes

  • Look, don’t fix: the kubelet recreates what you stop or remove. Change pods with kubectl.
  • Root: the CRI socket is root:root 0660.
  • New attempt, new ID: every restart is a new container. Only the last dead one, and its log, is kept.
  • stop defaults to SIGKILL; give -t for a graceful stop.
  • rm deletes logs; kubectl logs can’t read them afterwards.
  • rmi and --prune don’t protect images in use; the kubelet re-pulls on the next start.
  • crictl images <name> doesn’t filter; use -f reference=<name>.
  • No shell in distroless images: use nsenter -t <pid> and /proc/<pid>/root.

See Also