简体   繁体   English

容器终止宽限期未得到兑现

[英]Container termination grace period is not getting honoured

We are using windows containers managed by the Kubernetes where we have the terminationGracePeriodSeconds as 10mins.我们正在使用由 Kubernetes 管理的terminationGracePeriodSeconds容器,其中 TerminationGracePeriodSeconds 为 10 分钟。 To handle the shutdown notification, we are doing something like this https://gist.github.com/darstahl/fbb80c265dcfd1b327aabcc0f3554e56 .为了处理关闭通知,我们正在执行类似https://gist.github.com/darstahl/fbb80c265dcfd1b327aabcc0f3554e56的操作。 Once we catch the SIGTERM signal, we are doing our operations of gracefully shutting down all the services.一旦我们捕捉到SIGTERM信号,我们就会优雅地关闭所有服务。 In that sequence, we have a Sleep of 30sec duration.在该序列中,我们有 30 秒的睡眠时间。

The issue is container is getting terminated when it hits the Sleep, and not continuing the further operations, though the overall termination grace period is very large.问题是容器在进入睡眠状态时会被终止,并且不会继续进一步的操作,尽管整体终止宽限期非常长。

Any idea on the issue?对这个问题有任何想法吗? and how to fix it?以及如何解决?

As I mentioned in comments I think what you need is a PreStop hook .正如我在评论中提到的,我认为您需要的是PreStop hook

Container hooks集装箱挂钩

There are two hooks that are exposed to Containers:有两个暴露给容器的钩子:

PostStart启动后

This hook executes immediately after a container is created.这个钩子在容器创建后立即执行。 However, there is no guarantee that the hook will execute before the container ENTRYPOINT.但是,不能保证钩子会在容器 ENTRYPOINT 之前执行。 No parameters are passed to the handler.没有参数传递给处理程序。

PreStop预停

This hook is called immediately before a container is terminated due to an API request or management event such as liveness probe failure, preemption, resource contention and others.由于 API 请求或管理事件(例如活动探测失败、抢占、资源争用等),在容器终止之前立即调用此挂钩。 A call to the preStop hook fails if the container is already in terminated or completed state.如果容器已经终止或完成 state,则调用 preStop 挂钩失败。 It is blocking, meaning it is synchronous, so it must complete before the call to delete the container can be sent.它是阻塞的,意味着它是同步的,所以它必须在删除容器的调用被发送之前完成。 No parameters are passed to the handler.没有参数传递给处理程序。

A more detailed description of the termination behavior can be found in Termination of Pods .终止行为的更详细描述可以在Pod 的终止中找到。


Additionally there are few tutorials with examples how PreStop hook.此外,很少有教程包含 PreStop 如何挂钩的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM