ownerReferences in K8S

For the definition of ownerReferences in K8S, I won't duplicate it here. More details could be found here. Below is an example of the ownerReferences field of a Pod which is created by a ReplicaSet.

apiVersion: v1
kind: Pod
metadata:
  ...
  ownerReferences:
  - apiVersion: apps/v1
    controller: true
    blockOwnerDeletion: true
    kind: ReplicaSet
    name: my-repset
    uid: d9607e19-f88f-11e6-a518-42010a800195
  ...

Terminology

Owner: In the case of ReplicaSet and Pod, the owner of Pod is ReplicaSet .

Dependents: In the case of ReplicaSet and Pod, the Pod is the dependent of ReplicaSet.

Things you might be interested in

Cross-namespace owner references are disallowed by design

This means: 1) Namespace-scoped dependents can only specify owners in the same namespace, and owners that are cluster-scoped. 2) Cluster-scoped dependents can only specify cluster-scoped owners, but not namespace-scoped owners.

metadata.ownerReferences.controller: true

If this object is managed by a controller, then an entry in this list will point to this controller, with the controller field set to true. There cannot be more than one managing controller.

From the documentation, it says If true, this refrence points to the managing controller. In other words, the owner. The Garbage Collector's behavior of current object is under the instruction of its owner. If controller:false , the Garbage Collector manages the object freely.

Someone has asked this question here.

Why ownerReferences field is a slice

// List of objects depended by this object. If ALL objects in the list have
// been deleted, this object will be garbage collected. If this object is managed by a controller,
// then an entry in this list will point to this controller, with the controller field set to true.
// There cannot be more than one managing controller.
// +optional
// +patchMergeKey=uid
// +patchStrategy=merge
OwnerReferences []OwnerReference `json:"ownerReferences,omitempty" patchStrategy:"merge" patchMergeKey:"uid" protobuf:"bytes,13,rep,name=ownerReferences"`

From the code, there could be multiple owners of this object. But need to do more research on the real world case.

Last updated