在查看文档时,有一个API调用可以删除单个pod,但是否有一种方法可以删除所有名称空间中的所有pod ?
当前回答
我创建了一个python代码删除所有在命名空间
delall.py
import json,sys,os;
obj=json.load(sys.stdin);
for item in obj["items"]:
os.system("kubectl delete " + item["kind"] + "/" +item["metadata"]["name"] + " -n yournamespace")
然后
kubectl get all -n kong -o json | python delall.py
其他回答
如果你有hpa,那么缩小。
我尝试了这里列出的答案中的命令,但豆荚卡在终止状态。 我发现下面的命令可以删除特定名称空间中的所有pods,如果处于终止状态或无法删除它,那么可以强制删除pods。
kubectl delete pods --all --grace-period=0 --force --namespace namespace
希望对别人有用。
你只需要sed这样做:
kubectl get pods --no-headers=true --all-namespaces |sed -r 's/(\S+)\s+(\S+).*/kubectl --namespace \1 delete pod \2/e'
解释道:
use command kubectl get pods --all-namespaces to get the list of all pods in all namespaces. use --no-headers=true option to hide the headers. use s command of sed to fetch the first two words, which represent namespace and pod's name respectively, then assemble the delete command using them. the final delete command is just like: kubectl --namespace kube-system delete pod heapster-eq3yw. use the e modifier of s command to execute the command assembled above, which will do the actual delete works.
为了避免在kube-system namespace中删除pods,只需要在sed命令前添加grep -v kube-system排除kube-system namespace即可。
下面是一个单行程序,可以使用grep进行扩展以按名称过滤。
kubectl get pods -o jsonpath="{.items[*].metadata.name}" | \
tr " " "\n" | \
xargs -i -P 0 kubectl delete pods {}
如果你有多个pod崩溃或出错,你想删除它们
Kubectl delete pods——all -n | gep
推荐文章
- Kubernetes支持多个环境(Staging、QA、生产等)
- Kubernetes API -获取特定节点上的pod
- 我如何调试“ImagePullBackOff”?
- 在Kubernetes中更新configmap时重新启动pod ?
- 为部署的Kubernetes服务获取YAML ?
- 如何在kubernetes中切换命名空间
- 位于另一个名称空间中的服务
- 命名空间“卡住”作为终止,我如何删除它
- Kubernetes如何使部署更新映像
- 如何在gcloud和minikube之间切换kubectl集群
- 如何让容器在Kubernetes上运行?
- 如何手动触发Kubernetes计划作业?
- 如何从Kubernetes复制控制器的所有pod中获取日志?
- 删除Kubernetes pod时重新创建
- 使用/healthz进行应用程序运行状况检查的约定来自哪里?