CNAME records configuration
When you use Kafka’s built-in support for cluster discovery you can use CNAME records as shorter alternatives to the longer hostname that is an alias.
In addition to A records, it is also possible to have CNAME records in the DNS servers. It is good to have a simpler/shorter hostname as an alternative for the one that maps to all the brokers.
;CNAME record active.kafka. IN CNAME primary.kafka.cluster.hostname.
It this case, clients can use the simpler and shorter alternative for the hostname as follows:
kafka-topics --list --bootstrap-server active.kafka:9092
Using a CNAME also provides the possibility to easily switch between standby and active clusters. Assume there is also a standby cluster defined:
; PRIMARY CLUSTER first.primary.kafka.fqdn. IN A 1.2.3.4 second.primary.kafka.fqdn. IN A 4.5.6.7 third.primary.kafka.fqdn. IN A 6.7.8.9 ; DNS alias primary.kafka.cluster.hostname. IN A 1.2.3.4 primary.kafka.cluster.hostname. IN A 4.5.6.7 primary.kafka.cluster.hostname. IN A 6.7.8.9 ; STANDBY CLUSTER first.standby.kafka.fqdn. IN A 4.3.2.1 second.standby.kafka.fqdn. IN A 7.6.5.4 third.standby.kafka.fqdn. IN A 9.8.7.6 ; DNS alias standby.kafka.cluster.hostname. IN A 4.3.2.1 standby.kafka.cluster.hostname. IN A 7.6.5.4 standby.kafka.cluster.hostname. IN A 9.8.7.6 ;CNAME record active.kafka. IN CNAME primary.kafka.cluster.hostname.
If the primary cluster completely stops, it is only needed to change the
active.kafka
CNAME to point to
standby.kafka.cluster.hostname
instead of the primary one:
active.kafka. IN CNAME standby.kafka.cluster.hostname.