kuberneteskubernetes-helmvolumedata-sharingconfigmap

Kubernetes/Helm: sharing a single not properties file between Init and Main containers


In a kubernetes (minikube) / helm env I have an ldif file I want to share on a volume between an Init container and a normal one. I don't want to share the entire folder in which this file is stored.

Unfortunately from my understanding this is not possible unless the file is a properties one (syntax "key=value").

I tested using configMap/subPath and it seems like that if key/value syntax is not respected the Init container is not even starting, otherwise everything works and the file appears on the main container as well.

So I wonder if it is even possibile to accomplish this kind of sharing.

BR

edit: main container startup command is a single service start, it cannot execute copies or move the file shared by init container, unless it is the only way.


Solution

  • Yes, it is possible, and you are on the right track.

    Here's an example of how to do this.

    ---
    kind: ConfigMap 
    apiVersion: v1 
    metadata:
      name: example-configmap 
    data:
      my-file.ldif: |
         dn: cn=The Postmaster,dc=example,dc=com
         objectClass: organizationalRole
         cn: The Postmastermongodb
    ---
    kind: Pod
    apiVersion: v1
    metadata:
      name: example-pod
    spec:
      volumes: 
      - name: config-volume
        configMap:
          name: example-configmap
      initContainers:
      - name: init
        image: busybox
        volumeMounts:
        - name: config-volume
          mountPath: /path/in/the/init-container/my-file.ldif
          subPath: my-file.ldif
      containers:
      - name: main
        image: busybox
        volumeMounts:
        - name: config-volume
          mountPath: /path/in/the/container/my-file.ldif
          subPath: my-file.ldif
    

    It would help if you posted your configmap. You might be getting tripped up because for this to work you need the whole contents of your file as the value of one key in your configmap.