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.