gpt4 book ai didi

kubernetes - 如何对 Kubernetes 服务的请求使用 session 亲和性?

转载 作者:行者123 更新时间:2023-12-03 21:17:09 25 4
gpt4 key购买 nike

我找不到指定当附属部署使用多个副本扩展时 Kubernetes 服务行为方式的文档。

我假设有某种负载平衡。是否与服务类型有关?

此外,我希望在服务转发的请求中具有某种关联性(即,如果可能,所有具有特定后缀的请求应始终映射到同一个 pod,等等)。这是可以实现的吗?我看到的关闭是 Ambassador ,但这是服务级别的亲和力,而不是 pod 级别。

最佳答案

部署:无状态工作负载

I could not find a documentation that specifies how Kubernetes service behaves when the affiliated deployment is scaled with multi replicas.


使用 Deployment 部署的 Pod应该是无状态的。
入口到服务路由
使用时 Ingress ,L7-proxy,路由可以基于http请求内容,但这取决于你使用的IngressController是什么实现。例如 Ingress-nginx对粘性 session 有一些支持,其他实现可能有你正在寻找的东西。例如 Istio已支持类似设置。
大使
Ambassador你写的也有一些对 session 亲和性/粘性 session 的支持。

Configuring sticky sessions makes Ambassador route requests to the same backend service in a given session. In other words, requests in a session are served by the same Kubernetes pod


Pod 到 Service 路由
当集群中的 Pod 向集群内的 Service 发出 http 请求时, kube-proxy does routing循环赛默认方式。

By default, kube-proxy in userspace mode chooses a backend via a round-robin algorithm.


如果您希望 pod 到服务路由上的 session 亲缘关系,您可以设置 SessionAffinity: ClientIP字段 Service对象。

If you want to make sure that connections from a particular client are passed to the same Pod each time, you can select the session affinity based on client’s IP addresses by setting service.spec.sessionAffinity to “ClientIP” (the default is “None”).

关于kubernetes - 如何对 Kubernetes 服务的请求使用 session 亲和性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58955409/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com