• By Canonical Data Platform
Channel Revision Published Runs on
3/stable 123 24 May 2023
Ubuntu 22.04
3/edge 123 23 May 2023
Ubuntu 22.04
juju deploy kafka --channel 3/stable
Show information



Get a Charmed Kafka and Zookeeper up and running

This is part of the Charmed Kafka Tutorial. Please refer to this page for more information and the overview of the content.


To deploy Charmed Kafka, all you need to do is run the following command, which will fetch the needed charms(Kafka and Zookeeper) from Charmhub and deploy it to your model:

$ juju deploy zookeeper -n 5
$ juju deploy kafka -n 3

After this, it is necessary to connect them:

$ juju relate kafka zookeeper

Juju will now fetch Charmed Kafka and Zookeeper and begin deploying it to the LXD cloud. This process can take several minutes depending on how provisioned (RAM, CPU,etc) your machine is. You can track the progress by running:

juju status --watch 1s

This command is useful for checking the status of Charmed Zookeeper and Charmed Kafka and gathering information about the machines hosting the two applications. Some of the helpful information it displays include IP addresses, ports, state, etc. The command updates the status of the cluster every second and as the application starts you can watch the status and messages of Charmed Kafka and Zookeeper change.

Wait until the application is ready - when it is ready, juju status --watch 1s will show:

Model     Controller  Cloud/Region         Version  SLA          Timestamp
tutorial  overlord    localhost/localhost  2.9.38   unsupported  08:20:12Z

App        Version  Status  Scale  Charm      Channel      Rev  Exposed  Message
kafka               active      3  kafka      3/stable     117  no       
zookeeper           active      5  zookeeper  3/stable      99  no       

Unit          Workload  Agent  Machine  Public address  Ports  Message
kafka/0       active    idle   5           machine system settings are not optimal - see logs for info
kafka/1*      active    idle   6            machine system settings are not optimal - see logs for info
kafka/2       active    idle   7           machine system settings are not optimal - see logs for info
zookeeper/0   active    idle   0          
zookeeper/1   active    idle   1          
zookeeper/2   active    idle   2          
zookeeper/3*  active    idle   3           
zookeeper/4   active    idle   4          

Machine  State    Address        Inst id        Series  AZ  Message
0        started  juju-f1a2cd-0  jammy       Running
1        started  juju-f1a2cd-1  jammy       Running
2        started  juju-f1a2cd-2  jammy       Running
3        started   juju-f1a2cd-3  jammy       Running
4        started  juju-f1a2cd-4  jammy       Running
5        started   juju-f1a2cd-5  jammy       Running
6        started    juju-f1a2cd-6  jammy       Running
7        started   juju-f1a2cd-7  jammy       Running

To exit the screen with juju status --watch 1s, enter Ctrl+c.

Access Kafka cluster

To watch the process, juju status can be used. Once all the units show as active|idle the credentials to access a broker can be queried with:

juju run-action kafka/leader get-admin-credentials --wait

The output of the previous command is something like this:

  UnitId: kafka/1
  id: "2"
    client-properties: |-
      sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required username="admin" password="e2sMfYLQg7sbbBMFTx1qlaZQKTUxr09x";
    password: e2sMfYLQg7sbbBMFTx1qlaZQKTUxr09x
    username: admin
  status: completed
    completed: 2023-04-25 09:03:00 +0000 UTC
    enqueued: 2023-04-25 09:02:58 +0000 UTC
    started: 2023-04-25 09:02:59 +0000 UTC

Apache Kafka ships with bin/*.sh commands to do various administrative tasks, e.g bin/kafka-config.sh to update cluster configuration, bin/kafka-topics.sh for topic management, and many more! The Kafka Charmed Operator provides these commands to administrators to easily run their desired cluster configurations securely with SASL authentication, either from within the cluster or as an external client.

If you wish to run a command from the cluster, in order to (for example) list the current topics on the Kafka cluster, you can run:

BOOTSTRAP_SERVERS=$(juju run-action kafka/leader get-admin-credentials --wait | grep "bootstrap.servers" | cut -d "=" -f 2)
juju ssh kafka/leader 'charmed-kafka.topics --bootstrap-server $BOOTSTRAP_SERVERS --list --command-config /var/snap/charmed-kafka/common/client.properties'

Note that when no other application is related to Kafka, the cluster is secured-by-default and listeners are disabled, thus preventing any incoming connection. However, even for running the commands above, listeners must be enable. If there is no other application, deploy a data-integrator charm and relate it to Kafka, as outlined in the Relation section to enable listeners.

Available Kafka bin commands can be found with:

snap info charmed-kafka --channel 3/edge

Help us improve this documentation

Most of this documentation can be collaboratively discussed and changed on the respective topic in the doc category of the Charmhub forum. See the documentation guidelines if you’d like to contribute.

Last updated 19 days ago. Help improve this document in the forum.