1、kubectl 展示搜索出的pod列表(含pod所在的namespace)
kubectl get pod -A grep

在这里插入代码片
[root@tcs-10-21-0-157 ~]# kubectl get pod -A |grep yhl
ingress-nginx-yhl-large   yhl-large-ingress-nginx-controller-dc666995f-djk8k      1/1     Running             0          46d
ingress-nginx-yhl-large   yhl-large-ingress-nginx-controller-dc666995f-fncrq      1/1     Running             0          2m46s
ingress-nginx-yhl-large   yhl-large-ingress-nginx-controller-dc666995f-wxz2f      1/1     Running             0          4m30s
ingress-nginx-yhl         yhl-ingress-nginx-controller-fd565dddc-44z2d            1/1     Running             0          45d
ingress-nginx-yhl         yhl-ingress-nginx-controller-fd565dddc-nlst8            1/1     Running             0          45d
ingress-nginx-yhl         yhl-ingress-nginx-controller-fd565dddc-sjqx7            1/1     Running             0          45d

2、kubectl 删除pod命令
kubectl delete pod -n
在进行删除pod命令时,会发现pod并未被真正删除,原因是k8s误认为我们要删除的pod异常挂了,会启用容灾机制,导致重新在拉起一个新的pod。
故,我们想要正常且彻底的删除一个pod,必须要先破坏掉他的容灾机制,即删除deployment机制。
3、查看deployment信息
kubectl get deployment -n

[root@tcs-10-21-0-157 ~]# kubectl get deployment -n ingress-nginx-yhl
NAME                                 READY   UP-TO-DATE   AVAILABLE   AGE
yhl-ingress-nginx-controller   3/3     3            3           45d

4、删除deployment配置
kubectl delete deployment <deployment名> -n

[root@tcs-10-21-0-157 ~]# kubectl delete deployment yhl-ingress-nginx-controller -n ingress-nginx-yhl
deployment.apps "yhl-ingress-nginx-controller" deleted

5、然后进行删除pod命令即可,我删除deployment后,再次查询pod发现,上面的pod已经开始自行删除了
kubectl delete pod -n

附一个我这边删除deployment后pod自行删除的情况

root@tcs-10-21-0-157 ~]# kubectl get pod -A|grep yuhonglei
ingress-nginx-yhl   yhl-ingress-nginx-controller-fd565dddc-44z2d            1/1     Terminating         0          45d
ingress-nginx-yhl   yhl-ingress-nginx-controller-fd565dddc-nlst8            1/1     Terminating         0          45d
ingress-nginx-yhl   yhl-ingress-nginx-controller-fd565dddc-sjqx7            1/1     Terminating         0          45d```

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐