在Kubernetes中,什么是deletecollection? [英] In Kubernetes what is deletecollection?
问题描述
列出K8中的所有API资源时,您会得到:
$ kubectl api-resources -owide
NAME SHORTNAMES APIGROUP NAMESPACED KIND VERBS
bindings true Binding [create]
componentstatuses cs false ComponentStatus [get list]
configmaps cm true ConfigMap [create delete deletecollection get list patch update watch]
endpoints ep true Endpoints [create delete deletecollection get list patch update watch]
events ev true Event [create delete deletecollection get list patch update watch]
limitranges limits true LimitRange [create delete deletecollection get list patch update watch]
namespaces ns false Namespace [create delete get list patch update watch]
nodes no false Node [create delete deletecollection get list patch update watch]
persistentvolumeclaims pvc true PersistentVolumeClaim [create delete deletecollection get list patch update watch]
persistentvolumes pv false PersistentVolume [create delete deletecollection get list patch update watch]
pods po true Pod [create delete deletecollection get list patch update watch]
podtemplates true PodTemplate [create delete deletecollection get list patch update watch]
replicationcontrollers rc true ReplicationController [create delete deletecollection get list patch update watch]
resourcequotas quota true ResourceQuota [create delete deletecollection get list patch update watch]
secrets true Secret [create delete deletecollection get list patch update watch]
serviceaccounts sa true ServiceAccount [create delete deletecollection get list patch update watch]
services svc true Service [create delete get list patch update watch]
mutatingwebhookconfigurations admissionregistration.k8s.io false MutatingWebhookConfiguration [create delete deletecollection get list patch update watch]
... etc ...
许多列举动词deletecollection
听起来很有用,但我无法运行它,例如
$ kubectl deletecollection
Error: unknown command "deletecollection" for "kubectl"
Run 'kubectl --help' for usage.
unknown command "deletecollection" for "kubectl"
我也无法在文档中找到它,除了它出现在上面的api-resources输出中或作为动词提及的地方.
是否可以删除收藏集?
听起来好像比我通常会做的grep/awk/xargs顺序好,如果它做了我认为应该做的事情.即删除某种类型的所有吊舱.
delete
动词表示删除单个资源,例如单个Pod. deletecollection
动词指的是同时删除多个资源,例如,使用标签或字段选择器删除多个Pod,或者删除命名空间中的所有Pod.
要提供API文档中的一些示例,请执行以下操作:
- 要删除单个Pod :
DELETE /api/v1/namespaces/{namespace}/pods/{name}
- 要删除多个豆荚(或
deletecollection
):- 命名空间
DELETE /api/v1/namespaces/{namespace}/pods
中的所有Pod
- 命名空间中与给定标签选择器匹配的所有Pod:
DELETE /api/v1/namespaces/{namespace}/pods?labelSelector=someLabel%3dsomeValue
- 命名空间
关于kubectl:您不能使用kubectl
显式调用deletecollection
.
相反,kubectl
会根据您调用kubectl delete
的方式自行推断是使用delete
还是deletecollection
.在删除单个源(kubectl delete pod $POD_NAME
)时,kubectl将使用delete
调用,而在使用标签选择器或仅删除所有Pod(kubectl delete pods -l $LABEL=$VALUE
或kubectl delete pods --all
)时,它将使用deletecollection
动词. /p>
When listing all the API resources in K8s you get:
$ kubectl api-resources -owide
NAME SHORTNAMES APIGROUP NAMESPACED KIND VERBS
bindings true Binding [create]
componentstatuses cs false ComponentStatus [get list]
configmaps cm true ConfigMap [create delete deletecollection get list patch update watch]
endpoints ep true Endpoints [create delete deletecollection get list patch update watch]
events ev true Event [create delete deletecollection get list patch update watch]
limitranges limits true LimitRange [create delete deletecollection get list patch update watch]
namespaces ns false Namespace [create delete get list patch update watch]
nodes no false Node [create delete deletecollection get list patch update watch]
persistentvolumeclaims pvc true PersistentVolumeClaim [create delete deletecollection get list patch update watch]
persistentvolumes pv false PersistentVolume [create delete deletecollection get list patch update watch]
pods po true Pod [create delete deletecollection get list patch update watch]
podtemplates true PodTemplate [create delete deletecollection get list patch update watch]
replicationcontrollers rc true ReplicationController [create delete deletecollection get list patch update watch]
resourcequotas quota true ResourceQuota [create delete deletecollection get list patch update watch]
secrets true Secret [create delete deletecollection get list patch update watch]
serviceaccounts sa true ServiceAccount [create delete deletecollection get list patch update watch]
services svc true Service [create delete get list patch update watch]
mutatingwebhookconfigurations admissionregistration.k8s.io false MutatingWebhookConfiguration [create delete deletecollection get list patch update watch]
... etc ...
Many list the verb deletecollection
which sounds useful, but I can't run it e.g.
$ kubectl deletecollection
Error: unknown command "deletecollection" for "kubectl"
Run 'kubectl --help' for usage.
unknown command "deletecollection" for "kubectl"
Nor can I find it in the docs except where it appears in the api-resources output above or mentioned as a verb.
Is there a way to deletecollection?
It sounds like it would be better than the sequence of grep/awk/xargs that I normally end up doing if it does do what I think it should do. i.e. delete all the pods of a certain type.
The delete
verb refers to deleting a single resource, for example a single Pod. The deletecollection
verb refers to deleting multiple resources at the same time, for example multiple Pods using a label or field selector or all Pods in a namespace.
To give some examples from the API documentation:
- To delete a single Pod:
DELETE /api/v1/namespaces/{namespace}/pods/{name}
- To delete multiple Pods (or,
deletecollection
):- All pods in a namespace
DELETE /api/v1/namespaces/{namespace}/pods
- All pods in a namespace matching a given label selector:
DELETE /api/v1/namespaces/{namespace}/pods?labelSelector=someLabel%3dsomeValue
- All pods in a namespace
Regarding kubectl: You cannot invoke deletecollection
explicitly with kubectl
.
Instead, kubectl
will infer on its own whether to use delete
or deletecollection
depending on how you invoke kubectl delete
. When deleting a single source (kubectl delete pod $POD_NAME
), kubectl will use a delete
call and when using a label selector or simply deleting all Pods (kubectl delete pods -l $LABEL=$VALUE
or kubectl delete pods --all
), it will use the deletecollection
verb.
这篇关于在Kubernetes中,什么是deletecollection?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!