Image Volumes

A Pod needs the weights of a large ML model or a toolset that ships apart from the app image but must be in place before the app starts. How do you hand it over without baking it in, and how does a newer version reach the Pod?

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

Image Volumes, Kubernetes diagram

Image Volumes, step by step

  1. Pod llm-server declares an image volume named model, with reference llm:v1, pullPolicy IfNotPresent and mountPath /models. At Pod startup, before any container starts, Kubelet asks the container runtime to resolve that volume. The app image app:v3 is already on this Node.

    Play from step 1
  2. The model image llm:v1 is not on disk, so under IfNotPresent it gets pulled. It comes from the registry the same way a container image does, with the same pull credentials. The weights live in their own image, not baked into app:v3.

    Play from step 2
  3. As Kubelet creates the app container, the runtime mounts the image as one directory at the mountPath, /models, always read-only. Which kinds of OCI object can be mounted this way is up to the runtime, but at least every image a container can run.

    Play from step 3
  4. Only now does Kubelet start the app container, from its own image app:v3. Had resolving or pulling llm:v1 failed, the app container, which mounts that image, would wait while Kubelet retries with backoff, and the Pod would report why in its status.

    Play from step 4
  5. The app reads the weights in /models but cannot write there. A recreated Pod resolves the volume again, but under IfNotPresent a Node holding llm:v1 skips the pull unless that Node pulled the private image with other credentials. New weights take a new tag or digest, or pullPolicy Always, and app:v3 needs no rebuild for them.

    Play from step 5

Sources