收到SIGTERM后,Kubernetes吊舱是否仍然收到请求? [英] Do Kubernetes pods still receive requests after receiving SIGTERM?

查看:97
本文介绍了收到SIGTERM后,Kubernetes吊舱是否仍然收到请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Kubernetes Pod中实现正常关机.我知道我需要听SIGTERM,这表明关闭过程已开始.但是收到后我该怎么办?

I want to implement graceful shutdown in a Kubernetes Pod. I know I need to listen for SIGTERM, which indicates the start of the shutdown procedure. But what exactly do I do when I receive it?

至少我必须等待所有正在运行的请求完成才能退出.但是,在收到SIGTERM之后,pod还能接收新的请求吗? (它是通过服务公开的.)我在此上找不到任何明确的文档.

At the very least I must wait for all running request to finish before exiting. But can the pod still receive new requests after receiving the SIGTERM? (It's exposed using a service.) I can't find any explicit documentation on this.

文档状态:

已将Pod从端点列表中删除以进行服务,并且不再将其视为复制控制器正在运行的Pod集中的一部分.缓慢关闭的Pod可以继续充当流量,因为负载均衡器(如服务代理)会将其从轮换中移除.

Pod is removed from endpoints list for service, and are no longer considered part of the set of running pods for replication controllers. Pods that shutdown slowly can continue to serve traffic as load balancers (like the service proxy) remove them from their rotations.

因此,这似乎意味着仍然可以接收新请求.那么在正常终止之前,我应该继续期待新请求多长时间?我是否只是忽略SIGTERM,继续照常服务请求并等待最终的SIGKILL?

So that seems to imply that new requests can still come in. So how long should I continue to expect new requests before graceful termination? Do I simply ignore the SIGTERM, continue to serve requests as usual and wait for the eventual SIGKILL?

我想确保将来的准备情况检查失败,然后等待比检查发生的时间更长的时间才能终止?

I suppose ensuring future readiness checks fail and then waiting longer than the period with which they occur before terminating might work?

我正在使用Kubernetes 1.2.5,如果有什么不同的话,我不仅在谈论滚动更新,而且还在总体上缩减复制控制器.

I'm on Kubernetes 1.2.5, if that makes any difference, and am talking about rolling updates in particular, but also scaling replication controllers down generally.

推荐答案

我进行了一些实验以确切地了解会发生什么.

I ran some experiments to find out exactly what happens.

吊舱短暂地(<1s)在启动关闭后继续接收请求,因此您需要捕获SIGTERM或安装preStop钩子,以便可以等待它们(并完成当前的服务)请求).

The pod will briefly (<1s) continue receiving requests after shutdown is initiated, so you need to either catch SIGTERM or install a preStop hook so you can wait for them (and finish serving current requests).

但是,一旦启动关闭,就绪探测就不再重要,您无需更改其状态即可停止接收请求. (但在此之前,失败的准备就绪探针 会导致您的广告连播没有收到更多流量.)

However, once the shutdown has been initiated, the readiness probe no longer matters, you don't need to change its state to stop receiving requests. (But before that a failing readiness probe will lead to your pod receiving no more traffic.)

这篇关于收到SIGTERM后,Kubernetes吊舱是否仍然收到请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆