Expose individual Kafka brokers on Kubernetes through an ELB on AWS
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Apache Kafka is a popular distributed event streaming platform capable of handling trillions of events a day. Initially conceived as a messaging queue, Kafka is based on an abstraction of a distributed commit log. Since Kafka can handle such high-throughout, low-latency messaging, it's a favorite for building real-time data pipelines and streaming applications. When deploying Kafka on Kubernetes, which provides automatable deployment, scaling, and operations of application containers across clusters of hosts, it could be beneficial to expose each Kafka broker through an AWS Elastic Load Balancer (ELB) for better load distribution and fault tolerance. Here, we discuss how to achieve this by setting up a Kafka cluster on Kubernetes and then exposing each broker via an ELB on AWS.
Kubernetes Deployment of Kafka
To begin, Kafka can be deployed on a Kubernetes cluster in several ways, including using Helm charts (like the popular bitnami/kafka chart), or using operators like the Strimzi Kafka Operator, which simplifies the management of Kafka on Kubernetes.
Here's a basic step using Helm:
- Install Helm (if you haven't):
- Add Bitnami Chart and Install Kafka:
Expose Kafka Brokers Through an AWS ELB
Exposing each Kafka broker via an AWS ELB is slightly more complex than exposing a typical stateless service (like a web server) because Kafka brokers need to be individually addressable. You will need a way to assign each Kafka pod its own ELB, which requires dynamic provisioning and DNS updates.
Step-by-Step Configuration
- Create a Headless Service in Kubernetes: A headless service in Kubernetes is required to manage the DNS records that allow us to not only discover all brokers but also address them individually.
- Assign Each Kafka Pod an External IP Using ELB: Kubernetes does not natively support assigning an External IP from an ELB to a pod directly. Instead, you can create a LoadBalancer service for each broker which will be automatically assigned an ELB by AWS.First, ensure each Kafka pod has a stable and unique identifier, like
my-kafka-0,my-kafka-1, etc., typically achieved through a StatefulSet.Then, for each broker, create a LoadBalancer service:
- Update Kafka Configuration for Custom Listener: Brokers need to be aware of their external access configuration, configured using listeners. A separate listener for each broker can be set in the Kafka broker configuration:
Replace <ELB-DNS-0> with the actual DNS name of the ELB assigned to the broker.
Summary Table
| Step | Detail |
| Install Kafka | Use Helm to deploy Kafka on Kubernetes. |
| Configure Headless Service | Create a headless service for internal broker communication. |
| Set up LoadBalancer Services | Create a LoadBalancer service for each Kafka broker to get an ELB. |
| Configure Kafka Broker | Set up Kafka listeners for both internal and external communication. |
Considerations
- Security: Make sure to implement security groups and access controls to restrict access to the ELBs.
- Monitoring and Logging: Use tools like Prometheus and Grafana for monitoring and ELK stack or similar for logging.
Conclusion
Setting up Kafka on Kubernetes to expose individual brokers through an ELB involves configuring headless services, LoadBalancer services, and custom brokerage settings for network communication. This configuration supports high availability and fault tolerance, essential for production-grade Kafka deployments on AWS.
Related reading
- Exposing Kafka as a public API
- External system queries during Kafka Stream processing
- Extract binary values from stream with low memory consumption
- Extract the time stamp from kafka messages in spark streaming?
- expose kubernetes pod to internet
- Expose MongoDB on Kubernetes with StatefulSets outside cluster
- external-ip remains pending on controller-service after installation of Nginx Ingress Controller on AWS EKS
- External DNS Configure it in all namespaces

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.