Ownership and garbage collection
Follow the owner chain
A dependent object may record its owner in metadata.ownerReferences. Kubernetes controllers usually create and manage these relationships. In a typical Deployment, the Deployment owns ReplicaSets, and each ReplicaSet owns its Pods. A ReplicaSet is a controller that maintains a target number of Pods; full Deployment behavior is covered in the next chapter. All examples are offline illustrations, not observed cluster output. Optional read-only commands require an explicitly approved disposable cluster, a separately prepared ./lab.kubeconfig, a verified bytemind-lab context and matching fixture inventory. No cluster or kubeconfig is included. Do not query an unknown context.
Deployment catalog (uid dep-01) └─ ReplicaSet catalog-rs (uid rs-01) ├─ Pod catalog-a (uid pod-01) └─ Pod catalog-b (uid pod-02)Standalone Pod catalog-debug (uid pod-03)All objects are in book-lab. The arrows show ownership from owner to dependent, even though the actual reference is stored on the dependent. The debug Pod has the same app label but no owner reference in this snapshot.
Read an owner reference
The identity in an owner reference includes the API version, kind, name and UID. The UID identifies an actual object lifetime, not merely a reusable name. controller: true indicates a managing controller; at most one owner reference on an object may be marked that way. blockOwnerDeletion participates in foreground deletion when the dependent is known to the garbage collector. Do not manually set these fields as a beginner workflow.
metadata: name: catalog-a namespace: book-lab uid: pod-01 ownerReferences: - apiVersion: apps/v1 kind: ReplicaSet name: catalog-rs uid: rs-01 controller: true blockOwnerDeletion: trueThese short UIDs are synthetic teaching values, not actual server-issued UIDs. The reference identifies the ReplicaSet. The Pod does not directly reference the Deployment; follow the ReplicaSet reference to find the Deployment.
Check valid owner scope
A namespaced dependent can reference a cluster-scoped owner, or a namespaced owner in the same namespace. A cluster-scoped dependent can reference only a cluster-scoped owner. Cross-namespace references to namespaced owners are not allowed. An invalid cross-namespace reference is treated as absent; if all owners are confirmed absent the dependent may be collected. A cluster-scoped dependent referring to a namespaced kind is unresolvable and is not collected on that basis. These are different failure cases. Never create invalid ownership to experiment on a real cluster.
kubectl --kubeconfig ./lab.kubeconfig --context bytemind-lab -n book-lab get pod/catalog-a -o jsonpath='{.metadata.ownerReferences}'kubectl --kubeconfig ./lab.kubeconfig --context bytemind-lab -n book-lab get rs/catalog-rs -o jsonpath='{.metadata.ownerReferences}'On a matching approved lab, these show the dependent references; JSONPath output may omit a final newline. Compare the UID with the actual owner UID when investigating replacement. The offline ownership-graph.json supplies the relevant fields instead.
What happens when an owner is removed?
Garbage collection can clean dependent API objects when their owners are gone. With background cascading deletion, the owner is removed when its own finalizers allow it; dependent cleanup continues asynchronously. With foreground deletion, the owner enters a deleting state and eligible blocking dependents are processed before removal. Orphan deletion retains the dependents rather than cascading to them. These modes describe API object cleanup, not guarantees about data backups or instantaneous application shutdown. Multiple valid owners, finalizers and controller activity can change the outcome.
Background: owner removed, dependents cleaned laterForeground: owner deleting, blocking dependents processedOrphan: owner removed, direct dependents retainedAssume a single owner per dependent, no extra finalizers or concurrent changes, and a functioning garbage collector. Orphaning the Deployment retains its ReplicaSet and the Pods still owned by that ReplicaSet. This is a prediction exercise, not a deletion command.
Selection is not ownership
A label query for app=catalog returns both controlled Pods and catalog-debug in the synthetic snapshot. It does not prove that the debug Pod belongs to the ReplicaSet. In a real cluster, an eligible matching unowned Pod may be adopted by a controller, so the snapshot is not a guarantee of future state. A new owner with the same name but a new UID is not the former owner. A finalizer is a cleanup gate, not a backup or a timeout. If an object is stuck deleting, inspect its controller and cleanup obligations; never blindly remove finalizers.
Practice: trace before cleanup
Use ownership-graph.json and deletion-cases.json to trace the owner chain and predict direct and indirect dependents for each policy. Explain why the debug Pod is not a cascading dependent in this fixed snapshot. Do not run deletion commands. Next, learn how ReplicaSets and Deployments maintain replica counts and perform updates.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Ownership and garbage collection — knowledge check
Apply the lesson concepts to original offline scenarios.
In the graph, what directly owns catalog-a?
Why compare owner UIDs instead of names alone?
Which owner relationship is invalid?
In the fixed graph, what does orphan deletion of the Deployment retain?
Does the app=catalog label alone make catalog-debug a cascading dependent?