介绍
在 kubernetes 中我们可以访问直接访问 service 与后端 pod 进行沟通,那么 Service 是如何选取 Deployment 的呢?
kube-proxy
service 的流量转发是通过 kube-proxy 进行的,kube-proxx 的实现目前有几种:
- userspace
- iptables
- ipvs
其中 iptables 通过 随机数实现负载均衡。
而 ipvs 支持较多,如下所示
- rr:round-robin/轮询
- lc:least connection/最少连接
- dh:destination hashing/目标哈希
- sh:source hashing/源哈希
- sed:shortest expected delay/预计延迟时间最短
- nq:never queue/从不排队
userspace、iptables、ipvs 三种模式中默认的负载均衡策略都是通过 round-robin 算法来选择后端 pod 的
userspace、iptables、ipvs 三种模式中默认的负载均衡策略都是通过 round-robin 算法来选择后端 pod 的,在 service 中可以通过设置 service.spec.sessionAffinity 的值实现基于客户端 ip 的会话亲和性,service.spec.sessionAffinity 的值默认为"None",可以设置为 "ClientIP",此外也可以使用 service.spec.sessionAffinityConfig.clientIP.timeoutSeconds 设置会话保持时间。
网友评论