Load balancer
Load balancers automatically and efficiently distribute network traffic between multiple backend servers. A load balancer setup can be used in CSM Operator to expose your Kafka brokers to the outside world.
There are many load balancer implementations available and all cloud providers provide their own solutions. Different implementations handle load balancing on different levels of the network, most commonly you have layer 4 (transport) and layer 7 (application) load balancing. CSM Operator uses layer 4 load balancing. This is because common load balancer implementations do not support the Kafka protocol.
In CSM Operator, you set up external cluster access using load
balancers by adding a loadbalancer
type listener to your Kafka resource
(listeners.type:loadbalancer
).
- A load balancer and a corresponding LoadBalancer Service that serves as an external bootstrap. This is used by clients for the initial connection and to receive metadata (advertised listeners) from the Kafka cluster.
- A unique load balancer and a LoadBalancer Service for each Kafka Broker.
CSM Operator creates the LoadBalancer type Services first. Following the creation of the Services, the load balancers are automatically created. Typically your infrastructure provider assigns the load balancer a hostname and IP address. These are automatically added to the status section of the Kafka resource. CSM Operator collects both hostname and IP address and uses them to configure the advertised listeners of your Kafka brokers.
CSM Operator uses hostnames instead of IP addresses by default. This is because load balancer IP addresses might change, the hostnames, however, are fixed and remain the same as long as the load balancer is running. By default, CSM Operator uses the IP address if there is no hostname assigned to the load balancer. In case you want to use IP addresses, you can do so by manually configuring them during setup.
Once the listener is configured, you can connect your clients running outside of the Kubernetes network by directing them to the bootstrap load balancer. The load balancers, Kubernetes, and Kafka handle everything else and ensure that client requests are routed to the correct brokers.
Configuring load balancer listeners
Complete the following steps to set up and configure a loadbalancer listener in CSM Operator. The following steps also include an example on how to connect a Kafka console client to the cluster.
These steps demonstrate basic listener configuration with typical customizations. In
addition to the configuration shown here, you can further customize your listener
and enable and disable TLS encryption using the tls
property,
specify a client authentication mechanism with the authentication
property, as well as add various additional configurations using the
configuration
property. For a comprehensive list of available
properties, see the GenericKafkaListener schema reference in the
Strimzi API reference.