Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mount a ConfigMap as a file without using volume

The aim behind this question is to know how having a file inside a Pod, if we use ConfigMap, I don't want to apply changes if the configMap will change

Thanks

like image 365
Smaillns Avatar asked Oct 15 '25 09:10

Smaillns


1 Answers

I am not really understanding, why don't you want to use a volume? A proper way, to mount a confgimap to a pod looks like this: Configmap- specify name of the file in a data section:

apiVersion: v1
kind: ConfigMap
metadata:
  creationTimestamp: 2016-02-18T18:52:05Z
  name: txt-file-configmap
  namespace: default
  resourceVersion: "516"
  selfLink: /api/v1/namespaces/default/configmaps/game-config
  uid: b4952dc3-d670-11e5-8cd0-68f728db1985
data:
  file.txt: |
    here
    are
    filecontents

And in a pod, specify a volume with a configmap name and volumeMount, pointing a path, where to mount the volume:

apiVersion: v1
kind: Pod
metadata:
  name: dapi-test-pod
spec:
  containers:
    - name: test-container
      image: k8s.gcr.io/busybox
      command: [ "/bin/sh", "-c", "cat /etc/txtfiles/file.txt" ]
      volumeMounts:
      - name: txt-file
        mountPath: /etc/txtfiles
  volumes:
    - name: txt-file
      configMap:
        name: txt-file-configmap

The example pod which I provided you, will have the configmap mounted as a file and will print it's contents.

like image 75
Marcin Ginszt Avatar answered Oct 17 '25 05:10

Marcin Ginszt