My team doesn't have all our code in the same place locally but we are all working on the same service. This service depends on a few other libraries and during the development it would be great to have the live version of those libs mounted into the pod for faster iteration.
How the path becomes dynamic doesn't matter, env var, config map, weird volume mount sorcery, etc...
My current approach uses helm to template out the yaml. I was hoping to be able to do something like this:
volumes:
- name: my-lib
hostPath:
path: $CODE_PATH/my_lib
volumeMounts:
- name: my-lib
mountPath: /tmp/my_lib
Where my team members could externally define CODE_PATH
, allowing them to point to where they keep their code. I'm not attached to a method for doing this. Currently, mine doesn't work anyway. I just need to be able to mount a host directory into a pod without statically defining an absolute path right in the yaml.
According to the official documentation there are 2 ways to achieve this but in both of them the hostPath
has to be defined.
First approach would be to use hostPath, where hostPath
volume uses the local disk of the node to mount the volume and specify the hostPath
in Preferences->File Sharing in Docker Desktop.
Second approach would be to use a PersistentVolume approach in which cluster administrator creates the volumes and pods can access them through PersistentVolumeClaims
, a level of abstraction between the volume and its storage mechanism.