在Kubernetes中,什么是deletecollection? [英] In Kubernetes what is deletecollection?

查看:71
本文介绍了在Kubernetes中,什么是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文档中的一些示例,请执行以下操作:

  1. 删除单个Pod :DELETE /api/v1/namespaces/{namespace}/pods/{name}
  2. 删除多个豆荚(或deletecollection):

    1. 命名空间DELETE /api/v1/namespaces/{namespace}/pods
    2. 中的所有Pod
    3. 命名空间中与给定标签选择器匹配的所有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=$VALUEkubectl 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:

  1. To delete a single Pod: DELETE /api/v1/namespaces/{namespace}/pods/{name}
  2. To delete multiple Pods (or, deletecollection):

    1. All pods in a namespace DELETE /api/v1/namespaces/{namespace}/pods
    2. All pods in a namespace matching a given label selector: DELETE /api/v1/namespaces/{namespace}/pods?labelSelector=someLabel%3dsomeValue

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆