<p>What I want to do is providing pod with unified log store, currently persisted to hostPath, but I also want this path including UID so I can easily get its path after pod destroyed.</p>

<p>For example:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: pod-with-logging-support
spec:
  containers:
  - image: python:2.7
    name: web-server
    command:
    - "sh"
    - "-c"
    - "python -m SimpleHTTPServer &gt; /logs/http.log 2&gt;&amp;1"
    volumeMounts:
    - mountPath: /logs
      name: log-dir
  volumes:
  - name: log-dir
    hostPath:
      path: /var/log/apps/{metadata.uid}
      type: DirectoryOrCreate
</code></pre>

<p><code>metadata.uid</code> is what I want to fill in, but I do not how to do it.</p>

xudifsd
<p>For logging it's better to use another strategy.</p>

<p>I suggest you to look at this <a href="https://kubernetes.io/docs/concepts/cluster-administration/logging/" rel="nofollow noreferrer">link</a>.</p>

<p>Your logs are best managed if streamed to stdout and grabbed by an agent, like shown in this picture:</p>

<p><a href="https://i.stack.imgur.com/bhUtl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bhUtl.png" alt="enter image description here"></a></p>

<p>Don't persist your log on filesystem, but gather them using an agent and put them together for further analysis.</p>

<p><a href="https://www.fluentd.org/" rel="nofollow noreferrer">Fluentd</a> is very popular and deserves to be known.</p>
