skip to Main Content

I need to add a health-check for the kafka service in docker-compose.

  kafka:
    image: bitnami/kafka:3.6.1
    restart: always
    container_name: kafka
    ports:
      - '9092:9092'
    volumes:
      - 'kafka_data:/bitnami/kafka'
    environment:
      ALLOW_PLAINTEXT_LISTENER: yes
      KAFKA_ENABLE_KRAFT: yes
      KAFKA_CFG_PROCESS_ROLES: controller,broker
      KAFKA_CFG_CONTROLLER_LISTENER_NAMES: CONTROLLER
      KAFKA_CFG_NODE_ID: 0
      KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: 0@kafka:9093
      KAFKA_CFG_DELETE_TOPIC_ENABLE: 'true'
      KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: 'true'
      KAFKA_CFG_LISTENERS: INTERNAL://:29092,CONTROLLER://:9093,EXTERNAL://0.0.0.0:9092
      KAFKA_CFG_INTER_BROKER_LISTENER_NAME: INTERNAL
      KAFKA_CFG_ADVERTISED_LISTENERS: INTERNAL://kafka:29092,EXTERNAL://localhost:9092
      KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT,CONTROLLER:PLAINTEXT

What should I include in the health-check?

2

Answers


  1. You can add the heal check like this :

     healthcheck:
          test: ["CMD-SHELL", "echo 'test-message' | kafka-console-producer.sh --broker-list localhost:9092 --topic health-check-topic && kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic health-check-topic --from-beginning --max-messages 1 | grep 'test-message'"]
          interval: 15s
          timeout: 10s
          retries: 3
    

    Please adjust the interval/timeout etc according to your need

    Login or Signup to reply.
  2.   kafka:
        image: quay.io/debezium/kafka:2.5
        ports:
          - 9092:9092
        depends_on:
          zookeeper:
            condition: service_healthy
        environment:
         - ZOOKEEPER_CONNECT=zookeeper:2181
        healthcheck:
          test: /kafka/bin/kafka-cluster.sh cluster-id --bootstrap-server kafka:9092 || exit 1
          interval: 1s
          timeout: 60s
          retries: 60
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search