Update data in ConfigMap

63 Views Asked by At

I have a Kubernetes deployment that uses a ConfigMap with some configuration of the data which is frequently updated. I am mounting configMap as the volume inside the pod ( readOnly: False ), and with a Python script that is also running inside the pod, I am trying to update the data in configMap by reading/writing it as a file system in Python. I can read the data but am not able to write/update the configMap with new data.

Keys in configMap : ["etdFile", "currRecCount"]

Error : OSError: [Errno 30] Read-only file system: '/configMap/etdFile'

How can I write/update config map data inside pod without using kubectl scripts ?

1

There are 1 best solutions below

0
Piroozeh On

You can use the subPath option in your volume mount to specify the exact file that you want to mount from the config map. This way, you can avoid the read-only file system error, which occurs when you try to write to the directory that contains the config map files. For example, you can use the following code:

apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
containers:
 -  name: my-container

image: my-image
volumeMounts:
 -  name: config-volume

mountPath: /configMap/etdFile
subPath: etdFile # Specify the file name from the config map
volumes:
 -  name: config-volume

configMap:
 name: my-config-map