<p>Is it possible to get timestamp using downward API or any other way in pod spec</p>
<p>Checked here <a href="https://kubernetes.io/docs/tasks/inject-data-application/downward-api-volume-expose-pod-information/#capabilities-of-the-downward-api" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/inject-data-application/downward-api-volume-expose-pod-information/#capabilities-of-the-downward-api</a>, but couldn't find timestamp.</p>
<p>Below is sample section from yaml where  i want to generate output file with timestamp.</p>
<pre><code>          args:
            - &quot;audit&quot;
            - &quot;--config&quot;
            - &quot;/opt/app/app-config/app.yaml&quot;
            - &quot;--format&quot;
            - &quot;json&quot;
            - &quot;--output-file&quot;
            - &quot;/var/log/app/app-$(date +%s).log&quot;
</code></pre>
<p>Similar questions:</p>
<ul>
<li><a href="https://stackoverflow.com/questions/52218081/include-pod-creation-time-in-kubernetes-pod-name">Include Pod creation time in Kubernetes Pod name</a></li>
<li><a href="https://stackoverflow.com/questions/52218081/include-pod-creation-time-in-kubernetes-pod-name">Include Pod creation time in Kubernetes Pod name</a></li>
</ul>

Sumit Murari
<p>As mentioned in comments by @David Maze</p>
<blockquote>
<p>You can wrap this in a sh -c invocation to cause a shell to do the subprocess expansion.</p>
</blockquote>
<hr />
<p>Other way here would be to use <a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#set" rel="nofollow noreferrer">kubectl set</a>.</p>
<p>You can use</p>
<pre><code>kubectl set env deployment/deployment-name TIMESTAMP=$(kubectl get pod pod-name -o jsonpath='{.metadata.creationTimestamp}')
</code></pre>
<p>This will set creationTimestamp value as the env variable with TIMESTAMP name.</p>
<p>You can check the results with <code>kubectl describe pod pod-name</code> and search for Environment.</p>
<hr />
<p>Additionally you can use</p>
<pre><code>kubectl -n namespace get pod pod_name -o jsonpath=&quot;{range .status.conditions[*]}{.type}{','}{.lastTransitionTime}{'\n'}{end}&quot;
</code></pre>
<p>to get all the events of the pod with timestamps</p>
