kubelet删除pod异步操作

基本流程

1. kube-apiserver把Pod设置为Terminating状态。
2. 从Service中异步删除Endpoint。
3. 异步执行preStop Hook。
4. 异步发送SIGTERM信号。
5. 等待terminationGracePeriodSeconds(默认值为 30 秒)。
6. 超时后同步发送SIGKILL信号。

gracePeriodSeconds要大于preStop时间,避免出现preStop未执行完毕,pod已被kill的情况。

验证terminationGracePeriodSeconds

cat <<EOF | kubectl create -f -
apiVersion: apps/v1
kind: Deployment
metadata:
  name: busybox-deploy
spec:
  replicas: 1
  selector:
    matchLabels:
      app: busybox
  template:
    metadata:
      labels:
        app: busybox
    spec:
      containers:
      - name: busybox
        image: docker.io/library/busybox:1.32
        command: ["/bin/sh", "-c", "while true; do sleep 1; done"]
EOF

cat <<EOF | kubectl create -f -
apiVersion: apps/v1
kind: Deployment
metadata:
  name: busybox-deploy
spec:
  replicas: 1
  selector:
    matchLabels:
      app: busybox
  template:
    metadata:
      labels:
        app: busybox
    spec:
      terminationGracePeriodSeconds: 5
      containers:
      - name: busybox
        image: docker.io/library/busybox:1.32
        command: ["/bin/sh", "-c", "while true; do sleep 1; done"]
EOF

验证kubelet删除pod时会等cni完成

使用kube-ovn前提下,先删除ovs-ovn ds,再删除coredns pod,一直卡在Terminating,因为ovs-cni会因没有ovs-ovn而异常。

参考资料

https://zhuanlan.zhihu.com/p/466309880?utm_id=0

posted on 2023-09-19 22:15  王景迁  阅读(53)  评论(0)    收藏  举报

导航