Imagine the following deployment definition in kubernetes:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
env: staging
spec:
...
I have two questions in particular:
1). The label env: staging
won't be available in created pods. how can I access this data programmatically in client-go
?
2). When pod is created/updated, how can I found which deployment it belongs to?
You can get the
Deployment
using client-go. See the example Create, Update & Delete Deployment for operations on aDeployment
.When a
Deployment
is created, a ReplicaSet is created that manage thePods
.See the
ownerReferences
field of aPod
to see whatReplicaSet
manages it. This is described in How a ReplicaSet works