Kubernetes Pod预热以实现负载平衡 [英] Kubernetes Pod warm-up for load balancing

查看:176
本文介绍了Kubernetes Pod预热以实现负载平衡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个Kubernetes服务,其Pod需要一些时间来准备第一个请求.基本上,第一个传入请求将从Redis读取一些缓存的值,并且这些请求可能需要更长的时间才能处理.当这些新创建的Pod准备就绪并接收全部流量时,在从Redis正确加载并缓存所有内容之前,它们可能在长达30秒的时间内反应迟钝.

We are having a Kubernetes service whose pods take some time to warm up with first requests. Basically first incoming requests will read some cached values from Redis and these requests might take a bit longer to process. When these newly created pods become ready and receive full traffic, they might become not very responsive for up to 30 seconds, before everything is correctly loaded from Redis and cached.

我知道,我们绝对应该对应用程序进行重组,以防止出现这种情况,很不幸,这在不久的将来是不可行的(我们正在努力).

I know, we should definitely restructure the application to prevent this, unfortunately that is not feasible in a near future (we are working on it).

如果有可能减少新创建的Pod的重量,那将是很好的,因此,随着时间的流逝,它们在开始时会收到1/10的流量,而重量会增加.这对于我们新部署的应用程序版本查看其是否正常也非常有用.

It would be great if it was possible to reduce the weight of the newly created pods, so they would receive 1/10 of the traffic in the beggining with the weight increasing as the time would pass. This would be also great for newly deployed versions of our application to see if it behaves correctly.

推荐答案

直到可以对应用程序进行重组以在内部进行此启动"为止.

Until the application can be restructured to do this "priming" internally...

对于在Kubernetes上运行时,请查看容器生命周期挂钩并专门插入PostStart挂钩.文档此处和示例此处.

For when running on Kubernetes, look into Container Lifecycle Hooks and specifically into the PostStart hook. Documentation here and example here.

似乎"......在postStart处理程序完成之前,容器的状态未设置为RUNNING"的行为可以为您提供帮助.

It seems that the behavior of "...The Container's status is not set to RUNNING until the postStart handler completes" is what can help you.

很少有类似"...无法保证钩子在容器ENTRYPOINT之前执行"的陷阱,因为"... postStart处理程序相对于容器的代码异步运行",而"...没有参数"传递给处理程序".

There's are few gotchas like "... there is no guarantee that the hook will execute before the container ENTRYPOINT" because "...The postStart handler runs asynchronously relative to the Container’s code", and "...No parameters are passed to the handler".

也许自定义脚本可以使用某些重试逻辑来模拟第一个请求,以等待应用程序启动?

Perhaps a custom script can simulate that first request with some retry logic to wait for the application to be started?

这篇关于Kubernetes Pod预热以实现负载平衡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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