Edit file in k8s Pod in run time

10/1/2021

I have a k8s cluster (using OKD) with a deployment "X", with 1 pod "X_1", and a file "config.yaml" in a volume for this deployment that configure some aspects of the application running. This file is set in a ConfigMap as

data:
  x.config.file: |-
    ...

And it is shared with the deploument as:

template:
    metadata:
      creationTimestamp: null
      labels:
        app: x
        deploymentconfig: x
    spec:
      volumes:
        - name: config
          configMap:
            name: x-config
            items:
              - key: x.config.file
                path: config.yaml
            defaultMode: 420

The application running in this pod has a FileWatcher that checks whenever "config.yaml" file has been modified, and it changes its internal configuration depending on the new state of the file.

Is there a way to change this "config.yaml" file in k8s so every pod that is running (in my case just one, but however) gets the new configuration?

Alternative option

Is there a way to set up a k8s pod so it runs the application interactively, and so the commands in the Terminal tab go directly to the application (and so, change the configuration this way, and not with a file).

Update

I have checked that modifying the ConfigMap, it actually modifies the internal file. I cat the file from the Terminal and it actually updates (sometimes it takes time). The problem though would be that the inotify callback is not being called when the file has been updated.

-- jparisu
configmap
file-watcher
kubernetes
kubernetes-pod
okd

1 Answer

10/4/2021

I finally found the problem here. k8s creates the ConfigMap files in a subdirectory that that references the version of the configuration (in my case, something like: ..2021_10_04_08_03_00.xxx). And a sym link is created in the expected directory referring to the file inside the version directory.

Thus, the file that is being updated is not the actual file that is being watched by inotify. And regarding the inotify documentation (https://linux.die.net/man/7/inotify), updates in linked files are not reported.

-- jparisu
Source: StackOverflow