<p>I want to be able to know the Kubernetes uid of the Deployment that created the pod, from within the pod.</p>
<p>The reason for this is so that the Pod can spawn another Deployment and set the <code>OwnerReference</code> of that Deployment to the original Deployment (so it gets Garbage Collected when the original Deployment is deleted).</p>
<p>Taking inspiration from <a href="https://stackoverflow.com/questions/42274229/kubernetes-deployment-name-from-within-a-pod">here</a>, I've tried*:</p>
<ol>
<li>Using field refs as env vars:</li>
</ol>
<pre class="lang-yaml prettyprint-override"><code>containers:
  - name: test-operator
    env:
      - name: DEPLOYMENT_UID
        valueFrom: 
          fieldRef: {fieldPath: metadata.uid}
</code></pre>
<ol start="2">
<li>Using <code>downwardAPI</code> and exposing through files on a volume:</li>
</ol>
<pre class="lang-yaml prettyprint-override"><code>containers:
  volumeMounts:
    - mountPath: /etc/deployment-info
      name: deployment-info
volumes:
  - name: deployment-info
    downwardAPI:
      items:
      - path: &quot;uid&quot;
        fieldRef: {fieldPath: metadata.uid}
</code></pre>
<p>*Both of these are under <code>spec.template.spec</code> of a resource of kind: Deployment.</p>
<p>However for both of these the uid is that of the Pod, not the Deployment. Is what I'm trying to do possible?</p>

James Cockbain
<p>The behavior is correct, the <code>Downward API</code> is for <code>pod</code> rather than <code>deployment/replicaset</code>.</p>
<p>So I guess the solution is set the name of deployment manually in <code>spec.template.metadata.labels</code>, then adopt <code>Downward API</code> to inject the labels as env variables.</p>
