k8s中pod删不掉

将相本无种,男儿当自强。这篇文章主要讲述k8s中pod删不掉相关的知识,希望能为你提供帮助。
问题现象:pod一直删除不掉
【k8s中pod删不掉】起因:在pod运行过程中,修改了其deployment,导致pod一直删不掉操作过程:

  1. 删除pod,删不掉
  2. 强制删除pod,依然删除不了
  3. 删除deployment,旧的pod依然删不掉,因为deployment已经发生变更
  4. 查看pod的详情,发现如下ReplicaSet有关内容
kubectl get pods -n architect wx-xxx-luna-5b5755b69-zwrhb -oyaml
apiVersion: v1
kind: Pod
metadata:
annotations:
cni.projectcalico.org/podIP: 10.82.61.151/32
izone: default
kubectl.kubernetes.io/restartedAt: "2020-06-28T22:45:46+08:00"
sidecar.istio.io/status: {"version":"761ebc5a63976754715f22fcf548f05270fb4b8db07324894aebdb31fa81d960","initContainers":["istio-init"],"containers":["istio-proxy"],"volumes":["istio-envoy","istio-certs"],"imagePullSecrets":null}
creationTimestamp: "2021-05-28T04:29:27Z"
generateName: wx-xxx-luna-5b5755b69-
labels:
app: wx-xxx-luna
pod-template-hash: 5b5755b69
version: luna
name: wx-xxx-luna-5b5755b69-zwrhb
namespace: architect
ownerReferences:
- apiVersion: apps/v1
blockOwnerDeletion: true
controller: true
kind: ReplicaSet
name: wx-xxx-luna-5b5755b69
..............

  1. 删除这个ReplicaSet,pod被顺利删除
kubectl get pods -n architect |grep wx-xxx-luna
wx-xxx-luna-5b5755b69-zwrhb2/2Terminating014m
wx-xxx-luna-7b8f7f895d-8lnkh2/2Running06m31s

分析:
  1. 当我们通过deployment创建pod时,首先会调用deployment-controller控制器创建ReplicaSet yaml并写入etcd数据库
  2. ReplicaSet controller根据该ReplicaSet yaml向k8s apiserver请求创建pod
  3. 然后才是scheduler调度资源,kubelet创建pod
所以,Deployment删除之后,ReplicaSet并未删除,还是能让pod处于正常的运行状态。只有将rc、rs、job也删除,才能删除对应的pod。

    推荐阅读