<p>Imagine the following deployment definition in kubernetes:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
 name: nginx-deployment
 labels:
  env: staging
spec:
...
</code></pre>
<p>I have two questions in particular:</p>
<p>1). The label <code>env: staging</code> won't be available in created pods. how can I access this data programmatically in <code>client-go</code>?</p>
<p>2). When pod is created/updated, how can I found which deployment it belongs to?</p>

<blockquote>
<p>1). the label env: staging won't be available in created pods. how can I access this data programmatically in client-go?</p>
</blockquote>
<p>You can get the <code>Deployment</code> using client-go. See the example <a href="https://github.com/kubernetes/client-go/tree/master/examples/create-update-delete-deployment" rel="nofollow noreferrer">Create, Update &amp; Delete Deployment</a> for operations on a <code>Deployment</code>.</p>
<blockquote>
<p>2). when pod is created/updated, how can I found which deployment it belongs to?</p>
</blockquote>
<p>When a <code>Deployment</code> is created, a <a href="https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/" rel="nofollow noreferrer">ReplicaSet</a> is created that manage the <code>Pods</code>.</p>
<p>See the <code>ownerReferences</code> field of a <code>Pod</code> to see what <code>ReplicaSet</code> manages it. This is described in <a href="https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/#how-a-replicaset-works" rel="nofollow noreferrer">How a ReplicaSet works</a></p>
