Sub topic 10
Container Runtimes and the Container Runtime Interface
This chapter assumes you know the kubelet's role from the previous chapter. It also assumes you know what a container image is and can use a Linux shell.
What a container runtime does
The kubelet does not start containers itself. It asks a container runtime to do it. The runtime is software on each node that pulls images, unpacks them, creates containers, and reports their state.
Common runtimes include containerd and CRI-O. Both are Kubernetes-focused and widely used.
The Container Runtime Interface
The Container Runtime Interface (CRI) is a gRPC API that the kubelet uses to talk to a runtime. Because the kubelet only speaks CRI, you can swap runtimes without changing Kubernetes itself.
CRI defines two services:
RuntimeServicemanages Pod sandboxes and containers: create, start, stop, remove, and report status.ImageServicepulls, lists, and removes images.
A Pod sandbox is the shared environment of a Pod, such as its network namespace. The kubelet creates the sandbox first, then starts each container inside it.
Most runtimes do not create the container process directly. They delegate to a low-level OCI runtime, usually runc, which sets up namespaces and cgroups and starts the process. OCI is the Open Container Initiative, which defines the image and runtime formats.
Seeing which runtime a node uses
The -o wide output of kubectl get nodes includes a CONTAINER-RUNTIME column.
kubectl get nodes -o wideA value such as containerd://1.7.13 tells you the node runs containerd at that version.
Inspecting containers on a node
On a node, the crictl tool speaks CRI directly. You use it to debug when the API server is unreachable or a container will not start.
sudo crictl pods
sudo crictl ps
sudo crictl imagescrictl needs the runtime's socket path, which is often set in /etc/crictl.yaml.
Common errors
- Looking in the wrong place. On a containerd node,
docker psshows nothing for Kubernetes workloads. Usecrictl psinstead. - Assuming Docker is required. Kubernetes 1.24 removed
dockershim, the built-in adapter for Docker Engine. Images built with Docker still run, because they follow the OCI image format. Only the runtime on the node changed. - Mismatched cgroup drivers. The kubelet and the runtime must use the same cgroup driver, commonly
systemd. A mismatch can cause Pods to fail or nodes to be unstable. - Image pull failures. Errors such as
ImagePullBackOffcome from the runtime's image service. Check the image name, tag, and registry credentials withkubectl describe pod <pod-name>.
Exercise
A teammate runs docker ps on a worker node and sees no containers, though Pods are running. What is the likely cause, and what command should they use?
Show answer
The node probably uses containerd or CRI-O, not Docker Engine, so Docker does not manage the containers. They should run sudo crictl ps to list containers through the CRI.