Pod Sandbox via CRI

Containers in a Pod share one IP address and localhost, and the address outlives a restart of any of them, so it belongs to none. What does the Kubelet ask the runtime, such as containerd, to build before them?

Play the animation 5 steps, animated, plays on a computer or a tablet

Pod Sandbox via CRI, Kubernetes diagram

Pod Sandbox via CRI, step by step

  1. Kubelet calls RunPodSandbox with the Pod metadata, labels, and resource hints. The runtime first creates the Pod network namespace, still with no IP. Every workload container will share it, with IPC and UTS, by default. The PID namespace is shared only when spec.shareProcessNamespace or spec.hostPID is set.

    Play from step 1
  2. Inside the same RunPodSandbox call the runtime invokes the configured CNI plugin with the netns path. The plugin creates a veth pair, allocates an IP via IPAM, configures routes, and returns the result. Only then does the runtime start the pause container, which holds the network, IPC, and UTS namespaces.

    Play from step 2
  3. Kubelet calls PullImage for the app image, respecting imagePullPolicy and imagePullSecrets. The runtime fetches it from the registry into the Node image store. Under IfNotPresent Kubelet skips the call if the image is there, unless it pulled that private image with other credentials. No workload container exists yet.

    Play from step 3
  4. Kubelet calls CreateContainer with the sandbox id, container config (command, env, mounts), and resource limits. The runtime prepares the rootfs and the mounts and writes those limits into the OCI spec, then returns a container id. The container now exists but is not yet running, and its cgroup is created when it starts.

    Play from step 4
  5. Kubelet calls StartContainer with the container id. The runtime forks the container ENTRYPOINT process inside the shared namespaces of the sandbox. The Pod workload is now running and the Pod reports Ready once every container is ready, after its readiness probe passes if it has one, and any readinessGates are True.

    Play from step 5

Sources