k8s pod 如何删除
Posted 开飞机的苏克_Sucre
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了k8s pod 如何删除相关的知识,希望对你有一定的参考价值。
在k8s 里面如果直接删除pod,, 是起不到作用的,因为删除的pod 还是被继续拉起来。
看下面的例子,我们把 deployment-ngx-8ff559dc9-5v5f7 这个pod 通过kubectl delete pod 的方式删除掉
[root@k8s-master ~]# kubectl get pods NAME READY STATUS RESTARTS AGE deployment-ngx-8ff559dc9-5v5f7 1/1 Running 0 10m deployment-ngx-8ff559dc9-xcskd 1/1 Running 0 10m test 1/1 Running 0 22h test-nginx 1/1 Running 0 22h [root@k8s-master ~]# kubectl delete deployment-ngx-8ff559dc9-5v5f7 error: the server doesn\'t have a resource type "deployment-ngx-8ff559dc9-5v5f7" [root@k8s-master ~]# kubectl delete pod deployment-ngx-8ff559dc9-5v5f7 pod "deployment-ngx-8ff559dc9-5v5f7" deleted [root@k8s-master ~]# kubectl get pods -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES deployment-ngx-8ff559dc9-br8ww 0/1 ContainerCreating 0 15s <none> k8s-node1 <none> <none> deployment-ngx-8ff559dc9-xcskd 1/1 Running 0 10m 10.244.36.74 k8s-node1 <none> <none> test 1/1 Running 0 22h 10.244.36.68 k8s-node1 <none> <none> test-nginx 1/1 Running 0 22h 10.244.169.131 k8s-node2 <none> <none>
但是又立马重启了一个新的同类型的pod。
是因为deployment 控制replicasSet,, 当副本数跟实际的不相符的时候,rs 会自动再创建新的,直到跟模板上的一致
那么问题来了,要想删除pod 该怎么办呢
其实通过删除deployment,, 然后机会自动删除pod
[root@k8s-master ~]# kubectl delete deployment deployment-ngx deployment.apps "deployment-ngx" deleted [root@k8s-master ~]# kubectl get deployment No resources found in default namespace. [root@k8s-master ~]# kubectl get pods NAME READY STATUS RESTARTS AGE deployment-ngx-8ff559dc9-br8ww 0/1 Terminating 0 6m10s deployment-ngx-8ff559dc9-xcskd 0/1 Terminating 0 16m test 1/1 Running 0 22h test-nginx 1/1 Running 0 22h
以上是关于k8s pod 如何删除的主要内容,如果未能解决你的问题,请参考以下文章