Pre-populating GCE persistent disks while building and/or before running Docker image on GKE
Solution 1:
The obvious answer is to populate each persistent disk immediately after creating it.
If the application configs change from build to build, and they must match the running build, then there's an unresolved problem about what to do if multiple app versions share the same PD and conflict over what should be stored there.
If you don't need to worry about cross-version PD sharing, then you can initialize the contents of the PD using a job running in the application's pod. Kubernetes has a feature called init containers designed to make this easier; but it's still alpha at the time of writing.
Solution 2:
I did not hear about best practices, so this is what I have adopted for now:
-
docker build
the image withDockerfile
that also tars e.g./etc/<application>/
into<application>.tar
after it has done its other build steps - briefly
docker run
the image andscp
tar files off the running image - briefly create a temporary VM instance and add/attach the PD to it;
scp
tar files to the VM instance;gcloud compute ssh
into tit, mount the PD, and untar needed files below mount point