Kubernetes是否支持连接排空? [英] Does Kubernetes support connection draining?

查看:127
本文介绍了Kubernetes是否支持连接排空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Kubernetes是否支持连接排空?

Does Kubernetes support connection draining?

例如,我的部署推出了Web应用程序容器的新版本. 在连接排空模式下,Kubernetes应该从新映像启动一个新容器,并将进入我的服务的所有新流量路由到该新实例.旧实例应保留足够长的时间,以便为现有连接发送响应.

For example, my deployment rolls out a new version of my web app container. In connection draining mode Kubernetes should spin up a new container from the new image and route all new traffic coming to my service to this new instance. The old instance should remain alive long enough to send a response for existing connections.

推荐答案

Kubernetes 支持,但它的发生方式由Pod控制,称为

Kubernetes does support connection draining, but how it happens is controlled by the Pods, and is called graceful termination.

让我们以通过服务提供流量的一组Pod为例.这是一个简化的示例,有关详细信息,请参见文档.

Let's take an example of a set of Pods serving traffic through a Service. This is a simplified example, the full details can be found in the documentation.

  1. 系统(或用户)通知API Pod需要停止.
  2. Pod设置为Terminating状态.这会将其从服务流量中删除.现有的连接会保留,但是一旦负载均衡器识别到更改,新的连接应立即停止.
  3. 系统将SIGTERM发送到Pod中的所有容器.
  4. 系统等待terminationGracePeriodSeconds(默认30秒),或者直到Pod自行完成.
  5. 如果Pod中的容器仍在运行,则将其发送给SIGKILL并立即终止.此时,如果Pod仍在运行,则将其强制终止.
  1. The system (or a user) notifies the API that the Pod needs to stop.
  2. The Pod is set to the Terminating state. This removes it from a Service serving traffic. Existing connections are maintained, but new connections should stop as soon as the load balancers recognize the change.
  3. The system sends SIGTERM to all containers in the Pod.
  4. The system waits terminationGracePeriodSeconds (default 30s), or until the Pod completes on it's own.
  5. If containers in the Pod are still running, they are sent SIGKILL and terminated immediately. At this point the Pod is forcefully terminated if it is still running.

这不仅涵盖了简单的终止情况,而且在滚动更新部署中使用了完全相同的过程,每个Pod均以完全相同的方式终止,并有机会进行清理.

This not only covers the simple termination case, but the exact same process is used in rolling update deployments, each Pod is terminated in the exact same way and is given the opportunity to clean up.

如果您未在应用中处理SIGTERM,则Pod会立即终止,因为SIGTERM的默认操作是立即终止该过程,并且由于Pod退出而未使用宽限期

If you do not handle SIGTERM in your app, your Pods will immediately terminate, since the default action of SIGTERM is to terminate the process immediately, and the grace period is not used since the Pod exits on its own.

如果您需要连接消耗",这是在Kubernetes中实现它的基本方法:

If you need "connection draining", this is the basic way you would implement it in Kubernetes:

  1. 处理SIGTERM信号,并以应用程序决定的方式清理连接.这可能只是不执行任何操作"以允许清除机上连接.长时间运行的连接可能会以对客户端应用程序更友好的方式终止.
  2. 设置terminationGracePeriodSeconds足够长的时间,以便Pod可以自行清理.
  1. Handle the SIGTERM signal, and clean up your connections in a way that your application decides. This may simply be "do nothing" to allow in-flight connections to clear out. Long running connections may be terminated in a way that is (more) friendly to client applications.
  2. Set the terminationGracePeriodSeconds long enough for your Pod to clean up after itself.

这篇关于Kubernetes是否支持连接排空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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