Can I use an input file to load into a InitContainer?

Viewed 7

Currently I have an InitContainer that creates two directories.

    initContainers:
      - name: files-init
        image: quay.io/quay/busybox
        command:
        - "/bin/mkdir"
        args:
        - "-p"
        - "/files/test1"
        - "/files/test2"
        volumeMounts:
          - mountPath: /files
            name:  files 

Now it is only creating two directories, but in the future there will be more. And the readability will be going to be harder and also hard to manage. Is it possible to use an input file, with for example the name files.txt that has the following lines:

/files/test1
/files/test2

And that this will be read out with something like this?

    command:
    - "/bin/mkdir"
    args:
    - "-p $files.txt"

Anyone that can help me with this? Do I need to use ConfigMaps for this, if so how.

1 Answers

Please use configmap to load files into a pod. Below is sample. Also refer K8S documentation for other options as well.

apiVersion: v1
kind: Pod
metadata:
  name: mypod
spec:
  containers:
  - name: mypod
    image: redis
    volumeMounts:
    - name: foo
      mountPath: "/etc/foo
  volumes:
  - name: foo
    configMap:
    name: myconfigmap
Related