0

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.

Also I wonder if my app can send http request to outside of the pod during this period.

What is wrong here actually ?

user1474111
  • 1,356
  • 3
  • 23
  • 47

1 Answers1

1

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
yip102011
  • 751
  • 4
  • 11
  • The format I posted above is auto format after I enter as command: [sleep 60]. When I manually edit as you mentioned above it complains. – user1474111 Aug 03 '23 at 11:10
  • it is array, you need comma in between `command: ['sleep', '60']` – yip102011 Aug 03 '23 at 11:11
  • thanks a lot you are right I was aware missing comma. Is it possible to send http request outside of the pod during that time ? I am receiving refuse during that period. – user1474111 Aug 03 '23 at 11:22