在查看文档时,有一个API调用可以删除单个pod,但是否有一种方法可以删除所有名称空间中的所有pod ?
当前回答
你可以使用kubectl删除pods -l dev-lead!=carisa或其他标签。
其他回答
你只需要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 delete -n *NAMESPACE deployment *DEPLOYMENT
只需将NAMSPACE和DEPLOYMENT替换为相应的NAMSPACE和DEPLOYMENT,就可以通过以下命令获得所有部署信息
kubectl get deployments --all-namespaces
如果你想删除所有命名空间中的pod,只是为了让它们重新启动,并且你知道其中一些将被重新创建,我喜欢下面的for循环:
for i in $(kubectl get pods -A | awk '{print $1}' | uniq | grep -V NAMESPACE); do kubectl delete --all pods -n $i; done
kubectl delete po,ing,svc,pv,pvc,sc,ep,rc,deploy,replicaset,daemonset --all -A
K8s完全在命名空间的基础上工作。如果要释放与指定命名空间相关的所有资源。
你可以使用下面提到的:
kubectl delete namespace k8sdemo-app
推荐文章
- Kubectl连续日志
- 我的kubernetes豆荚不断崩溃与“CrashLoopBackOff”,但我找不到任何日志
- 如何从kubectl配置中删除集群和上下文?
- Kubernetes支持多个环境(Staging、QA、生产等)
- Kubernetes API -获取特定节点上的pod
- 我如何调试“ImagePullBackOff”?
- 在Kubernetes中更新configmap时重新启动pod ?
- 为部署的Kubernetes服务获取YAML ?
- 如何在kubernetes中切换命名空间
- 位于另一个名称空间中的服务
- 命名空间“卡住”作为终止,我如何删除它
- Kubernetes如何使部署更新映像
- 如何在gcloud和minikube之间切换kubectl集群
- 如何让容器在Kubernetes上运行?
- 如何手动触发Kubernetes计划作业?