I have a headless k8s service for which the local DNS resolver gives all the IPs of the pods sitting behind the service. The requests made to the service are not getting load balanced with go1.22.7 and all the requests go to a single pod. The HTTP client is invoked using the following snippet:
Requests made from the above with go1.23.1 are getting load balanced appropriately(not sure if it’s round robin though). I compared the transport logic for both the versions but couldn’t find anything concrete which could cause this problem. Can you experts please help me out?
If you are aware of the presence of a cache for DNS resolution, you can either pass in a new DNS resolver or write a simple DNS process for resolving domain names.
IIUC, DNS cache (if at all used) should be present in the library only. I am trying to understand the reason for the difference between the two versions. Just to clarify - I have the run the exact same code (shared above) on the same setup and experienced difference in resolution w.r.t different go versions.
Well, it’s common to have problems with go version differences (I’ve had it a few times). I don’t think there’s any other way to do it than if you look at the differences in the source code.
I think it’s imperative to avoid such a serious discrepancy (or to update your own Go development environment)
Since headless services return the individual pod IPs, the client (in this case, your Go application) is responsible for implementing load balancing. If the Go application is only hitting one of the pods consistently, it may appear that load balancing is not occurring.