简体   繁体   English

如何在 kubernetes 上重新启动 Pod 时处理请求?

[英]how are requests processed on pod restart on kubernetes?

I need help understanding how Kubernetes handles requests upon a pod restart.我需要帮助了解 Kubernetes 如何在 pod 重新启动时处理请求。

If I have two pods running on a Kubernetes cluster and one dies or restarts midway, does the current request that the first pod is handling get transferred to the second pod or does the current request fail?如果我有两个 Pod 在 Kubernetes 集群上运行,并且一个在中途死亡或重新启动,那么第一个 Pod 正在处理的当前请求会转移到第二个 Pod 还是当前请求失败?

Kubernetes sends traffic only when the pod is running perfectly, now if in the mean time of serving the request pod dies then that traffic will fail. Kubernetes 仅在 Pod 运行良好时发送流量,现在如果在服务请求 Pod 的同时死亡,那么流量将失败。

In ideal scenario you would want to to have all client request handled properly without any broken connections.在理想情况下,您希望正确处理所有客户端请求,而不会出现任何断开的连接。 By itself, Kubernetes does not prevent you from this. Kubernetes 本身并不会阻止您这样做。

When your pod is started, its is being added as endpoint to all the services that label selector matches the labels that place on the pod.当您的 pod 启动时,它会作为端点添加到 label 选择器与放置在 pod 上的标签匹配的所有服务中。 Pod needs to let Kubernetes know that it's ready by sending. Pod 需要通过发送让 Kubernetes 知道它已准备好。 Until this signal is being sent, it won't become service endpoint and won't receive any requests from you clients.在发送此信号之前,它不会成为服务端点,也不会收到来自您的客户端的任何请求。

If you don't specify readiness probe for your pod, it is always considered ready and it will start receiving request almost immediately (as soon as kube-proxy will update the iptables rules).如果你没有为你的 pod 指定就绪探测,它总是被认为是就绪的,它几乎会立即开始接收请求(只要 kube-proxy 更新 iptables 规则)。 In this time if you application is not ready to serve you will receive connection refused errors.此时,如果您的应用程序尚未准备好服务,您将收到连接被拒绝错误。 So having successfully probe return when you app is ready will make those error go away.因此,当您的应用程序准备就绪时成功探测返回将使这些错误 go 消失。

With pod deletion there are two things occurring in parallel, one being kubelet deleting the pod and the endpoint controller removing the service endpoint.删除 pod 时会同时发生两件事,一是 kubelet 删除 pod,端点 controller 删除服务端点。 In most causes the deletion of the pod is happening faster since endpoint removal chain is slightly longer.在大多数情况下,由于端点删除链稍长,因此删除 pod 的速度更快。 This will also means that upon deletion your pod might be deleted faster then the endpoint being removed.这也意味着在删除时,您的 pod 可能会比端点被删除更快地被删除。 Delaying that removal until endpoint is removed will also help with refused connections.延迟删除直到端点被删除也将有助于拒绝连接。

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

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