kubernetes: Long Lived TCP Connections Fail When Downscaling Kube Proxy (ExternalTrafficPolicy Cluster)
What happened?
Some external cloud providers such as Azure use a pass-through(direct server return) load balancer. This means that TCP connections are not terminated on the loadbalancer, but instead downstream in the kubernetes cluster.
ExternalTrafficPolicy Cluster configures load balancers to send traffic to any node in the cluster, even if the node is not running a pod that the traffic is destined to. From there kube-proxy routes the request to the pod (which could either be on the same or different node).
In our case, when client sets up a long living TCP connection and that traffic path hits kube-proxy on a node that downscales sometime during the duration of the TCP connection, we observe 520 errors from the server.
What did you expect to happen?
Kubernetes nodes that act as a intermediate hop between the loadbalancer and the node/pod that the traffic is destined to should gracefully allow all existing TCP connections to finish before the node/processes are terminated.
This is important because some loadbalancers like Azure continue to send traffic to existing TCP even though the target node has been marked unheathly.
How can we reproduce it (as minimally and precisely as possible)?
- Setup any service (e.g., nginx ingress), tolerated/tainted to node group A. Use loadbalancer with external traffic policy: cluster.
- Scale node pool B.
- Simulate many http requests, targetting loadbalancer endpoint of service created in step 1
- Scale down node pool B.
- Observe errors on requests that proxied through scaled down node in node pool B.
Anything else we need to know?
No response
Kubernetes version
1.30
Cloud provider
OS version
# On Linux:
$ cat /etc/os-release
# paste output here
$ uname -a
# paste output here
# On Windows:
C:\> wmic os get Caption, Version, BuildNumber, OSArchitecture
# paste output here
Install tools
Container runtime (CRI) and version (if applicable)
Related plugins (CNI, CSI, …) and versions (if applicable)
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (10 by maintainers)
@elmiko, I have not personally verified this issue on other platforms, but I did find this issue in the autoscaler repo since creating this issue:
https://github.com/kubernetes/autoscaler/issues/1907
Based on my understanding of the issue, it doesn’t seem to be resolved. Most/all of the workarounds described by end-users are AWS specific implementations.
In addition to AWS and Azure, I believe that GCP would be suceptible to this as well as it uses a pass-through loadbalancer.
I do suspect there might be a need for cloud-specific solutions to this, as each cloud’s LB has its own idiosyncracies. For instance, Azure LBs are pass-through and also, upon a node being marked unhealthy, all existing TCP connections to said node will continue to be passed through to it. Moreover, there is no draining concept in the loadbalancer (other than health checks).
I mention this despite the fact that the autoscaler/service controller does not seem to mark the node as unhealthy in the AZ loadbalancer before terminating it anyway.