Disclosure up front: I run IPYE, a company that leases IP space. This is a practical how-to, and IPYE comes up where it helps, with a short call to action at the end.
Most Kafka connection problems come from advertised.listeners. Clients connect to a bootstrap server, receive a list of broker addresses, and then connect to those addresses. If a broker advertises an address the client can't reach, the client fails after a successful first connection. With IPv6, there's an extra trap: addresses need brackets. This guide configures a KRaft-mode Kafka cluster on a free IPv6 /48 from IPYE. The examples use the documentation prefix 2001:db8:100::/48, with brokers at 2001:db8:100:1b::1 to ::3.
Broker configuration
server.properties on broker 1 (combined broker and controller):
process.roles=broker,controller node.id=1 controller.quorum.voters=1@[2001:db8:100:1b::1]:9093,2@[2001:db8:100:1b::2]:9093,3@[2001:db8:100:1b::3]:9093 listeners=PLAINTEXT://[2001:db8:100:1b::1]:9092,CONTROLLER://[2001:db8:100:1b::1]:9093 advertised.listeners=PLAINTEXT://kafka1.example.net:9092 listener.security.protocol.map=PLAINTEXT:PLAINTEXT,CONTROLLER:PLAINTEXT controller.listener.names=CONTROLLER inter.broker.listener.name=PLAINTEXT log.dirs=/var/lib/kafka/data A few notes:
-
listenerscontrols where the broker binds. Brackets around the literal address are required. -
advertised.listenersis what clients are told. A hostname with an AAAA record is easier to work with than a literal, and it lets you add an A record later for IPv4 clients. - Recent Kafka releases replace
controller.quorum.voterswithcontroller.quorum.bootstrap.serversand dynamic quorums. The bracket rule is the same either way.
Java and IPv6
Kafka runs on the JVM, which handles IPv6 well, but some environments set -Djava.net.preferIPv4Stack=true in KAFKA_OPTS. Remove it. To prefer IPv6 when resolving names that have both A and AAAA records:
export KAFKA_OPTS="-Djava.net.preferIPv6Addresses=true" Format storage and start
KAFKA_CLUSTER_ID=$(bin/kafka-storage.sh random-uuid) bin/kafka-storage.sh format -t $KAFKA_CLUSTER_ID -c config/server.properties bin/kafka-server-start.sh -daemon config/server.properties Use the same cluster ID on all three brokers.
Check from a client
bin/kafka-broker-api-versions.sh --bootstrap-server '[2001:db8:100:1b::1]:9092' | head -3 bin/kafka-metadata-quorum.sh --bootstrap-server kafka1.example.net:9092 describe --status kafka-broker-api-versions prints one line per broker, with the advertised address it handed out. If those lines show a name or address your client can't resolve or reach, fix advertised.listeners on that broker.
Separate internal and external listeners
When clients outside your network connect, give them their own listener with TLS and authentication, and keep inter-broker traffic on an internal one:
listeners=INTERNAL://[2001:db8:100:1b::1]:9092,EXTERNAL://[2001:db8:100:1b::1]:9094,CONTROLLER://[2001:db8:100:1b::1]:9093 advertised.listeners=INTERNAL://kafka1.internal.example.net:9092,EXTERNAL://kafka1.example.net:9094 listener.security.protocol.map=INTERNAL:PLAINTEXT,EXTERNAL:SASL_SSL,CONTROLLER:PLAINTEXT inter.broker.listener.name=INTERNAL Because the addresses are globally routable, both listeners can share one address and differ by port. You don't need NAT tricks or per-network hostname hacks.
Firewall
ip6 saddr 2001:db8:100:1b::/64 tcp dport { 9092, 9093 } accept ip6 saddr 2001:db8:100:1c::/64 tcp dport 9092 accept tcp dport 9094 accept tcp dport { 9092, 9093 } drop Port 9093 (controller) should only ever be reachable by the other brokers.
Why routable broker addresses
Kafka clients connect to every broker directly, so NAT between clients and brokers means maintaining address translations for every broker. With globally unique addresses from a prefix you control, there's nothing to translate. IPYE's free /48 provides that prefix, and you can announce it from any provider that accepts a LOA.
Get started
Claim your free /48 in the IPYE portal, bracket every IPv6 listener, and check what brokers advertise with kafka-broker-api-versions.
About IPYE
IPYE leases IPv4, IPv6 and ASN space with instant setup. Your first IPv6 /48 is free for the first year, a real allocation you can announce on your own ASN, with a LOA from the portal and the ROA created automatically. IPv4 /24 to /22 leases include LOA, ROA and per-/24 rDNS, and ASN and region changes apply automatically. Locations: Los Angeles, New York, Ashburn, Salt Lake City, London, Amsterdam, Frankfurt. More at ipye.com. Questions: ipye@turnel.com.
Disclosure: I run IPYE