Pod termination takes long time

Pod delete takes long time

Vikash Kumar

1 minute read

Sometimes deletion of pod takes longer time. There could be multiple reasons for that. For me, it was ‘busybox’ pod. It used to take more than a minute to delete the pod. Below is the yaml.

apiVersion: v1
kind: Pod
metadata:
  name: busybox

  namespace: default
spec:
  containers:
  - image: busybox
    command:
      - sleep
      - "3600"
    imagePullPolicy: IfNotPresent
    name: busybox
  restartPolicy: Always

The real issue in above case is, ‘sleep’ in the container. Even though the graceful termination for the pod (read documentation of Pod on k8s website) is 30s, but it takes longer than that. It is always a good idea to allow the resource cleanup gracefully. But if one need to bypass the graceful termination, there are multiple ways to do it. Below are few ways.

kubectl delete pod <podname> --grace-period=0 --force

or,

kubectl delete pod <podname> --wait=false

or use TerminationGracePeriodSeconds in pod’s spec,

...
spec:
  containers:
  - image: busybox
    command:
      - sleep
      - "3600"
    imagePullPolicy: IfNotPresent
    name: busybox
  restartPolicy: Always
  TerminationGracePeriodSeconds: 0

Reference:

  1. https://github.com/kubernetes/kubernetes/issues/69851
comments powered by Disqus