Graceful pod termination

后端 未结 2 646
耶瑟儿~
耶瑟儿~ 2021-01-14 10:08

I need to let the container to run 5 minutes after the kubectl \' termination. It needs to do some work before it\'s destroyed. It seems that kubernetes contain

相关标签:
2条回答
  • 2021-01-14 10:50

    You may be able to set magic sleep in 'preStop' hook. This hook will be extecuted prior to kubectl sending SIGTERM to your container.

    http://kubernetes.io/docs/user-guide/production-pods/#lifecycle-hooks-and-termination-notice

    something like:

    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
      name: nginx
    spec:
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx
            ports:
            - containerPort: 80
            lifecycle:
              preStop:
                exec:
                  command: ["/bin/sleep","300"]
    
    0 讨论(0)
  • 2021-01-14 11:00

    https://pracucci.com/graceful-shutdown-of-kubernetes-pods.html may this can help you.

    There’re some circumstances where a SIGTERM violently kill the application, vanishing all your efforts to gracefully shutdown it. Nginx, for example, quickly exit on SIGTERM.

    0 讨论(0)
提交回复
热议问题