Deploy Kafak container on RHEL7

This article will show you how to deploy Apache Kafka as a docker container on RHEL7, use Bitnami distribution as an example.

Draft docker compose file

Get example docker-compose.yml from bitnami
curl -sSL https://raw.githubusercontent.com/bitnami/containers/main/bitnami/kafka/docker-compose.yml > docker-compose.yml
Generate SSL file to be used in kafka configuration

kafka-generate-ssl.sh

Update default configuration
# docker-compose.yml
version: "2"

services:
  zookeeper:
    image: docker.io/bitnami/zookeeper:3.8
    ports:
      - "2181:2181"
    volumes:
      - "zookeeper_data:/bitnami"
    environment:
      - ZOO_ENABLE_AUTH=yes
      - ZOO_SERVER_USERS=kafka
      - ZOO_SERVER_PASSWORDS=kafka_password
  kafka:
    image: docker.io/bitnami/kafka:3.4
    ports:
      - "9092:9092"
    environment:
      - KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181
      - KAFKA_CFG_LISTENERS=CLIENT://:9092
      - KAFKA_CFG_ADVERTISED_LISTENERS=CLIENT://kafka:9092
      - KAFKA_ZOOKEEPER_PROTOCOL=SASL
      - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CLIENT:SASL_SSL
      - KAFKA_ZOOKEEPER_USER=kafka
      - KAFKA_ZOOKEEPER_PASSWORD=kafka_password
      - KAFKA_CFG_INTER_BROKER_LISTENER_NAME=CLIENT
      - KAFKA_CFG_SASL_MECHANISM_INTER_BROKER_PROTOCOL=SCRAM-SHA-256
      - KAFKA_CLIENT_USERS=kafka
      - KAFKA_CLIENT_PASSWORDS=KafkaPassword
      - KAFKA_CERTIFICATE_PASSWORD=changeit
      - KAFKA_TLS_TYPE=JKS
    volumes:
      - "kafka_data:/bitnami"
      - './keystore/kafka.keystore.jks:/opt/bitnami/kafka/config/certs/kafka.keystore.jks:ro'
      - './truststore/kafka.truststore.jks:/opt/bitnami/kafka/config/certs/kafka.truststore.jks:ro'
    depends_on:
      - zookeeper

volumes:
  zookeeper_data:
    driver: local
  kafka_data:
    driver: local

Deploy Kafka container with docker compose command

#Go to docker-compose.yml file folder and run below docker command on RHEL 7
docker compose up -d

# Example output
CONTAINER ID   IMAGE                             COMMAND                  CREATED              STATUS                    PORTS                                                                     NAMES
5a82d5f944d6   bitnami/kafka:3.4                 "/opt/bitnami/script…"   About a minute ago   Up 59 seconds             0.0.0.0:9092->9092/tcp, :::9092->9092/tcp                                 kafka-kafka-1
f6fa79cf8d8e   bitnami/zookeeper:3.8             "/opt/bitnami/script…"   10 minutes ago       Up 5 minutes              2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp, :::2181->2181/tcp, 8080/tcp   kafka-zookeeper-1

Reference

Scroll to Top