Kafdrop Documentation

repository·master·Indexed 27 days ago

https://github.com/obsidiandynamics/kafdrop

A lightweight, web-based UI for Apache Kafka and Azure Event Hubs. Kafdrop allows developers to view brokers, topics, partitions, and consumer groups, and browse messages using JSON, Avro, and Protobuf encodings. It supports deployment via JAR, Docker, systemd, and Kubernetes (Helm), and provides JSON APIs with OpenAPI and Swagger documentation.

Tokens
3.7K
Snippets
11
Records
19
Agent score
91%

What's inside Kafdrop

  1. Run Kafdrop with Docker using Secure Connection

    master

    You can run Kafdrop via Docker using two methods for secure connections:

    Method 1: Base64 Encoded Environment Variables

    Pass the contents of your properties and certificate files as base64-encoded strings via environment variables.

    Method 2: Mounting Files

    Mount your local kafka.properties, kafka.truststore.jks, and kafka.keystore.jks files into the container and use the _FILE environment variables to point to their internal paths.

    # Method 1: Base64
    docker run -d --rm -p 9000:9000 \
        -e KAFKA_BROKERCONNECT=<host:port,host:port> \
        -e KAFKA_PROPERTIES="$(cat kafka.properties | base64)" \
        -e KAFKA_TRUSTSTORE="$(cat kafka.truststore.jks | base64)" \
        -e KAFKA_KEYSTORE="$(cat kafka.keystore.jks | base64)" \
        obsidiandynamics/kafdrop
    
    # Method 2: File Mounting
    docker run -d --rm -p 9000:9000 \
        -v $(pwd)/kafka.properties:/tmp/kafka.properties:ro \
        -v $(pwd)/kafka.truststore.jks:/tmp/kafka.truststore.jks:ro \
        -v $(pwd)/kafka.keystore.jks:/tmp/kafka.keystore.jks:ro \
        -e KAFKA_BROKERCONNECT=<host:port,host:port> \
        -e KAFKA_PROPERTIES_FILE=/tmp/kafka.properties \
        -e KAFKA_TRUSTSTORE_FILE=/tmp/kafka.truststore.jks \
        -e KAFKA_KEYSTORE_FILE=/tmp/kafka.keystore.jks \
        obsidiandynamics/kafdrop
  2. Deploy Kafdrop to Kubernetes using Helm

    master
    Deploy Kafdrop to a Kubernetes cluster using the provided Helm chart. You can set the image tag, broker connection, and command arguments via --set flags. To support Protobuf, use the mountProtoDesc facility to mount descriptor files.
  3. Secure the Kafdrop UI with NGINX Basic Auth

    master

    Kafdrop does not have native authentication. You can secure it by using NGINX as a reverse proxy with Basic Auth.

    Setup Steps

    1. Install Requirements: Ensure nginx and httpd (for htpasswd) are installed.
    2. Create Password File: Run htpasswd -c /usr/local/etc/nginx/.htpasswd admin to set an admin password.
    3. Configure NGINX: Use an upstream block to point to Kafdrop (default port 9000) and add auth_basic directives to your server block.
    4. Add Logout Functionality: Create a logout page at /usr/local/opt/nginx/html/401.html and a /logout location in NGINX that returns a 401 status code.
    5. Start NGINX: Run nginx or nginx -s reload.
    http {
      upstream kafdrop {
        server 127.0.0.1:9000;
        keepalive 64;
      }
    
      server {
        listen *:8080;
        server_name _;
        auth_basic "Restricted Area";
        auth_basic_user_file /usr/local/etc/nginx/.htpasswd;
    
        location / {
          proxy_pass http://kafdrop;
        }
    
        location /logout {
          return 401;
        }
    
        error_page 401 /errors/401.html;
    
        location /errors {
          auth_basic off;
          ssi        on;
          alias /usr/local/opt/nginx/html;
        }
      }
    }
  4. Load Extra JARs for SASL Client Callbacks in Docker

    master

    If you need to load extra classes (e.g., for AWS MSK IAM authentication), mount a folder containing the required JAR files to /extra-classes and run the container.

    # Example for AWS MSK IAM
    mkdir extra-kafdrop-classes
    wget --directory-prefix=extra-kafdrop-classes https://repo1.maven.org/maven2/software/amazon/msk/auth/iam/AWSMSKClientCallbackHandler/1.0.0/aws-msk-iam-auth-1.0.0.jar
    
    docker run -d --rm -p 9000:9000 \
        -v $(pwd)/kafka.properties:/tmp/kafka.properties:ro \
        -v $(pwd)/extra-kafdrop-classes:/extra-classes:ro \
        -e KAFKA_BROKERCONNECT=<host:port,host:port> \
        -e KAFKA_PROPERTIES_FILE=/tmp/kafka.properties \
        -v $(pwd)/extra-kafdrop-classes:/extra-classes:ro \
        obsidiandynamics/kafdrop
  5. Run Kafdrop from a JAR

    master
    To run Kafdrop directly using a JAR file, use the java command with the --kafka.brokerConnect flag. Note that as of version 3.10.0, ZooKeeper is no longer required. The web UI is accessible at http://localhost:9000 by default, but you can override the server ports using --server.port and --management.server.port.
  6. Run Kafdrop from JAR with Secure Connection

    master

    To run Kafdrop from a JAR file while connecting to a secure broker, create a kafka.properties file and use the --kafka.propertiesFile flag along with --kafka.brokerConnect.

    java -jar target/kafdrop-<version>.jar \
        --kafka.brokerConnect=<host:port,host:port> \
        --kafka.propertiesFile=./kafka.properties
  7. Install Kafdrop as a systemd service

    master

    To deploy Kafdrop as a systemd service on Ubuntu 22.04 LTS (or similar distributions), follow these steps.

    Prerequisites:

    • An assumed installation directory ($INSTALLDIR) of /opt/kafdrop. If you use a different path, you must update the # Paths section within the kafdrop.service file.

    Installation Steps:

    1. Create the $INSTALLDIR directory and download the latest Kafdrop release into it.
    2. Create the kafdrop user and group using systemd-sysusers:
      systemd-sysusers --inline 'u  kafdrop  -  "KafDrop user"  $INSTALLDIR  /usr/sbin/nologin'
    3. Copy start.sh to $INSTALLDIR, configure your specific startup parameters and options, and make it executable:
      chmod 755 $INSTALLDIR/start.sh
    4. Copy kafdrop.service to $INSTALLDIR and create a symbolic link in /etc/systemd/system:
      (cd /etc/systemd/system && ln -s $INSTALLDIR/kafdrop.service)
    5. Reload the systemd daemon:
      systemctl daemon-reload
    6. Enable and start the service:
      systemctl enable kafdrop.service && systemctl start kafdrop.service
    systemd-sysusers --inline 'u  kafdrop  -  "KafDrop user"  $INSTALLDIR  /usr/sbin/nologin'
    chmod 755 $INSTALLDIR/start.sh
    (cd /etc/systemd/system && ln -s $INSTALLDIR/kafdrop.service)
    systemctl daemon-reload
    systemctl enable kafdrop.service && systemctl start kafdrop.service
  8. Deploy Kafdrop using Helm with Secure Connection

    master

    When deploying via Helm, supply the security files (properties, truststore, keystore) in base-64 encoded form using the --set flag.

    helm upgrade -i kafdrop chart --set image.tag=3.x.x \
        --set kafka.brokerConnect=<host:port,host:port> \
        --set kafka.properties="$(cat kafka.properties | base64)" \
        --set kafka.truststore="$(cat kafka.truststore.jks | base64)" \
        --set kafka.keystore="$(cat kafka.keystore.jks | base64)"
  9. Connect to a Secure Kafka Broker (TLS/SASL)

    master

    Kafdrop supports TLS (SSL) and SASL for encryption and authentication. To connect to a secure broker, you must provide a kafka.properties file containing your security configuration (e.g., security.protocol, sasl.mechanism, sasl.jaas.config). If using TLS or mutual TLS, you also need to provide a truststore (kafka.truststore.jks) and/or a keystore (kafka.keystore.jks).

    security.protocol=SASL_SSL
    sasl.mechanism=SCRAM-SHA-512
    sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required username="foo" password="bar"
  10. Configure Schema Registry and Message Formats

    master

    When running from a JAR, you can connect to a Schema Registry and define default message/key formats.

    Valid format values for --message.format and --message.keyFormat are DEFAULT, AVRO, and PROTOBUF. If --message.keyFormat is not specified, it defaults to the value of --message.format.