我在 2 天前接到了设置 Kubernetes 设置的任务,但我没有该技术的背景。如果我的问题或设置不好,我们深表歉意。
拓扑非常简单,一个公共(public) IP,一个专用的 HA 代理,配置为将请求转发到包含部署的 Kubernetes 服务 2 个 pod 。 (需要粘性!)
Service setup
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": "api-admin2",
"namespace": "default",
"selfLink": "/api/v1/namespaces/default/services/api-admin2",
"uid": "98121d0d-698b-11e8-8d90-262e68d4dba8",
"resourceVersion": "245163",
"creationTimestamp": "2018-06-06T13:14:50Z",
"labels": {
"app": "api-admin"
},
"annotations": {
"service.beta.kubernetes.io/azure-load-balancer-internal": "true"
}
},
"spec": {
"ports": [
{
"protocol": "TCP",
"port": 80,
"targetPort": 6543,
"nodePort": 31302
}
],
"selector": {
"app": "api-admin"
},
"clusterIP": "10.100.22.118",
"type": "LoadBalancer",
"sessionAffinity": "ClientIP",
"externalTrafficPolicy": "Local",
"healthCheckNodePort": 32660,
"sessionAffinityConfig": {
"clientIP": {
"timeoutSeconds": 10800
}
}
},
"status": {
"loadBalancer": {
"ingress": [
{
"ip": "10.100.21.97"
}
]
}
}
}
流量到达 pod 但不是循环,所有流量都进入同一个 pod。为了让流量流向另一个 pod,我必须阻止获得它的那个……这不是这个的目的……
知道如何通过粘性正确地对流量进行负载平衡吗?
谢谢!
最佳答案
来自 proxy mode: IPVS 的服务文档:
In any of these proxy model, any traffic bound for the Service’s IP:Port is proxied to an appropriate backend without the clients knowing anything about Kubernetes or Services or Pods.
Client-IP
based session affinity can be selected by setting service.spec.sessionAffinity to“ClientIP”
(the default is“None”
), and you can set the max session sticky time by setting the fieldservice.spec.sessionAffinityConfig.clientIP.timeoutSeconds
if you have already setservice.spec.sessionAffinity to “ClientIP”
(the default is “10800”).
在您的配置中,负责选择 pod 的 session 亲和性设置为 clientIP,这意味着 10800 是粘性时间,如果所有流量来自同一客户端,它们将被转发到同一 pod 3 小时。
如果您还想指定时间,则需要更改以下内容:
sessionAffinityConfig:
clientIP:
timeoutSeconds: _TIME_
这将允许您更改生病时间,因此如果您将 TIME 更改为 10,该服务将每 10 秒切换一次 pod。
关于Kubernetes - 流量总是重定向到同一个 pod,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50737766/