3

Currently it takes quite a long time before the pod can be terminated after a kubectl delete command. I have the feeling that it could be because of the sleep command.

How can I make the container stop faster? What best practices should I use here?

apiVersion: apps/v1
kind: Deployment
...
spec:
  template:
    spec:
      containers:
        - image: alpine
          ..
          command:
            - /bin/sh
            - -c
            - |
              trap : TERM INT 
              while true; do
                # some code to check something
                sleep 10
              done

Is my approach with "trap: TERM INT" correct? At the moment I don't see any positive effect...

When I terminate the pod it takes several seconds for the command to come back.

kubectl delete pod my-pod
user5580578
  • 1,134
  • 1
  • 12
  • 28

1 Answers1

2

Add terminationGracePeriodSeconds to your spec will do:

...
spec:
  template:
    spec:
      terminationGracePeriodSeconds: 10  # <-- default is 30, can go as low as 0 to send SIGTERM immediately.
      containers:
        - image: alpine
gohm'c
  • 13,492
  • 1
  • 9
  • 16