Bertone
Bertone

Reputation: 756

How to configure bitnami ksqldb docker image in a docker-compose

I honestly never used an image from bitnami and I am having difficulties in understanding how to use the KSQLDB one. I am pretty sure I am doing something pretty stupid since I misunderstood something quite basic.

This is my basic docker-compose:

services:
  ksqldb-server:
    image: bitnami/ksql:latest
    hostname: ksqldb-server
    container_name: ksqldb-server
    ports:
      - "8088:8088"
    volumes:
      - "./ksql-server.properties:/opt/bitnami/ksql/config/ksql-server.properties"
    environment:
      # KSQL
      KSQL_LISTENERS: http://0.0.0.0:8088
      KSQL_BOOTSTRAP_SERVERS: my-remote-server:9092
      KSQL_MOUNTED_CONF_DIR: "/opt/bitnami/ksql/config"
  ksqldb-cli:
    image: confluentinc/ksqldb-cli:0.29.0
    container_name: ksqldb-cli
    depends_on:
      - ksqldb-server
    entrypoint: /bin/sh
    tty: true

My goal was to set these few ENVS in the BITNAMI documentation and then set the others through conf file. I want to keep default values for all the others.

Here is my config file:

security.protocol=SASL_SSL
sasl.mechanism=PLAIN
sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="usernameXXX" password="passwordXXX";
ssl.endpoint.identification.algorithm=HTTPS
ksql.internal.topic.replicas=3
ksql.sink.replicas=3
ksql.streams.replication.factor=3
ksql.logging.processing.topic.replication.factor=3
ksql.logging.processing.stream.auto.create=true
ksql.logging.processing.topic.auto.create=true
ksql.log4j.root.loglevel=DEBUG

Since bitname uses user 1001 I do chown -R 1001:1001 ksql-server.properties.

When I launch this I get:

ksqldb-server  | ksql 09:04:32.27 INFO  ==> 
ksqldb-server  | ksql 09:04:32.28 INFO  ==> ** Starting KSQL setup **
ksqldb-server  | ksql 09:04:32.30 INFO  ==> Validating settings in KSQL_* env vars
ksqldb-server  | ksql 09:04:32.33 INFO  ==> Initializing Confluent KSQL
ksqldb-server  | ksql 09:04:32.34 INFO  ==> Injected configuration file found. Skipping default configuration
ksqldb-server  | ksql 09:04:32.34 INFO  ==> Waiting for Kafka brokers to be up
ksqldb-server exited with code 1

I also tried to remove: KSQL_MOUNTED_CONF_DIR: "/opt/bitnami/ksql/config"

and set:

volumes:
      - "./ksql-server.properties:/opt/bitnami/ksql/etc/ksqldb/ksql-server.properties"

Nothing changed, still detecting injected config, no debug logs.

If I remove the volume at all (no config file) I get a "no config detected using default" and then an obvious error on Kafka endpoint.

My initial guess would have been that the /opt/bitnami/ksql/etc/ksqldb folder is used for creating the default file when you don't provide it with KSQL_MOUNTED_CONF_DIR. Nevertheless, even substituting the file in that folder creates an "injected configuration file found" log, so I have no idea how this works.

Moreover, looking in that folder with docker run -it bitnami/ksql /bin/bash I saw lots of templates. In particular one is called ksqldb-server.properties.template and has inside:

{% set kr_props = env_to_props('KSQL_', '') -%}
{% for name, value in kr_props.items() -%}
{{name}}={{value}}
{% endfor -%}

That seems the approach used in the docker image confluentinc/ksqldb-server and that would be my favourite way to configure. I tried (without hopes to add other ENVS not written in the bitnami's very small docs like this:

      KSQL_SASL_JAAS_CONFIG: >
        org.apache.kafka.common.security.plain.PlainLoginModule required
        username="usernameXXX"
        password="passwordXXX";
      KSQL_SECURITY_PROTOCOL: SASL_SSL
      KSQL_SASL_MECHANISM: PLAIN
      KSQL_SSL_ENDPOINT_IDENTIFICATION_ALGORITHM: "HTTPS"

Same error.

In short:

Upvotes: 1

Views: 219

Answers (1)

poisoned_monkey
poisoned_monkey

Reputation: 442

As I understand you can either use environment variables from config file or by specifying them in docker-compose.yml. I've tried to start your docker-compose, and faced the issue:

ksqldb-server  | ksql 16:48:59.81 INFO  ==> ** Starting KSQL setup **
ksqldb-server  | ksql 16:48:59.86 INFO  ==> Validating settings in KSQL_* env vars
ksqldb-server  | ksql 16:48:59.89 INFO  ==> Initializing Confluent KSQL
ksqldb-server  | ksql 16:48:59.92 INFO  ==> No injected configuration files found, creating default config file.
ksqldb-server  | grep: /opt/bitnami/ksql/etc/ksqldb/ksql-server.properties: Is a directory
ksqldb-server  | /opt/bitnami/scripts/libksql.sh: line 158: /opt/bitnami/ksql/etc/ksqldb/ksql-server.properties: Is a directory
ksqldb-server exited with code 1

I've added environment variables through docker-compose and after that it worked

services:
  ksqldb-server:
    image: bitnami/ksql:latest
    hostname: ksqldb-server
    container_name: ksqldb-server
    ports:
      - "8088:8088"
    volumes:
      - "./ksql-server.properties:/opt/bitnami/ksql/config/ksql-server.properties"
    environment:
      # KSQL
      KSQL_LISTENERS: http://0.0.0.0:8088
      KSQL_BOOTSTRAP_SERVERS: my-remote-server:9092
      KSQL_SECURITY_PROTOCOL: SASL_SSL
      KSQL_SASL_MECHANISM: PLAIN
      KSQL_SASL_JAAS_CONFIG: 'org.apache.kafka.common.security.plain.PlainLoginModule required username="usernameXXX" password="passwordXXX";'
      KSQL_SSL_ENDPOINT_IDENTIFICATION_ALGORITHM: "HTTPS"
      KSQL_INTERNAL_TOPIC_REPLICAS: 3
      KSQL_SINK_REPLICAS: 3
      KSQL_STREAMS_REPLICATION_FACTOR: 3
      KSQL_LOGGING_PROCESSING_TOPIC_REPLICATION_FACTOR: 3
      KSQL_LOGGING_PROCESSING_STREAM_AUTO_CREATE: true
      KSQL_LOGGING_PROCESSING_TOPIC_AUTO_CREATE: true
      KSQL_LOG4J_ROOT_LOGLEVEL: DEBUG
  ksqldb-cli:
    image: confluentinc/ksqldb-cli:0.29.0
    container_name: ksqldb-cli
    depends_on:
      - ksqldb-server
    entrypoint: /bin/sh
    tty: true

Here is the output:

ksqldb-server  | ksql 16:52:07.73 INFO  ==> 
ksqldb-server  | ksql 16:52:07.73 INFO  ==> Welcome to the Bitnami ksql container
ksqldb-server  | ksql 16:52:07.73 INFO  ==> Subscribe to project updates by watching https://github.com/bitnami/containers
ksqldb-server  | ksql 16:52:07.74 INFO  ==> Submit issues and feature requests at https://github.com/bitnami/containers/issues
ksqldb-server  | ksql 16:52:07.74 INFO  ==> Upgrade to Tanzu Application Catalog for production environments to access custom-configured and pre-packaged software components. Gain enhanced features, including Software Bill of Materials (SBOM), CVE scan result reports, and VEX documents. To learn more, visit https://bitnami.com/enterprise
ksqldb-server  | ksql 16:52:07.74 INFO  ==> 
ksqldb-server  | ksql 16:52:07.75 INFO  ==> ** Starting KSQL setup **
ksqldb-server  | ksql 16:52:07.76 INFO  ==> Validating settings in KSQL_* env vars
ksqldb-server  | ksql 16:52:07.80 INFO  ==> Initializing Confluent KSQL
ksqldb-server  | ksql 16:52:07.81 INFO  ==> No injected configuration files found, creating default config file.
ksqldb-server  | ksql 16:52:07.84 INFO  ==> Waiting for Kafka brokers to be up
ksqldb-server  | 
ksqldb-server  | ksql 16:52:07.85 INFO  ==> ** KSQL setup finished! **
ksqldb-server  | ksql 16:52:07.86 INFO  ==> ** Starting KSQL **

I have checked the variables inside the container. All the variables specified in docker-compose.yml were successfully injected.

Upvotes: 1

Related Questions