kubernetes - 在 Kubernetes 中什么是 deletecollection?
问题描述
列出 K8s 中的所有 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 序列更好,如果它确实做了我认为它应该做的事情。即删除某种类型的所有pod。
解决方案
动词是delete
指删除单个资源,例如单个 Pod。动词是指同时deletecollection
删除多个资源,例如使用标签或字段选择器的多个 Pod 或命名空间中的所有 Pod。
从 API 文档中举一些例子:
- 要删除单个 Pod:
DELETE /api/v1/namespaces/{namespace}/pods/{name}
- 要删除多个 Pod(或,
deletecollection
):- 命名空间中的所有 pod
DELETE /api/v1/namespaces/{namespace}/pods
- 命名空间中与给定标签选择器匹配的所有 pod:
DELETE /api/v1/namespaces/{namespace}/pods?labelSelector=someLabel%3dsomeValue
- 命名空间中的所有 pod
关于 kubectl:您不能deletecollection
使用kubectl
.
相反,kubectl
将自行推断是否使用delete
或deletecollection
取决于您如何调用kubectl delete
. 当删除单个源(kubectl delete pod $POD_NAME
)时,kubectl 将使用delete
调用,当使用标签选择器或简单地删除所有 Pod(kubectl delete pods -l $LABEL=$VALUE
或kubectl delete pods --all
)时,它将使用deletecollection
动词。
推荐阅读
- android - 我可以修改“工具”命名空间吗?
- java - KStream 是否一次处理一条消息?
- prolog - Prolog clpfd中所有不同的全局约束
- arrays - Powershell数组排序并分离成两个不同的数组
- spring-boot - 创建名为“gemfireCache”的 bean 时出错:FactoryBean 在创建对象时抛出异常
- android - 如何在 android pie(9) 设备中获取当前 wifi 连接名称?
- swift - 在 webview 中打印 pdf 文件
- json - 如何通过传递变量(参数)来获取api数据?
- c# - 应用程序直接运行,但在 Clickonce 发布后不运行
- angularjs - 如何使用 Angular js 在同一页面内链接?