在查看文档时,有一个API调用可以删除单个pod,但是否有一种方法可以删除所有名称空间中的所有pod ?


当前回答

你只需要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即可。

其他回答

你只需要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即可。

仅删除所有命名空间中的所有pod(重新启动部署)

 kubectl get pod -A -o yaml | kubectl delete -f -

一行命令删除所有命名空间中的所有pod。

kubectl get ns -o=custom-columns=Namespace:.metadata.name --no-headers | xargs -n1 kubectl delete pods --all -n

删除pv的步骤如下:

删除所有与该PV相关的部署和pod或资源 Kubectl delete——all deployment -n namespace Kubectl delete——所有pod -n命名空间 编辑光伏 Kubectl编辑pv pv_name -n namespace 删除kubernetes.io / pv-protection 删除pv Kubectl delete pv pv_name -n namespace

如果您已经有了重新创建的pod,请考虑先删除所有部署

kubectl delete -n *NAMESPACE deployment *DEPLOYMENT

只需将NAMSPACE和DEPLOYMENT替换为相应的NAMSPACE和DEPLOYMENT,就可以通过以下命令获得所有部署信息

kubectl get deployments --all-namespaces