// Module included in the following assemblies:
//
// assembly-kafka-broker-external-listeners-loadbalancers.adoc

[id='con-kafka-broker-external-listeners-loadbalancers-{context}']

= Exposing Kafka using loadbalancers

When exposing Kafka using `Loadbalancer` type `Services`, a new loadbalancer service is created for every Kafka broker pod.
An additional loadbalancer is created to serve as a Kafka _bootstrap_ address.
Loadbalancers listen to connections on port 9094.

By default, TLS encryption is enabled.
To disable it, set the `tls` field to `false`.

.Example of an external listener of type `loadbalancer`
[source,yaml,subs="attributes+"]
----
# ...
listeners:
  external:
    type: loadbalancer
    authentication:
      type: tls
# ...
----

For more information on using loadbalancers to access Kafka, see xref:proc-accessing-kafka-using-loadbalancers-{context}[].

= Customizing the DNS names of external loadbalancer listeners

On `loadbalancer` listeners, you can use the `dnsAnnotations` property to add additional annotations to the loadbalancer services.
You can use these annotations to instrument DNS tooling such as {KubernetesExternalDNS}, which automatically assigns DNS names to the loadbalancer services.

.Example of an external listener of type `loadbalancer` using `dnsAnnotations`
[source,yaml,subs="attributes+"]
----
# ...
listeners:
  external:
    type: loadbalancer
    authentication:
      type: tls
    overrides:
      bootstrap:
        dnsAnnotations:
          external-dns.alpha.kubernetes.io/hostname: kafka-bootstrap.mydomain.com.
          external-dns.alpha.kubernetes.io/ttl: "60"
      brokers:
      - broker: 0
        dnsAnnotations:
          external-dns.alpha.kubernetes.io/hostname: kafka-broker-0.mydomain.com.
          external-dns.alpha.kubernetes.io/ttl: "60"
      - broker: 1
        dnsAnnotations:
          external-dns.alpha.kubernetes.io/hostname: kafka-broker-1.mydomain.com.
          external-dns.alpha.kubernetes.io/ttl: "60"
      - broker: 2
        dnsAnnotations:
          external-dns.alpha.kubernetes.io/hostname: kafka-broker-2.mydomain.com.
          external-dns.alpha.kubernetes.io/ttl: "60"
# ...
----

= Customizing the loadbalancer IP addresses

On `loadbalancer` listeners, you can use the `loadBalancerIP` property to request a specific IP address when creating a loadbalancer.
Use this property when you need to use a loadbalancer with a specific IP address.
The `loadBalancerIP` field is ignored if the cloud provider does not support the feature.

.Example of an external listener of type `loadbalancer` with specific loadbalancer IP address requests
[source,yaml,subs="attributes+"]
----
# ...
listeners:
  external:
    type: loadbalancer
    authentication:
      type: tls
    overrides:
      bootstrap:
        loadBalancerIP: 172.29.3.10
      brokers:
      - broker: 0
        loadBalancerIP: 172.29.3.1
      - broker: 1
        loadBalancerIP: 172.29.3.2
      - broker: 2
        loadBalancerIP: 172.29.3.3
# ...
----
