- Learn OpenShift
- Denis Zuev Artemii Kropachev Aleksey Usov
- 220字
- 2021-08-13 16:03:52
Deleting Kubernetes resources
If we've done something wrong with the pod, or it may have broken for some reason, there is a simple way to delete a pod using the kubectl delete pod command:
$ kubectl delete pod httpd-8576c89d7-qjd62
pod "httpd-8576c89d7-qjd62" deleted
We can delete all pods using the --all option:
$ kubectl delete pod --all
pod "httpd-8576c89d7-qjd62" deleted
pod "httpd1-c9f7d7fd9-rn2nz" deleted
pod "httpd2-5b4ff5cf57-vlhb4" deleted
Note that if you run kubectl get pods, you will see all the containers running again. The reason for this is that, when we run the kubectl run command, it creates several different Kubernetes resources, which we are going to discuss in the following section.
We can delete Kubernetes resources by running kubectl delete all with the -l option:
$ kubectl delete all -l app=httpd-demo1
deployment "httpd1" deleted
pod "httpd1-c9f7d7fd9-d9w94" deleted
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
httpd-8576c89d7-qjd62 1/1 Running 0 17m
httpd2-5b4ff5cf57-9llkn 1/1 Running 0 15s
This command will delete all Kubernetes with a httpd-demo1 label only. The other two pods will be still available.
Alternatively, we can delete all Kubernetes resources we have created so far by running the kubectl delete all --all command:
$ kubectl delete all --all
deployment "httpd" deleted
deployment "httpd2" deleted
pod "httpd-8576c89d7-ktnwh" deleted
pod "httpd2-5b4ff5cf57-t58nd" deleted
service "kubernetes" deleted
service "nginx-exposed" deleted
推薦閱讀
- Linux運維之道(第3版)
- BPEL and Java Cookbook
- Windows Phone 7.5 Data Cookbook
- 開源安全運維平臺OSSIM疑難解析:入門篇
- 嵌入式操作系統(Linux篇)(微課版)
- Windows Server 2012網絡操作系統企業應用案例詳解
- Linux內核設計的藝術:圖解Linux操作系統架構設計與實現原理
- Django Project Blueprints
- CSS揭秘
- OpenStack Essentials(Second Edition)
- Mastering Azure Serverless Computing
- Website Development with PyroCMS
- Serverless Architectures with Kubernetes
- 蘋果派
- Linux內核設計的藝術:圖解Linux操作系統架構設計與實現原理(第2版)