Mount Static Assets from an OCI Image into a Kubernetes Pod
Container images are long-used for shipping not only applications but also arbitrary artifacts - static assets, model weights, configuration files, etc.
Getting the contents of a(n artifact) container image into a Pod historically required either an
init container that copied the files into a shared emptyDir, or baking the
image's files into the application container itself. Since Kubernetes v1.36 (GA),
there is a much simpler option: the image volume type,
which lets the Pod mount an OCI image directly as a volume.
In this challenge, an OCI image with a custom index.html page has already been
pushed to registry.iximiuz.com/welcome-page:v1. Your task is to deploy a Pod
that runs nginx and mounts this image so that its index.html becomes nginx's
default index page.
Success criteria:
- A Pod named nginx-1 exists in the
defaultnamespace. - The Pod uses an
imagevolume that referencesregistry.iximiuz.com/welcome-page:v1. - That volume is mounted at
/usr/share/nginx/htmlin the nginx container. - Hitting the Pod's nginx on port 80 returns the custom welcome page from the OCI image.
Hint: What is an OCI Image Volume?
A Pod volume of kind image makes Kubernetes pull an OCI image from a registry
and expose its filesystem as a regular (read-only) volume that can be mounted into one or
more Pod's containers. The contents of the image's root filesystem appear at the
volume's mountPath, replacing whatever was there in the original container image (if anything).
Read more in the official Kubernetes documentation.
Hint: How To Add an Image Volume to a Pod?
A Pod with an image volume looks exactly like a regular Pod, but with one of the
volumes entries declared as an OCI image reference:
...regular pod spec...
volumes:
- name: <volume-name>
image:
reference: <registry>/<repo>/<image>:<tag>
pullPolicy: IfNotPresent
Hint: Where Should the Image Be Mounted?
By default, nginx serves files from /usr/share/nginx/html. If you mount the
image volume at that exact path, the image's index.html will replace Nginx's
default welcome page automatically.
Hint: Inspecting the Image Volume
If something doesn't work, you can verify the image volume is mounted correctly by running:
kubectl exec nginx-1 -- ls -la /usr/share/nginx/html
kubectl exec nginx-1 -- cat /usr/share/nginx/html/index.html
Does the file exist? Does cat show the expected content?
If both commands succeed, you can verify that Nginx serves the expected welcome page by running:
kubectl exec nginx-1 -- wget -qO- localhost:80