In docker world, we can use pure docker image and use --volumes-from
to connect it with container, how this works in the kubernetes
Docker image could be html files like
FROM scratch
COPY html /www
How can I mount it to the nginx pod?
BTW: Surely I can turn docker pure data image to use busybox
as base image, then copy the data out using initContainers, which make the image 1M bigger, here try to see whether it is possible in k8s world
2
Answers
You would use the
volumes
andvolumeMounts
.UPD:
html file to mount:
Create configMap with the content of the file:
nginx pod file:
Creating the pod:
Checking nginx serves the file:
UPD2:
You can have everything in one big happy file, no need to prep anything in advance:
Unlike Docker’s named volumes, volume mounts in Kubernetes never copy anything into the volume. You occasionally see tricks with Docker Compose setups where a Docker named volume is mounted over two containers, with the expectation that static files will be copied into the volume from one of them to be served by the other; this just doesn’t work in Kubernetes unless you copy the files yourself.
For the setup you show, you have a collection of files you want to serve, and you want to have the standard
nginx
image serve them. Instead of trying to copy files between images, you can have a unified image that startsFROM nginx
and contains your files:You don’t need any sort of volume to run this. Just specify it as the
image:
in your Deployment spec, and all of the files to be served are already compiled into the image.