'Dynamically change log levels across all instances

Let's say, I have a spring boot application where I am using Log4j for logging. In there, I want to change the log level dynamically without staring the whole application.
This can be achieved by exposing some endpoint to set the levels. But, at production level, there might be multiple instances of the same application running across different servers.
So, how can we set the logging levels dynamically across all the container instances running the applications which are managed by kubernetes?



Solution 1:[1]

If your application read log levels from application.properties or application.yaml, ConfigMap would do it:

A ConfigMap is an API object used to store non-confidential data in key-value pairs. Pods can consume ConfigMaps as environment variables, command-line arguments, or as configuration files in a volume A ConfigMap allows you to decouple environment-specific configuration from your container images, so that your applications are easily portable.

You can check my other answer where I wrote step by step with explanation how to use a ConfigMap

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 RadekW