How to add ConfigMap data to a Volume in a Pod

0 votes

Hi Guys,

I have created a ConfigMap. I want to add the data of ConfigMap to my Container. How can I do that?

Aug 31, 2020 in Kubernetes by akhtar
• 38,260 points
1,240 views

1 answer to this question.

0 votes

Hi@akhtar,

When you create a ConfigMap using --from-file, the filename becomes a key stored in the data section of the ConfigMap. The file contents become the key's value. Now to add the ConfigMap name under the volumes section of the Pod specification. This adds the ConfigMap data to the directory specified as volumeMounts.mountPath. The command section lists directory files with names that match the keys in ConfigMap. You can also see the below example.

apiVersion: v1
kind: Pod
metadata:
  name: dapi-test-pod
spec:
  containers:
    - name: test-container
      image: k8s.gcr.io/busybox
      command: [ "/bin/sh", "-c", "ls /etc/config/" ]
      volumeMounts:
      - name: config-volume
        mountPath: /etc/config
  volumes:
    - name: config-volume
      configMap:
        name: special-config
  restartPolicy: Never
answered Aug 31, 2020 by MD
• 95,460 points

Related Questions In Kubernetes

+1 vote
1 answer

How to use a Volume to communicate between two Containers running in the same Kubernetes-Pod?

Create a Pod that runs two Containers Create a ...READ MORE

answered Jul 23, 2019 in Kubernetes by Sirajul
• 59,230 points
2,602 views
0 votes
0 answers

How to access the configmap created on a worker node, in the pod.yaml in Master?

1. Configmap is created on the node1. ...READ MORE

Apr 5, 2020 in Kubernetes by jayabmaguluri
• 140 points
1,029 views
0 votes
1 answer

How to configure a Pod to use the updated configMap?

If the config map is mounted into ...READ MORE

answered Jul 18, 2019 in Kubernetes by Sirajul
• 59,230 points
1,174 views
0 votes
1 answer

How to edit ConfigMap to add new data?

Hi@MD, You can edit your ConfigMap. Kubectl has ...READ MORE

answered Aug 31, 2020 in Kubernetes by akhtar
• 38,260 points
9,216 views
+1 vote
1 answer
0 votes
3 answers

Error while joining cluster with node

Hi Kalgi after following above steps it ...READ MORE

answered Jan 17, 2019 in Others by anonymous
15,577 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,062 views
0 votes
1 answer

How to launch one Pod in a particular namespace in minikube?

Hi@akhtar, You can pass your namespace name when ...READ MORE

answered Jun 30, 2020 in Kubernetes by MD
• 95,460 points
957 views
0 votes
1 answer

How to copy file inside a Pod in Kubernetes?

Hi@akhtar, You need to use the kubectl cp command ...READ MORE

answered Jul 5, 2020 in Kubernetes by MD
• 95,460 points
4,779 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP