Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to merge two configmaps using volume mount in kubernetes

I am having two different config maps test-configmap and common-config. I tried to mount them at the same location, but one config map overwrote the other. Then I read about subPath and did not work.

deploy.yaml

apiVersion: apps/v1beta1 # for versions before 1.8.0 use apps/v1beta1
kind: Deployment
metadata:
  name: testing
spec:
  replicas: 1
  template:
    metadata:
      name: testing
      labels:
        app: testing
    spec:
      containers:
      - name: testing-container
        image: testing
        imagePullPolicy: IfNotPresent
      ports:
      - containerPort: __PORT__
      volumeMounts:
      - name: commonconfig-volume
        mountPath: /usr/src/app/config/test.config
        subPath: test.config
    volumes:
      - name: commonconfig-volume
        configMap:
          name: test-configmap
      - name: commonconfig-volume
        configMap:
          name: common-config

Error :

The Deployment "testing" is invalid: spec.template.spec.volumes[1].name: Duplicate value: "commonconfig-volume"

I am not sure if merging two config map achievable of not. And if yes then how should I do it.

like image 481
jack Avatar asked Mar 14 '18 20:03

jack


People also ask

How do I mount a ConfigMap as volume in Kubernetes?

Mount the ConfigMap through a VolumeAttach to the created Pod using `kubectl exec -it pod-using-configmap sh`. Then run `ls /etc/config` and you can see each key from the ConfigMap added as a file in the directory. Use `cat` to look at the contents of each file and you'll see the values from the ConfigMap.

How do I add multiple ConfigMap in Kubernetes?

You can use kubectl create configmap to create a ConfigMap from multiple files in the same directory. When you are creating a ConfigMap based on a directory, kubectl identifies files whose basename is a valid key in the directory and packages each of those files into the new ConfigMap.

How do I mount a ConfigMap?

Mount the configmap into the application container Create a container using the specified image from DockerHub; Make the configmap clusters-config-file available as a mountable volume called clusters-config-volume ; and. Mount that volume into the container at the path /clusters-config.


1 Answers

You have to use special projected volumes for achieve that. Example your deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: testing
spec:
  replicas: 1
  selector:
    matchLabels:
      app: testing
  template:
    metadata:
      name: testing
      labels:
        app: testing
    spec:
      containers:
      - name: testing-container
        image: testing
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: __PORT__
        volumeMounts:
        - name: commonconfig-volume
          mountPath: /usr/src/app/config
      volumes:
        - name: commonconfig-volume
          projected:
            sources:
            - configMap:
                name: test-configmap
            - configMap:
                name: common-config

You can use secret same as configMap

like image 53
kvaps Avatar answered Sep 30 '22 02:09

kvaps