Categorygithub.com/go-tk/kubetransport
modulepackage
0.2.3
Repository: https://github.com/go-tk/kubetransport.git
Documentation: pkg.go.dev

# README

kubetransport

GoDev Workflow Status Coverage Status

HTTP/2 transport wrapper for client-side load balancing in Kubernetes

Problem

When an HTTP/2 client sends a request to an HTTP/2 server, a persistent connection between the client and the server is established, and thanks to the multiplexing feature of the HTTP/2 protocol, all the subsequent requests from the client can go through this connection concurrently without establishing additional connections, which significantly improves the use of network resources.

Unfortunately, the persistent connection also comes with a side effect that it breaks the load balancing in Kubernetes. Let's say there are three server instances behind a Kubernetes Service FQDN and our client send out requests with this FQDN, which will result in a persistent connection established with only one of the server instances, and no traffic will reach the other server instances.

Solution

Kubernetes provides Endpoints API to retrieve and watch the endpoints information of a Service which contains the IP addresses of server instances. If we intercept every request sent out and replace the hostname (FQDN) in its URL with one of the IP addresses randomly, the load balancing can work again. For intercepting outgoing requests, we can simply wrap the HTTP transport.

That is all about what this package did.

# Functions

MustWrapTransport likes WrapTransport but panics when an error occurs.
WrapTransport wraps the given transport for client-side load balancing in Kubernetes.

# Variables

ErrEndpointsNotFound is returned when the endpoints does not exist.
ErrNoIPAddress is returned when there is no ip address of the endpoints.