>我已经生成了一堆如下所示的命名空间,现在我想只删除这些命名空间而不删除kube系统命名空间,我尝试使用grep但没有成功
Kubectl delete namespaces | grep "gatling*" 错误:提供了资源,但未指定名称、标签选择器或 --all 标志
多个命名空间
首先获取要删除的命名空间的名称:
kubectl get namespaces --no-headers=true -o custom-columns=:metadata.name | grep gatling
对于-o custom-columns=:metadata.name
,我们只输出服务的名称。输出通过管道传输到grep
,通过查找gatling
来过滤它们。
然后对每一行运行删除命令,xargs
:
kubectl get namespaces --no-headers=true -o custom-columns=:metadata.name | grep gatling | xargs kubectl delete namespace