kubernetesgraceful-shutdown

Kubernetes preStop hook does not sleep


I am trying to add preStop hook to my k8s container but for some reason sleep seems like it does not work. I tried to add echo and in that case I can see that it work. But when I replace echo with sleep it seems like it does not work and sleep because pod is removed before given number of seconds in the sleep command.

lifecycle:
        preStop:
          exec:
            command:
              - sleep 60

Note than my gracefulTerminationPeriod is above 60.


Solution

  • see doc https://kubernetes.io/docs/tasks/configure-pod-container/attach-handler-lifecycle-event/

    command and args much write in array format, you cannot just use space

    lifecycle:
            preStop:
              exec:
                command:
                  - sleep
                  - 60