<p>I have a java application, which has to be deployed to different environments via gitlab-ci. One of such environments is Kubernetes cluster. My app has some log configs. For Kubernetes cluster they live in <code>logback-k8s.xml</code>.
So, in <code>logback</code> i have something like</p>
<pre><code>&lt;root level=&quot;INFO&quot;&gt;
    &lt;appender-ref ref=&quot;STDOUT&quot;/&gt;
&lt;/root&gt;
</code></pre>
<p>In a <code>Dockerfile</code> I have something like</p>
<pre><code>ENTRYPOINT [&quot;java&quot;,&quot;-jar&quot;,&quot;run/app.jar&quot;,&quot;-Dlogback.configurationFile=/run/classes/logback_k8s.xml&quot;]
</code></pre>
<p>My app is deployed via <code>Deployment.yaml</code>, where I have something like</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: app
      containers:
        - image: registry.myreg.ru/app:1.1.1
          name: app
</code></pre>
<p>In <code>.gitlab-ci.yml</code> I have something like</p>
<pre><code>Kuber:
  stage: Kubectl
  script:
    - kubectl apply -f kuber/Deployment.yaml -n development
</code></pre>
<p>Having all of this, how can I change logging lvl of my app, when it already is deployed to the cluster? Like, the silly way I can imagine is to change <code>logback</code> configs in a project and then rerun pipeline. But it looks like too much actions. What if I have any troubles with my current running version of the app, and all I want - is to restart it with <code>DEBUG</code> lvl to inspect the situation? What the best practices?</p>
<p>UPD: already answered <a href="https://stackoverflow.com/questions/49566123/kubernetes-deployment-externalizing-log-file/51838500">here</a></p>

Victoria Agafonova
<p>The simplest approach here is to let your app read log level from environment variables. This way - you don't need to change it and the behaviour will depend on the environment. To find out how to add an env. variable to your container in your deployment you can do: <code>kubectl explain deployment.spec.template.spec.containers.env --api-version=apps/v1</code> (You can always use <code>kubectl explain</code> to understand how to configure particular kubernetes resource.<br />
So, in your case, you can configure your deployment, like the following:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: app
spec:
  template:
    spec:
      containers:
        - image: registry.myreg.ru/app:1.1.1
          name: app
          env:
            - name: LOG_LEVEL
              value: &quot;INFO&quot;

</code></pre>
<p>If you app ignores <code>LOG_LEVEL</code> env. variable you can use <a href="https://logback.qos.ch/manual/configuration.html#variableSubstitution" rel="nofollow noreferrer">variable substitution</a> in logback configuration. Also, don't forget to specify a <code>selector</code> for your deployment: <code>kubectl explain deployment.spec.selector --api-version=apps/v1</code> <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/</a></p>
