k8s nodePort类型的service,session保持



apiVersion: v1
kind: Service
metadata:
  name: helloworldsvc
  labels:
    weblogic-app: helloworld
spec:
  type: NodePort
  ports:
  - port: 7001
    protocol: TCP
    targetPort: 7001
    name: http
    nodePort: 30005
  selector:
    weblogic-app: helloworld
  sessionAffinity: ClientIP
sessionAffinityConfig:
clientIP:
timeoutSeconds: 10800

最核心就是最后那句,会基于客户端访问服务的ip进行hash运算后把同一ip的请求路由到同一个pod.这样通过nodePort方式过来的请求就不会到处分发了.下面的timeoutSeconds指的是session保持的时间,这个时间默认是10800秒,也就是三个小时。那么原理是啥呢?当不设置session保持时,service向后台pod转发规则是轮询。当设置了session保持之后,k8s会根据访问的ip来把请求转发给他以前访问过的pod,这样session就保持住了。

 
 

 

 

 
posted @ 2021-09-11 20:48  浪淘沙&  阅读(551)  评论(0编辑  收藏  举报