liveBook · Manning

Image volume

As explained in Kubernetes in Action, Second Edition

An image volume is a Kubernetes volume that exposes the files from an OCI image to containers in the same pod, typically as read-only content.

An image volume exposes the files in an OCI image as a volume mounted into containers in the same pod. Containers can read these files but cannot write to them, making the type useful for static or large files such as model weights or database initialization scripts. section 9.3.1 section 9.7

The volume is declared at pod level and mounted by individual containers. Unlike an emptyDir volume populated by an init container, an image volume needs no file-copying helper: the kubelet obtains the referenced image and exposes its contents at the mount path. section 9.3.1 section 9.1.2

Listing 9.8 Defining an image volume in a pod manifest
apiVersion: v1
kind: Pod
metadata:
  name: quiz
spec:
  volumes:
  - name: initdb                               #1
    image:                                     #1
      reference: luksa/quiz-questions:latest     #2
      pullPolicy: Always                     #3
  - name: quiz-data
    emptyDir: {}
  containers:
  - name: quiz-api
    image: luksa/quiz-api:0.1
    imagePullPolicy: IfNotPresent
    ports:
    - name: http
      containerPort: 8080
  - name: mongo
    image: mongo:7
    volumeMounts:
    - name: quiz-data
      mountPath: /data/db
    - name: initdb                                #4
      mountPath: /docker-entrypoint-initdb.d/     #4
      readOnly: true                              #4

A complete pod manifest shows the image reference, pull policy, container mount, and read-only setting. section 9.3.1

Providing MongoDB initialization files

A quiz pod uses luksa/quiz-questions:latest as an image volume and mounts it in MongoDB at /docker-entrypoint-initdb.d/. Inspecting that directory reveals insert-questions.js, while kubectl describe pod shows the image being pulled before the application containers start. section 9.3.1

The feature is not automatically available in every cluster. The administrator must enable the ImageVolume feature gate; otherwise, manifests may accept the fields while the volume does not work. Current support covers image artifacts, while broader OCI artifact support is planned. section 9.3 section 9.3.1

How Kubernetes in Action, Second Edition covers it

How deep it goes
Defines the volume, manifest fields, mount behavior, startup events, and feature gate, but stops short of broader artifact support.
Examples
Uses quiz questions, insert-questions.js, MongoDB, a pod manifest, kubectl describe, and kubectl exec directory inspection.
What it assumes
Assumes basic pods, containers, volumes, and mounts while introducing OCI images and the ImageVolume feature gate.
What you can do after
Operate/configure an image volume in a pod and verify its mounted files and startup events with kubectl.
How it connects
Connects OCI images, pods, containers, volume mounts, emptyDir volumes, init containers, and the ImageVolume feature gate.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.