> For the complete documentation index, see [llms.txt](https://daniel-guo.gitbook.io/notebook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://daniel-guo.gitbook.io/notebook/miscellaneous/owners-and-dependents-in-k8s.md).

# ownerReferences in K8S

For the definition of `ownerReferences` in K8S, I won't duplicate it here. More details could be found [here](https://kubernetes.io/docs/concepts/workloads/controllers/garbage-collection/#owners-and-dependents). 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](https://github.com/kubernetes/apimachinery/blob/master/pkg/apis/meta/v1/types.go#L305), 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](https://stackoverflow.com/questions/51068026/when-exactly-do-i-set-an-ownerreferences-controller-field-to-true).

### 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](https://github.com/kubernetes/apimachinery/blob/master/pkg/apis/meta/v1/types.go#L247), there could be multiple owners of this object. But need to do more research on the real world case.&#x20;
