在Kubernetes中,什么是deletecollection?

时间:2019-07-19 16:42:43

标签: kubernetes kubectl

列出K8中的所有API资源时,您会得到:

# production
# /build <= comment out this line

许多列举动词$ 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

我也无法在文档中找到它,除了它出现在上面的api-resources输出中或作为动词提及的地方。

是否可以删除收藏集?

听起来好像比我通常会做的grep / awk / xargs顺序好,如果它做了我认为应该做的事情。即删除某种类型的所有吊舱。

2 个答案:

答案 0 :(得分:2)

delete动词是指删除单个资源,例如单个Pod。 deletecollection动词是指同时删除多个资源,例如,使用标签或字段选择器删除多个Pod,或者删除命名空间中的所有Pod。

要提供API文档中的一些示例:

  1. delete a single PodDELETE /api/v1/namespaces/{namespace}/pods/{name}
  2. delete multiple Pods(或deletecollection):
    1. 命名空间DELETE /api/v1/namespaces/{namespace}/pods中的所有pod
    2. 名称空间中与给定标签选择器匹配的所有Pod:DELETE /api/v1/namespaces/{namespace}/pods?labelSelector=someLabel%3dsomeValue

关于kubectl:您不能使用deletecollection显式调用kubectl

相反,kubectl会根据您调用delete的方式自行推断是使用deletecollection还是kubectl delete。删除单个来源(kubectl delete pod $POD_NAME)时,kubectl将使用delete调用,而使用标签选择器或仅删除所有Pod(kubectl delete pods -l $LABEL=$VALUEkubectl delete pods --all)时,它将使用deletecollection动词。

答案 1 :(得分:0)

DeleteCollection不是命令。

[创建删除deletecollection获取列表补丁更新监视]

Kubernetes称之为“动词”,它们用于定义对象:Role或ClusterRole,如以下Yaml文件。

apiVersion:rbac.authorization.k8s.io/v1

种类:角色

元数据:

命名空间:默认

名称:pod-reader

规则:

  • apiGroups:[“”]#“”表示核心API组

    资源:[“豆荚”]

    动词:[“ get”,“ watch”,“ list”,“ delete”,“ deletecollection”]