title: Kubernetes: Redirecting pod STDOUT, STDERR and pod termination log to a PVC file
body: <p>I am trying to get STDOUT and STDERR of a pod written to the file at PVC mount location.</p>
  
  <p>Following is the template content of my deployment:</p>
  
  <pre><code>
      "template": {
        "metadata": {
          "name": "python-stdout-app",
          "creationTimestamp": null,
          "labels": {
            "k8s-app": "python-stdout-app"
          }
        },
        "spec": {
          "volumes": [
            {
              "name": "task-pv-volume",
              "persistentVolumeClaim": {
                "claimName": "task-pv-claim"
              }
            }
          ],
          "containers": [
            {
              "name": "python-stdout-app",
              "image": "trideep/demo-stdout-app",
              "resources": {},
              "volumeMounts": [
                {
                  "name": "task-pv-volume",
                  "mountPath": "/usr/share"
                }
              ],
              "terminationMessagePath": "/usr/share/1fed8c03-bc30-4889-952e-46f4c19b6ac1.log",
              "terminationMessagePolicy": "File",
              "imagePullPolicy": "Always",
              "securityContext": {
                "privileged": false
              }
            }
          ],
          "restartPolicy": "Always",
          "terminationGracePeriodSeconds": 30,
          "dnsPolicy": "ClusterFirst",
          "securityContext": {},
          "schedulerName": "default-scheduler"
        }
      }
  </code></pre>
  
  <p>I can see the file being written while inside the pod. But not seeing the output on mounted host location.</p>
  
  <p>Following is the execution command</p>
  
  <pre class="lang-sh prettyprint-override"><code>python demo_stdout.py &gt;&gt; /usr/share/1fed8c03-bc30-4889-952e-46f4c19b6ac1.log 2&gt;&amp;1
  </code></pre>
  
  <p>One thing which I did is the output file and the "terminationMessagePath" is the same as i want the pod termination footprint and the stdout/stderr in the same file.</p>
  
  <p>Dockerfile is as below: </p>
  
  <pre><code>FROM python:2.7.15-alpine3.9
  
  WORKDIR /usr/src/app
  
  COPY . .
  
  CMD ["sh", "-c", "tail -f /dev/null"]
  </code></pre>
  
  <p>Tried the following:</p>
  
  <pre class="lang-sh prettyprint-override"><code>python demo_stdout.py &gt;&gt; /usr/share/test.log 2&gt;&amp;1
  </code></pre>
  
  <p>The above produces the log in PVC. But need to get the pod termination log in the same file.</p>
  
  <p>Can someone help me with this?</p>