apiVersion: v1
kind: Pod
metadata:
...
ownerReferences:
- apiVersion: apps/v1
controller: true
blockOwnerDeletion: true
kind: ReplicaSet
name: my-repset
uid: d9607e19-f88f-11e6-a518-42010a800195
...
The role of the Kubernetes garbage collector is to delete certain objects that once had an owner, but no longer have an owner.
Deleting dependents automatically is called cascading deletion
有兩種級聯(lián)刪除
background and foreground
There are two modes of cascading deletion: background and foreground.
orphaned
If you delete an object without deleting its dependents automatically, the dependents are said to be orphaned.
Foreground cascading deletion
在前臺級聯(lián)刪除中罪既,根對象首先進入“正在刪除”狀態(tài)
- 通過REST API,對象仍然可見
- 對象的deletionTimestamp被設(shè)置
- 對象的元數(shù)據(jù)袍祖。終結(jié)器包含值“foregroundDeletion”
一旦設(shè)置了“正在刪除”狀態(tài)勋陪,垃圾收集器就會刪除對象的依賴項决侈。一旦垃圾收集器刪除了所有的“阻塞”依賴項(ownerreference.blockownerdelete =true的對象)铅协,它就會刪除owner對象
Background cascading deletion
Kubernetes立即刪除owner對象刷钢,垃圾收集器然后刪除后臺的依賴項
To delete dependents automatically using kubectl, set --cascade to true
To orphan dependents, set --cascade to false.
The default value for --cascade is true.
Here's an example that orphans the dependents of a ReplicaSet:
kubectl delete replicaset my-repset --cascade=false