What I would like to have is a github repo, containing multiple folders and files to be available as a configmap, for the services to mount as volumes and use them, as it where local files.
We can add files (or folders) to this repo - and the configmap when updated - should make sure these files are also available for the services.
I am able to create a configmap
kubectl create configmap my-config --from-file=/my-repo/
But the configmap has only the files under the folder, not the sub-folders and files in them.
How can I mount the entire folder such that they are available for the services to use?
When creating a ConfigMap in Kubernetes using kubectl create configmap, it does not automatically include sub-folders and files in your directory. You'll need to explicitly include all the files and directories you want in your ConfigMap. However, you can automate this process with a script or use Kubernetes resources like ConfigMap and Volume to achieve what you want. Here's a step-by-step guide:
Create a ConfigMap that includes all your files and directories :
You can use kubectl create configmap or a YAML file to define your ConfigMap. Here's an example YAML file that includes files and directories from a local directory:
In the above example, the ConfigMap includes three files, including one in a subdirectory.
Apply the ConfigMap:
Use kubectl apply to create or update the ConfigMap:
Mount the ConfigMap as a volume in your pod:
You can now mount this ConfigMap as a volume in your pods. Here's an example Pod YAML that mounts the ConfigMap as a volume:
In this Pod definition, the ConfigMap is mounted as a volume at the path /config. This means you can access the files and directories from the ConfigMap as if they were local files within your container.
With this setup, any changes to your ConfigMap will be reflected in your pods. If you add or modify files in the ConfigMap, the pods using it will automatically see those changes without needing to recreate the pods.