how does tcp connection works in kubernetes loadbalancer

7/13/2021

Hi I am running 5 replicas tcp-client( can be scaled up) and exposed 3 services as LoadBalancer to external network to get incoming connection. This client is listining on a port 7777 internally and mapped to external port 17777, 27777, 37777.

Pods

[root@pwconfig-k8s-master0 tcp_poc]# kubectl get pods -l app=tcp-client
NAME                          READY   STATUS    RESTARTS   AGE
tcp-client-7dd545dcc9-54bdl   1/1     Running   0          4m47s
tcp-client-7dd545dcc9-628jn   1/1     Running   0          4m47s
tcp-client-7dd545dcc9-7pm44   1/1     Running   0          2m30s
tcp-client-7dd545dcc9-b287n   1/1     Running   0          4m47s
tcp-client-7dd545dcc9-mrmnm   1/1     Running   0          2m30s

Service

[root@pwconfig-k8s-master0 tcp_poc]# kubectl get svc | grep tcp-client
tcp-client        ClusterIP      y.y.y.y    <none>         7777/TCP                              4m36s
tcp-client-0      LoadBalancer   y.y.y.y   x.x.x.x   17777:30859/TCP                       2m55s
tcp-client-1      LoadBalancer   y.y.y.y     x.x.x.x   27777:30089/TCP                       2m55s
tcp-client-2      LoadBalancer   y.y.y.y    x.x.x.x   37777:31031/TCP                       2m55s

We have seen this behavior that once any external client makes the tcp connection, the connection get fixed with particular pod and stay alive until external client closes the connection. I wanted to know the how the routing and tcp connection is working as I can see the LoadBalancing is over external client tcp connection not over the packets. So if there are 100 external client , it will loadbalance over the client and route the tcp connection and fix with the pod for the lifecycle of the tcp connection.

Thanks for the help in advanced.

-- Hackaholic
kubernetes
kubernetes-ingress
load-balancing
tcp
tcpclient

0 Answers