| name | kafka-troubleshooting |
| description | Troubleshoot Kafka, ZooKeeper, and Broker issues. Use when debugging service failures, connection issues, or unexpected errors in the Kafka cluster. |
Kafka Cluster Troubleshooting
This skill helps diagnose and fix issues with Kafka brokers, ZooKeeper ensemble, and related services.
When to Use This Skill
- Kafka broker fails to start or crashes
- ZooKeeper connection issues
- Consumer/producer connectivity problems
- TLS/SSL certificate errors
- Cluster coordination failures
- JMX Exporter not exposing metrics
- Prometheus targets not UP
- Grafana dashboards blank or missing data
- Nginx 502/504 gateway errors
- Traffic generator not producing messages
Container Access
IMPORTANT: Use docker exec instead of molecule login for non-interactive troubleshooting.
molecule login requires an interactive shell which is not suitable for automated troubleshooting.
docker ps --format "table {{.Names}}\t{{.Status}}"
docker exec <container_name> <command>
Log File Locations
ZooKeeper Logs
docker exec zk1 cat /opt/zookeeper/logs/zookeeper-root-server-zk1.out
docker exec zk1 tail -50 /opt/zookeeper/logs/zookeeper-root-server-zk1.out
docker exec zk1 journalctl -u zookeeper -n 50 --no-pager
docker exec zk1 /opt/zookeeper/bin/zkServer.sh status
Kafka Broker Logs
docker exec kafka1 cat /opt/kafka/logs/server.log
docker exec kafka1 tail -100 /opt/kafka/logs/server.log
docker exec kafka1 journalctl -u kafka -n 50 --no-pager
docker exec kafka1 /opt/kafka/bin/kafka-broker-api-versions.sh --bootstrap-server localhost:9092
System Logs
docker exec kafka1 journalctl -xe --no-pager | tail -50
Common Diagnostic Commands
ZooKeeper Health
docker exec zk1 /opt/zookeeper/bin/zkServer.sh status
docker exec zk1 bash -c 'echo ruok | nc localhost 2181'
docker exec zk1 bash -c 'echo stat | nc localhost 2181'
docker exec zk1 /opt/zookeeper/bin/zkCli.sh -server localhost:2181 ls /
Kafka Health
docker exec kafka1 /opt/kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 --list
docker exec kafka1 /opt/kafka/bin/kafka-metadata.sh --snapshot /var/kafka-logs/__cluster_metadata-0/00000000000000000000.log --command "describe"
docker exec kafka1 /opt/kafka/bin/kafka-broker-api-versions.sh --bootstrap-server localhost:9092
docker exec kafka1 /opt/kafka/bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list
Network/Port Verification
docker exec kafka1 ss -tlnp
docker exec zk1 ss -tlnp
docker exec kafka1 bash -c 'nc -zv zk1 2181'
Process Status
docker exec kafka1 jps -l
docker exec zk1 jps -l
docker exec kafka1 systemctl status kafka
docker exec zk1 systemctl status zookeeper
Common Issues and Solutions
Issue: ZooKeeper Won't Form Quorum
Symptoms: zkServer.sh status shows "Error contacting service"
Check:
docker exec zk1 cat /var/lib/zookeeper/myid
docker exec zk1 cat /opt/zookeeper/conf/zoo.cfg
Issue: Kafka Cannot Connect to ZooKeeper
Symptoms: Kafka logs show "Connection refused" to ZooKeeper
Check:
docker exec kafka1 bash -c 'for zk in zk1 zk2 zk3; do echo -n "$zk: "; nc -zv $zk 2181 2>&1; done'
docker exec kafka1 grep zookeeper.connect /opt/kafka/config/server.properties
Issue: TLS/SSL Certificate Errors
Symptoms: SSL handshake failures in logs
Check:
docker exec kafka1 ls -la /opt/kafka/config/*.jks
docker exec kafka1 keytool -list -v -keystore /opt/kafka/config/kafka.keystore.jks -storepass <password> | grep -A2 "Valid from"
Observability Stack Troubleshooting
JMX Exporter Not Exposing Metrics
Symptoms: curl kafka1:7071/metrics times out or returns nothing
docker exec kafka1 jps -v | grep jmx_prometheus
docker exec kafka1 journalctl -u kafka -n 100 --no-pager | grep -i jmx
docker exec kafka1 ls -la /opt/jmx-exporter/
docker exec kafka1 cat /opt/jmx-exporter/kafka.yml
Fix: Ensure kafka_jmx_exporter_enabled: true in group_vars/all.yml. The JMX Exporter is a Java agent — the flag must be set before Kafka starts. Re-run molecule converge to redeploy.
Prometheus Targets Not UP
Symptoms: Prometheus UI shows targets in DOWN or UNKNOWN state
docker exec monitoring1 cat /etc/prometheus/prometheus.yml
docker exec monitoring1 curl -s http://kafka1:7071/metrics | head -5
docker exec monitoring1 curl -s http://zk1:7072/metrics | head -5
docker exec monitoring1 curl -s http://localhost:9308/metrics | head -5
docker exec monitoring1 curl -s http://kafka1:9100/metrics | head -5
docker exec monitoring1 journalctl -u prometheus -n 50 --no-pager
Grafana Dashboards Blank
Symptoms: Grafana loads but panels show "No data" or "Error"
docker exec monitoring1 curl -s -u admin:admin http://localhost:3000/api/datasources
docker exec monitoring1 curl -s http://localhost:9090/api/v1/query?query=up
docker exec monitoring1 ls -la /var/lib/grafana/dashboards/
docker exec monitoring1 cat /etc/grafana/provisioning/dashboards/kafka-dashboards.yml
docker exec monitoring1 cat /etc/grafana/provisioning/datasources/prometheus.yml
docker exec monitoring1 journalctl -u grafana-server -n 50 --no-pager
Common cause: Prometheus job names in dashboards must match scrape config. Check that Prometheus job kafka-jmx (not kafka_jmx) matches the {job=...} filter in dashboard queries.
Nginx Gateway Errors
Symptoms: 502 Bad Gateway or SSL errors
docker exec nginx1 nginx -t
docker exec nginx1 cat /var/log/nginx/error.log | tail -30
docker exec nginx1 ls -la /opt/kafka-ca/nginx1.crt /opt/kafka-ca/nginx1.key
docker exec nginx1 curl -s http://monitoring1:3000/api/health
docker exec nginx1 curl -s http://kafkaui1:8080/api/clusters
Fix: If cert is missing, check that nginx group was included in prepare.yml cert generation play.
Traffic Generator Issues
Symptoms: traffic-generator service fails or exits; no messages in Kafka topics
docker exec traffic1 systemctl status traffic-generator
docker exec traffic1 journalctl -u traffic-generator -n 50 --no-pager
docker exec traffic1 python3 -c "import kafka; print(kafka.__version__)"
docker exec traffic1 python3 -c "
from kafka import KafkaProducer
p = KafkaProducer(bootstrap_servers=['kafka1:9092'])
print('connected')
p.close()
"
docker exec kafka1 /opt/kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 --list
Filtering Ansible Output
When running Molecule commands, always filter to avoid context window bloat:
molecule converge 2>&1 | grep -E "(FAILED|fatal:|ERROR|PLAY RECAP|Scenario)" -A 15
molecule converge 2>&1 | grep -B 5 -A 25 "fatal:"