其他分享
首页 > 其他分享> > 09-K8S Basic-kubernetes垃圾回收器 Garbage Collection(GC)

09-K8S Basic-kubernetes垃圾回收器 Garbage Collection(GC)

作者:互联网

一、Kubernetes之Garbage Collection

1.1、从对象与根对象(Owners and dependents)

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: my-repset
spec:
  replicas: 3
  selector:
    matchLabels:
      pod-is-for: garbage-collection-example
  template:
    metadata:
      labels:
        pod-is-for: garbage-collection-example
    spec:
      containers:
      - name: nginx
 
 
创建此ReplicaSet:
    kubectl create -f https://k8s.io/examples/controllers/replicaset.yaml
 
 
查看:
    kubectl get pods --output=yaml
 
 
结果如下:确认ownerReferences的值
apiVersion: v1
kind: Pod
metadata:
  ...
  ownerReferences:
  - apiVersion: apps/v1
    controller: true
    blockOwnerDeletion: true
    kind: ReplicaSet
    name: my-repset
    uid: d9607e19-f88f-11e6-a518-42010a800195

1.2、如何控制垃圾回收删除从对象?

1.2.1、前台级联删除

1.2.2、后台级联删除

1.2.3、不删除从对象

1.3、在具体操作时设置删除策略

kubectl proxy --port=8080
curl -X DELETE localhost:8080/apis/apps/v1/namespaces/default/replicasets/my-repset \
-d '{"kind":"DeleteOptions","apiVersion":"v1","propagationPolicy":"Background"}' \
-H "Content-Type: application/json"
kubectl proxy --port=8080
curl -X DELETE localhost:8080/apis/apps/v1/namespaces/default/replicasets/my-repset \
-d '{"kind":"DeleteOptions","apiVersion":"v1","propagationPolicy":"Foreground"}' \
-H "Content-Type: application/json"
kubectl proxy --port=8080
curl -X DELETE localhost:8080/apis/apps/v1/namespaces/default/replicasets/my-repset \
-d '{"kind":"DeleteOptions","apiVersion":"v1","propagationPolicy":"Orphan"}' \
-H "Content-Type: application/json"
kubectl delete replicaset my-repset --cascade=false
# 当--cascade为true时,kubectl采用的是前台级联删除还是后台级联删除,文档中没有讲。

1.4、级联删除Deployment时的注意点

标签:kubectl,级联,删除,kubernetes,v1,对象,Collection,ReplicaSet,Garbage
来源: https://www.cnblogs.com/dai-zhe/p/14881465.html