kubernetes: grace-period=0 --force Forced deletion failed

What happened?

image A case where Forced deletion does not stop! (Example: container is in sleep 9999 state) when I first kubectl delete pod --grace-perios=30 and then when kubectl delete pod --grace-perios=0 -force. The second time the force delete will not have any effect on the kubelet. According to the latest documentation, gracePeriod, when set to 0 and force, triggers the kubelet to start cleaning up immediately. But looking at the source code, I found that if gracePeriod=0 and force. kubelt triggers the handler.HandlePodRemoves function and then goes to the kl.deletePod function, which is correct. But in the real processing, the UpdatePod function is used (I looked at several versions of the code before 1.22 and they all use the deletePod function). When entering the update, there is no judgment that gracePeriod=0 and force. All as a normal updatePod to deal with, which also led to, the second gracePeriod = 0 was treated as a normal update, stored in the lastUndeliveredWorkUpdate cache. And the first delete because of the need to interact with the CRI, need to wait for the CRI to return the results, so you need to wait for the first 30s processing success before processing this forced deletion. This is not in line with the documentation logic and code logic. There should be gracePeriod=0 to handle the logic code of forced delete. Here is the source code flow. 1.kubelet.go handler.HandlePodRemoves(u.Pods) image 2.kubelet.go deletepod image 3.kubelet.go kl.podWorkers.UpdatePod() image 4. pod_workers.go image The code that follows is the gracePeriod time that is waited for when the kill container is in place. I looked at the code in version 1.19 and found that after the HandlePodRemoves function is triggered, there are two steps. 1. Close the podupdate channel and remove the lastUndeliveredWorkUpdate. 2. Open the goroutine to call CRI to remove the container. The code after version 1.22 does not have this step of the operation, that is, the abandonment of gracePeriod = 0 and force forced deletion, this problem should be marked in the documentation, but I did not see. I changed the source code locally and tested it to achieve force deletion, is this a bug and do I need to pull request?

What did you expect to happen?

After the first grace-period=30, the second grace-period=0 should be deleted immediately. Now the situation is that apiserver will delete the pod, but kubelet will not delete the container

How can we reproduce it (as minimally and precisely as possible)?

Start a container
1.docker run name sh -c “sleep 99999” 2.kubectl delete pod name --grace-period=30 3.kubectl delete pod name --grace-period=0 --force The third process will not execute successfully

Anything else we need to know?

no

Kubernetes version

$ kubectl version 1.22.2
# paste output here

Cloud provider

null

OS version

# On Linux:
$ cat /etc/os-release
# paste output here
$ uname -a
# paste output here

# On Windows:
C:\> wmic os get Caption, Version, BuildNumber, OSArchitecture
# paste output here

Install tools

Container runtime (CRI) and version (if applicable)

Related plugins (CNI, CSI, …) and versions (if applicable)

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Comments: 22 (11 by maintainers)

Most upvoted comments

/remove-lifecycle stale

/assign @haircommander

@haircommander mentioned that the issue may not exist in CRI-O with the special handling of this case. Will research and report back.

/triage accepted /priority backlog