Home > Back-end >  Kubernetes: make pod directory writable
Kubernetes: make pod directory writable

Time:05-26

I have docker image with config folder in it. Logback.xml is located there. So I want to have ability to change logback.xml in pod (to up log level dinamicly, for example) First, I've thought to use epmtyDir volume, but this thing rewrite directory and it becomes empty. So Is there some simple method to make directory writable into pod?

CodePudding user response:

Hello, hope you are enjoying your kubernetes Journey, if I understand, you want to have a file in a pod and be able to modify it when needed,

The thing you need here is to create a configmap based on your logback.xml file (can do it with imperative or declarative kubernetes configuration, here is the imperative one:

kubectl create configmap logback --from-file logback.xml

And after this, just mount this very file to you directory location by using volume and volumeMount subpath in your deployment/pod yaml manifest:

...
        volumeMounts:
        - name: "logback"
          mountPath: "/CONFIG_FOLDER/logback.xml"
          subPath: "logback.xml"
      volumes:
        - name: "logback"
          configMap:
            name: "logback"
...

After this, you will be able to modify your logback.xml config, by editing / recreating the configmap and restarting your pod.

But, keep in mind:

1: The pod files are not supposed to be modified on the fly, this is against the container philosophy (cf. Pet vs Cattle)

2: Howerver, Depending on your container image user rights, all pods directories can be writable...

  • Related