kafka on kubernetes cannot produce/consume topics (ClosedChannelException, ErrorLoggingCallback)
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
When Kafka runs on Kubernetes, ClosedChannelException and producer ErrorLoggingCallback failures usually point to connectivity or listener configuration rather than to the topic itself. In practice, the most common root cause is that clients can connect to the bootstrap service but are then redirected to broker addresses they cannot actually reach.
Why This Happens on Kubernetes
Kafka clients do not stay on the bootstrap address forever. They connect to a bootstrap endpoint, fetch broker metadata, and then open connections to the advertised broker listeners returned by the cluster.
If those advertised addresses are wrong for the client's network position, you get symptoms such as:
- producers timing out or logging send failures
- consumers failing to fetch or rebalancing repeatedly
- '
ClosedChannelException' - callbacks that log errors but do not explain the network topology problem directly
This is why Kafka-on-Kubernetes issues often look mysterious until you inspect listener configuration.
Check advertised.listeners First
The first question is: what addresses are brokers advertising to clients?
If a broker advertises an internal pod DNS name to an external client, or an external load balancer address to an internal pod, the client will fail after bootstrap.
A typical broker configuration needs listeners that match the client path. For example, one internal listener and one external listener:
The exact values depend on your deployment, but the pattern is the same: advertise reachable addresses for the clients that will use each listener.
Verify the Path End to End
A good troubleshooting sequence is:
- Confirm the bootstrap service is reachable.
- Inspect the broker metadata returned to the client.
- Confirm the advertised broker hostnames resolve from the client location.
- Confirm those broker ports are reachable.
Inside Kubernetes, use a temporary debug pod:
Then test DNS and connectivity:
If the client is outside the cluster, perform the equivalent tests from outside the cluster as well. Internal success does not prove external reachability.
StatefulSets and Headless Services Matter
Kafka brokers on Kubernetes are usually deployed as a StatefulSet with stable identities and a headless service. That arrangement lets each broker advertise a stable DNS name such as kafka-0, kafka-1, and kafka-2.
If the deployment uses only one generic service without preserving per-broker identity, clients may bootstrap correctly but fail when they try to connect to individual brokers after metadata lookup.
That is one reason Kafka on Kubernetes is trickier than stateless web services.
What ErrorLoggingCallback Often Means
ErrorLoggingCallback is a symptom reporter, not the root cause. It frequently logs failures triggered by:
- unreachable advertised listeners
- TLS or SASL mismatch
- network policies blocking broker-to-client traffic
- brokers restarting or not yet ready
So treat the callback as evidence that the producer failed, not as proof that the callback itself is the problem.
Other Kubernetes-Specific Checks
Once listeners are verified, also inspect:
- NetworkPolicy rules between client pods and broker pods
- readiness and liveness probes that may recycle brokers too aggressively
- persistent volume stability and broker restarts
- pod anti-affinity so all brokers are not landing on the same node
These issues can cause channels to close even when listener configuration is technically correct.
Common Pitfalls
The biggest mistake is testing only the bootstrap address and assuming Kafka networking is therefore correct. Kafka clients must also reach the individual broker addresses returned in metadata.
Another issue is using advertised listeners that are valid only from one network zone. Internal pods and external clients often need different listener paths.
Developers also focus on topic creation or ACLs first when the real failure is lower-level connectivity. ClosedChannelException is often a transport symptom before it is an authorization symptom.
Finally, remember that Kubernetes service discovery is not enough by itself. Kafka needs stable, correct broker identities, not just any reachable service IP.
Summary
- '
ClosedChannelExceptionon Kafka-on-Kubernetes usually points to listener or connectivity problems.' - Always inspect
advertised.listeners, not just bootstrap reachability. - Verify broker DNS names and ports from the actual client network location.
- Use StatefulSets and stable broker identities so metadata points to real brokers.
- Treat
ErrorLoggingCallbackas a symptom of failed sends, then trace the underlying network or listener issue.

