注意:建议做好备份,以免误删数据丢失,本教程只做演示。
完整的k8s教程资料可访问:https://blog.tag.gg/showinfo-3-36255-0.html
删除pod
删除指定pod。删除pod对应的yaml文件即可。
执行后显示:kubectl delete -f secret-vol.yaml
删除所有pod:删除后会自动生成新pod(删除前务必确认是否需要,不然数据丢失无法找回)[root@master ~]# kubectl delete -f secret-vol.yaml
pod "mypod" deleted
谨慎操作:不然数据丢失无法找回,建议做好备份后操作。
[root@master ~]# kubectl delete Pod --all
pod "ds-test-crpsf" deleted
pod "ds-test-glnql" deleted
pod "hello-28040482-kzd6c" deleted
pod "hello-28040483-j9chm" deleted
pod "hello-28040484-xwkh8" deleted
pod "myapp-deploy-54fd65cd-x84gx" deleted
pod "myapp-deploy-54fd65cd-z9f2m" deleted
pod "myapp-deploy-s-s-66f44577d5-ngnfq" deleted
pod "myapp-deploy-s-s-66f44577d5-q9b2f" deleted
pod "myjob-fp4bl" deleted
pod "web-statefulset-0" deleted
pod "web-statefulset-1" deleted
pod "web-statefulset-2" deleted
[root@master ~]#
另外的删除命令:
谨慎操作:建议做好备份后操作
删除后会重新生成新的pod,kubectl delete pod nginx-565fdsfs5656-4wxza
这是因为当前Pod是由Pod控制器创建的,控制器会监控Pod状况,一旦发现Pod死亡,会立即重建此时要想删除Pod,必须删除Pod控制器先来查询一下当前namespace下的Pod控制器
执行后如下:kubectl get deployment
可以看到一个Nginx,然后,删除这个nginx即可。[root@master ~]# kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
nginx 1/1 1 1 3d1h
执行如下:kubectl delete deployment nginx
再次查看:[root@master ~]# kubectl delete deployment nginx
deployment.apps "nginx" deleted
此时pod节点也无法打开了,确认是删除了。[root@master ~]# kubectl get deployment
No resources found in default namespace.
[root@master ~]# kubectl get pod
No resources found in default namespace.
删除service
查看service情况可执行如下命令
或kubectl get pod,svc
执行后如下:kubectl get service
我们要删除nginx、web11和web21[root@master ~]# kubectl get pod,svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 8d
service/nginx NodePort 10.96.241.120 <none> 80:31261/TCP 8d
service/web11 ClusterIP 10.100.177.151 <none> 80/TCP 2d19h
service/web21 NodePort 10.111.156.174 <none> 80:31990/TCP 28m
[root@master ~]# kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 8d
nginx NodePort 10.96.241.120 <none> 80:31261/TCP 8d
web11 ClusterIP 10.100.177.151 <none> 80/TCP 2d19h
web21 NodePort 10.111.156.174 <none> 80:31990/TCP 36m
执行后如下:kubectl delete svc nginx
再次查看service已经删除了[root@master ~]# kubectl delete svc nginx
service "nginx" deleted
[root@master ~]# kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 8d
文章评论 本文章有个评论