1)概括

Kubernetes控制器的删除有3种模式:
a、Foreground:
删除控制器之前,先删除控制器所管理的资源对象删除。
b、Background:
删除控制器后,控制器所管理的资源对象由GC在后台进行删除。
c、Orphan:
只删除控制器,不删除控制器所管理的资源对象。


2)rest api格式(以Deployment控制器为例):

a、只删除控制器(对应ReplicSet和Pod不删除)

DELETE /apis/apps/v1/namespaces/{namespace}/deployments/{name}
{
“Kind”: “DeleteOptions”,
“apiVersion”: “v1”,
“propagationPolicy”: “Orphan”
}

b、前台级联删除(按照Pod->ReplicaSet->Deployment的顺序进行删除)

DELETE /apis/apps/v1/namespaces/{namespace}/deployments/{name}
{
“kind”: “DeleteOptions”,
“apiVersion”: “v1”,
“propagationPolicy”: “Foreground”
}

c、后台级联删除(按照Deployment->ReplicaSet->Pod的顺序进行删除)

DELETE /apis/apps/v1/namespaces/{namespace}/deployments/{name}
{
“kind”: “DeleteOptions”,
“apiVersion”: “v1”,
“propagationPolicy”: “Background”
}


3)例子:

a、Orphan模式例子

删除请求的请求体中指定了模式是Orphan:
{
“Kind”: “DeleteOptions”,
“apiVersion”: “v1”,
“propagationPolicy”: “Orphan”
}
在这里插入图片描述
发现:控制器所管理的pod对象并没有被删除
在这里插入图片描述

b、Background模式例子

使用kubectl删除控制器,查看具体的命令详细,发现是Background模式:
-bash-4.2# kubectl delete ds nginx-ingress-controller -n ingress-nginx -v 10

I0730 11:54:08.751432 22493 loader.go:359] Config loaded from file: /root/.kube/config
I0730 11:54:08.752544 22493 cached_discovery.go:114] returning cached discovery info from /root/.kube/cache/discovery/192.168.35.75_16443/servergroups.json
I0730 11:54:08.753276 22493 cached_discovery.go:71] returning cached discovery info from /root/.kube/cache/discovery/192.168.35.75_16443/authorization.k8s.io/v1/serverresources.json
I0730 11:54:08.753301 22493 cached_discovery.go:71] returning cached discovery info from /root/.kube/cache/discovery/192.168.35.75_16443/metrics.k8s.io/v1beta1/serverresources.json



I0730 11:54:08.794908 22493 request.go:947] Request Body: {“propagationPolicy”:“Background”}
I0730 11:54:08.795008 22493 round_trippers.go:419] curl -k -v -XDELETE -H “Accept: application/json” -H “Content-Type: application/json” -H “User-Agent: kubectl/v1.15.1 (linux/amd64) kubernetes/4485c6f” ‘https://192.168.35.75:16443/apis/extensions/v1beta1/namespaces/ingress-nginx/daemonsets/nginx-ingress-controller’
I0730 11:54:08.823891 22493 round_trippers.go:438] DELETE https://192.168.35.75:16443/apis/extensions/v1beta1/namespaces/ingress-nginx/daemonsets/nginx-ingress-controller 200 OK in 28 milliseconds
I0730 11:54:08.823918 22493 round_trippers.go:444] Response Headers:
I0730 11:54:08.823931 22493 round_trippers.go:447] Content-Type: application/json
I0730 11:54:08.823939 22493 round_trippers.go:447] Content-Length: 201
I0730 11:54:08.823947 22493 round_trippers.go:447] Date: Tue, 30 Jul 2019 03:54:08 GMT
I0730 11:54:08.823983 22493 request.go:947] Response Body: {“kind”:“Status”,“apiVersion”:“v1”,“metadata”:{},“status”:“Success”,“details”:{“name”:“nginx-ingress-controller”,“group”:“extensions”,“kind”:“daemonsets”,“uid”:“2918e9da-70d9-4752-bdd2-a26c1dea607e”}}
daemonset.extensions “nginx-ingress-controller” deleted

Logo

开源、云原生的融合云平台

更多推荐