-1

I have a configmap that I have mounted onto a pod as a volume and I am able to use its content from inside the pod. Now, I want to write something back to this configmap from inside the pod and I want it to be reflected in the configmap when I check it outside the pod.

Is this possible?

When it comes to docker, we can access the data from the host and vice versa. Is it true for K8s volumes also?

Thanks

codego123
  • 171
  • 2
  • 12
  • No, you can't achieve it using ConfigMap. – Kamol Hasan Mar 09 '21 at 10:21
  • @KamolHasan Thanks for answering, is there any other type of volume in K8s that I can use? – codego123 Mar 09 '21 at 10:24
  • Hi Saloni, Can you elaborate what you are trying to do? The Configmap suppose to be readable more like environment variable. You can use persistent volume mount to write the data, but really depends on your use case. You may better be placed to use a database connection or API from one POD to the DB POD. If you can detail your usecase we may recommend a better solution. – A Modgil Mar 09 '21 at 10:29
  • Yes, you can use any kind of persistent volume that persists the data with changes. – Kamol Hasan Mar 09 '21 at 10:30
  • @AModgil I am trying to run a command on my container (from a dockerfile) and I want to report back the output/error status so that the application that is running the container can take action accordingly. – codego123 Mar 09 '21 at 10:34
  • in this case i would recommend a logging agent. there are few out there but i came across sematext https://sematext.com/guides/kubernetes-logging/ . The issue with capturing log the way you are doing is what if the container is completely dead and you have a new container spun up to replace the old one. The log on old one is gone with it. Therefore you need an agent which keeps on talking to a centralise logging system. For a small application you can build something custom but that wont be scalable and you may hit into issues later. – A Modgil Mar 09 '21 at 10:40
  • @AModgil Thanks for the suggestion I will check it out. Although it would be ok if I lose the logs in those rare cases since I am just running flexible I/O commands on it. – codego123 Mar 09 '21 at 10:46

1 Answers1

0

ConfigMaps are always mounted as read-only so you won't be able to write back anything. The alternative is to have some sort logging agent or write that output somewhere where it will persist beyond pod life cycle.

By default, if container for some reason is being restarted, kubelet will keep only one terminated container with its logs. If the pod is evicted, the containers inside along with their logs are gone. So what ever your app will return and store will be gone.

In a prod system, you`ll want to use a centralized, cluster-wide logging solution, so your all logs are collected and stored permanently in central location.

The components for providing a centralized storage of the container logs must be provided by additional components, which usually run as regular pods in the cluster such as logging agent.

The cluster-level logging section of Kubernetes docs goes thru couple of examples of how to:

  • Use a node-level logging agent that runs on every node.
  • Include a dedicated sidecar container for logging in an application pod.
  • Push logs directly to a backend from within an application.
acid_fuji
  • 6,287
  • 7
  • 22