<p>I want to use the time that a pod is deployed as an environment variable within the pod.
I cannot seem to make this work though. Anybody have an example on how to do this or maybe some pointers?</p>

Karim Tawfik
<p>If you are using simple pods, then this solution won't work for you. Because pod's env field becomes immutable once created.</p>
<p>But if you are using managed pods ( i.e. deployment, statefulset etc), you can use <code>kubectl set env</code> command to update environment variables.</p>
<pre class="lang-sh prettyprint-override"><code>$ kubectl get deployment nginx-deployment -o=jsonpath='{.metadata.creationTimestamp}'
2020-10-07T13:24:49Z

$ kubectl set env deployment/nginx-deployment CREATIONTIME=$(kubectl get deployment nginx-deployment -o=jsonpath='{.metadata.creationTimestamp}')
deployment.apps/nginx-deployment env updated

$ kubectl exec -it nginx-deployment-7657f96b7f-6w8lf -- env
... ... ...
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=nginx-deployment-7657f96b7f-6w8lf
NGINX_VERSION=1.15.4-1~stretch
NJS_VERSION=1.15.4.0.2.4-1~stretch
CREATIONTIME=2020-10-07T13:24:49Z
... ... ...
</code></pre>
<p>Deployment file I used - <a href="https://github.com/kubernetes-client/python/blob/master/examples/nginx-deployment.yaml" rel="nofollow noreferrer">Link</a></p>
