Node
Pulling an image
Manifests, layers, cache
How containerd finds, downloads and unpacks image layers, and why the second pull is instant. Follow the 1.5.0 pull on node-2: three of its five layers are already on disk from 1.4.2, so 6.1 MB moves instead of 48 MB - and the next pull of the same tag moves nothing at all.
- Image
- registry.example.com/shop/web:1.5.0
- Layers
- 5 · 3 already on disk · 2 to fetch
- Download
- 6.1 MB of 48.3 MB
- Digests
- every blob addressed by sha256 of its bytes
Read the whole lesson as text
1. Resolve and auth
The kubelet's PullImage call lands on containerd, which turns the registry name into a connection: DNS for registry.example.com, then HTTPS on 443. The registry answers the first request with 401 and a token service; containerd proves it may pull shop/web and gets a scoped bearer token. Public registries run the same dance with an anonymous token.
- The kubelet asks containerd for the 1.5.0 image.
- The registry asks who's calling, and a token service lets containerd in.
2. The manifest
The first real fetch is the manifest: JSON that lists the layers as content-addressed digests. For a multi-arch image it's two steps - an index listing every platform, then the arm64 manifest inside it. Each digest is the sha256 of the exact bytes being described, which is what makes caching and verification the same mechanism.
- containerd fetches the index, then the arm64 manifest inside it.
- The manifest lists five layers by the hash of their bytes.
3. Layer math
Before fetching anything, containerd checks its content store: do I already have these exact digests? Layers 1, 2 and 3 match 1.4.2's - base OS and runtime, unchanged - so they're skipped entirely. Layers 4 and 5 are new. The downloads run in parallel and each is verified as it streams in: the hash is computed while the bytes arrive, and a mismatch aborts the pull.
- Three of the five layers are already on disk, byte-for-byte identical.
- Only the two new layers cross the network, in parallel, hashes checked as they land.
4. Unpack
Bytes in the content store aren't a filesystem yet. The snapshotter unpacks each new layer's tar into its own snapshot directory, stacked on the three snapshots already there from 1.4.2. A whiteout file - usr/local/.wh.tmp in a later layer - records that this path was deleted upstream, so unpacking it hides usr/local/tmp from the layers below. Order matters: layer 5's files win over layer 1's wherever both have a path.
- The two new layers are unpacked, each into its own directory, on top of the three already there.
- The image is stored, unpacked and indexed. 690 ms, most of it the 6.1 MB download.
5. The second pull
Pull the same tag again on this node - imagePullPolicy: Always on a container restart, say - and almost nothing happens. containerd re-fetches only the manifest to learn what the tag points at today; the digest matches what's in the content store, every layer skips, and the call returns in tens of milliseconds. Rollbacks are the same trick in reverse: 1.4.2's layers are all still there.
- A second PullImage asks for the same tag.
Summary
Everything about image distribution falls out of one idea: blobs are named by the hash of their bytes. Sharing is automatic - same digest, same bytes, fetch once. Verification is free - hash what arrives. And a second pull is one manifest round trip, because the store already agrees with the registry about every layer.
Next lesson: Probes and restarts