Kubernetes optimizing deployment file

6/15/2018

I have 3 properties for an applications.

serviceA.properties
serviceB.properties
serviceC.properties

Either I can have one configMap with 3 files or 3 different configMaps. Due to some restriction I am going with 3 configMaps in this case.

 volumeMounts:
    - name: prop1
      mountPath: /conf/prop1
    - name: prop2
      mountPath: /conf/prop2
    - name: prop3
      mountPath: /conf/prop3

 volumes:
  - name: prop1
    configMap:
      name: prop1
      items:
      - key: serviceA.properties
        path: serviceA.properties
  - name: prop2
    configMap:
      name: prop2
      items:
      - key: serviceB.properties
        path: serviceB.properties
  - name: prop3
    configMap:
      name: prop3
      items:
      - key: serviceC.properties
        path: serviceC.properties

Here, I have 3 volume mounts and 3 volumes. Is there any other ptimized way for this?

I tried with only one volume mount and tried to use the same across all 3 volumes. But, getting error(/prop must be unique) while creating the deployment.

-- user1578872
kubernetes

2 Answers

6/15/2018

Definitely you can use 1 ConfigMap with 3 files within:

apiVersion: v1
kind: ConfigMap
metadata:
  name: abcservices-configmap
  namespace: <your_namespace>
data:
    serviceA.properties: |-
      contnet of some settings for the service A
      contnet of some settings for the service A
      contnet of some settings for the service A
    serviceB.properties: |-
      contnet of some settings for the service B
      contnet of some settings for the service B
      contnet of some settings for the service B
    serviceC.properties: |-
      contnet of some settings for the service C
      contnet of some settings for the service C
      contnet of some settings for the service C

And use it after in your deployment:

...
volumeMounts:
  - name: servicea-config
    mountPath: <path_to_serviceA_conf_dir>
    subPath: serviceA.properties
volumeMounts:
  - name: serviceb-config
    mountPath: <path_to_serviceB_conf_dir>
    subPath: serviceB.properties
volumeMounts:
  - name: servicec-config
    mountPath: <path_to_serviceC_conf_dir>
    subPath: serviceC.properties
...
volumes:
  - name: servicea-config
    configMap:
      name: abcservices-configmap
      items:
        - key: serviceA.properties
          path: serviceA.properties
  - name: serviceb-config
    configMap:
      name: abcservices-configmap
      items:
        - key: serviceB.properties
          path: serviceB.properties
  - name: servicec-config
    configMap:
      name: abcservices-configmap
      items:
        - key: serviceC.properties
          path: serviceC.properties

If <path_to_service_conf_dir> is the same for all 3 services, then only one volume would be sufficient.

More info:

https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/ https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath

Hope this helps!

-- Konstantin Vustin
Source: StackOverflow

6/15/2018

If you Populate a Volume with data stored in a ConfigMap, adding the ConfigMap data to the directory specified as volumeMounts.mountPath, ... then yes, you need 3 volumes in your case.

if you create a Kubernetes Volume from a ConfigMap, each data item in the ConfigMap is represented by an individual file in the volume.

If you could, try instead creating a configMap from directories (within the same volume).

-- VonC
Source: StackOverflow