Deployment guide

Apache Kafka

Overview

Apache Kafka is an open source distributed event streaming platform. You use it to build real-time data pipelines and streaming applications, to decouple producers from consumers, and to aggregate logs and metrics at scale. This image runs Kafka in KRaft mode as a single combined broker and controller, so there is no separate ZooKeeper ensemble to operate.

What you get:

  • A Kafka broker that runs as an unprivileged service user under systemd and listens for clients on port 9092.
  • A bundled web management console with a Topics view, a Nodes view and a Consumer Groups view. You can browse individual messages, inspect partition assignments and watch consumer lag. The console runs as its own service, bound to the loopback interface, behind an nginx reverse proxy that serves it on port 80.
  • Authentication on by default. The broker enforces SASL SCRAM SHA 256, and the web console is protected by HTTP basic authentication.
  • A unique administrator password for each instance. On first boot, a one-shot service generates a fresh password, bakes it into the KRaft cluster metadata as a SCRAM credential, and reuses it for the web console. The password is written to /root/kafka-credentials.txt with mode 0600, so only the root user can read it. Two instances launched from the same Amazon Machine Image never share a password.
  • A dedicated EBS data volume mounted at /var/lib/kafka for Kafka log directories and cluster metadata. It is separate from the operating system disk and independently resizable. The mount is pinned by filesystem identifier, so it survives every reboot.

Prerequisites

Before you deploy this image, make sure you have:

  • An Amazon Web Services account where you can launch EC2 instances
  • IAM permissions to launch instances, create security groups, and subscribe to AWS Marketplace products
  • An EC2 key pair in the target Region for SSH access to the instance
  • A VPC and subnet in the target Region, with a security group allowing inbound port 22 from your management network and inbound port 80 from the networks that will reach the web console
  • Inbound port 9092 from your client network, if you plan to connect external Kafka clients
  • The AWS CLI (version 2) installed locally if you plan to deploy from the command line
1

Launch the instance from AWS Marketplace

Sign in to the AWS Management Console, open the EC2 service and choose Launch instance. Under Application and OS Images, choose AWS Marketplace AMIs and search for Apache Kafka. Choose Select on the SecureAnyCloud listing, then choose Continue on the subscription summary.

Choose an instance type of m5.large or larger, because the Kafka broker and the bundled web console are both JVM processes. Choose your EC2 key pair under Key pair (login). Under Network settings, choose your VPC and subnet, then create or choose a security group. The group must allow inbound port 22 from your management network, inbound port 80 from the networks that will reach the web console, and inbound port 9092 from your Kafka client network. Keep the root volume at the default size or larger.

Choose Launch instance. First boot initialization takes about one minute after the instance state becomes Running and the status checks pass.

2

Launch the instance from the AWS CLI

The following command launches an instance from the SecureAnyCloud Apache Kafka Marketplace AMI into an existing subnet and security group. Replace <ami-id> with the AMI ID shown on the Marketplace listing, <key-name> with your EC2 key pair name, <subnet-id> with your subnet ID, and <security-group-id> with a security group that opens ports 22, 80 and 9092 as described above.

aws ec2 run-instances \
  --image-id <ami-id> \
  --instance-type m5.large \
  --key-name <key-name> \
  --subnet-id <subnet-id> \
  --security-group-ids <security-group-id> \
  --block-device-mappings '[{"DeviceName":"/dev/sda1","Ebs":{"VolumeSize":30,"VolumeType":"gp3"}}]' \
  --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=apache-kafka-01}]'

On success, the command prints a JSON document. Note the instance ID, then get the public address once the instance is running with aws ec2 describe-instances --instance-ids <instance-id> --query "Reservations[].Instances[].PublicIpAddress" --output text.

3

Connect and retrieve the initial credentials

Connect over SSH with the key pair you chose and the public IP address from step 2. The SSH login user depends on the operating system of the AMI variant you launched:

AMI variant SSH login user

Apache Kafka on Ubuntu 24.04 ubuntu

The first boot service runs before the SSH daemon is ready, so the credentials file is in place when you first log in. Display it:

ssh <login-user>@<public-ip>
sudo cat /root/kafka-credentials.txt

The plain text file contains the broker bootstrap address, the administrator username (SecureAnyCloud), the administrator password, and the security protocol and SASL mechanism the broker expects. Copy these values to a secure place such as a password manager or encrypted vault. Do not commit them to source control. The same password authenticates Kafka clients on port 9092 and the web management console on port 80.

4

Confirm that the services are running

The image runs three services: kafka.service (the broker and controller), akhq.service (the web management console) and nginx.service (the reverse proxy in front of the console). Confirm that all three are active and check the installed Kafka version:

sudo systemctl is-active kafka.service akhq.service nginx.service ls /opt/kafka/libs/ | grep -E '^kafka-clients-' | head -1

You should see active three times, followed by the Kafka client library version:

active active active kafka-clients-4.3.0.jar
5

Build a client configuration file

Every Kafka command-line tool needs a small properties file that carries the SASL credentials. Build one from the values in the credentials file. This block reads the password directly from /root/kafka-credentials.txt, so you never paste it:

PASS=$(sudo grep '^kafka.admin.pass=' /root/kafka-credentials.txt | cut -d= -f2-)
cat > /tmp/sac.properties <<EOF security.protocol=SASL_PLAINTEXT sasl.mechanism=SCRAM-SHA-256 sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required username="sac" password="${PASS}"; EOF

The broker enforces authentication, so any tool invoked without --command-config /tmp/sac.properties is rejected. This confirms that authentication is working.

6

Inspect the broker and list topics

With the client configuration in place, query the broker API versions and list the topics. The broker API call confirms that the SASL handshake succeeds end to end:

sudo /opt/kafka/bin/kafka-broker-api-versions.sh --bootstrap-server 127.0.0.1:9092 --command-config /tmp/sac.properties | head -3 sudo /opt/kafka/bin/kafka-topics.sh --bootstrap-server 127.0.0.1:9092 --command-config /tmp/sac.properties --list

The first command prints the broker id and its supported API range. The second lists the topics, including the sample SecureAnyCloud topic created on first boot:

127.0.0.1:9092 (id: 1 rack: null isFenced: false) -> ( Produce(0): 0 to 13 [usable: 13], Fetch(1): 4 to 18 [usable: 18], __consumer_offsets sac
7

Web management console: Topics

Open a web browser and go to http://<public-ip>/. When the browser prompts for HTTP basic authentication, sign in as the SecureAnyCloud user with the password from /root/kafka-credentials.txt. The console opens on the Topics view. It lists every topic with its message count, size on disk, partition count, replication factor and any consumer groups attached to it.

Choose the magnifying glass on a topic row to open the topic detail. There you can browse individual messages, view per-partition offsets and edit topic configuration.

8

Web management console: Nodes

The Nodes view shows every broker in the cluster. A single-instance deployment has one node: broker id 1, host 127.0.0.1:9092, marked as the controller and holding all of the cluster's partitions.

When you scale to a multi-broker cluster, each broker appears here with its own share of the partitions. The controller column shows which broker currently holds the controller role.

9

Web management console: Consumer Groups

The Consumer Groups view lists every consumer group, its state, the broker coordinating it, the number of live members and the topics it consumes. The lag badge next to each topic shows how far behind the group is. A lag of zero means the group has consumed every available message.

A group whose consumers have all disconnected shows the EMPTY state but keeps its committed offsets. When a consumer rejoins, consumption resumes exactly where it stopped.

10

Produce and consume a message

Confirm the full streaming path from the command line. The first command pipes a single message into the SecureAnyCloud topic. The second reads it back from the start of the topic:

echo "hello sac $(date +%s)" | sudo /opt/kafka/bin/kafka-console-producer.sh --bootstrap-server 127.0.0.1:9092 --command-config /tmp/sac.properties --topic sac
sudo /opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server 127.0.0.1:9092 --command-config /tmp/sac.properties --topic sac --from-beginning --max-messages 1 --timeout-ms 10000

The consumer prints the earliest message in the topic, then exits. Both commands succeed only because the client configuration carries valid SASL credentials.

11

Create a new topic

Create your own topics with kafka-topics.sh. Replace <topic-name> with your topic name, and <partitions> and <replication> with your chosen numbers. On a single broker, the replication factor cannot exceed one. Add brokers first if you need replicas.

sudo /opt/kafka/bin/kafka-topics.sh --bootstrap-server 127.0.0.1:9092 --command-config /tmp/sac.properties --create --topic <topic-name> --partitions <partitions> --replication-factor <replication>

Refresh the Topics view in the web console. The new topic appears immediately.

12

Connect an external client

External producers and consumers connect to the broker on port 9092 with the same SASL SCRAM SHA 256 credentials. Make sure your security group allows inbound port 9092 from the client network, then point the client at <public-ip>:9092 with these properties:

bootstrap.servers=<public-ip>:9092 security.protocol=SASL_PLAINTEXT sasl.mechanism=SCRAM-SHA-256 sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required username="sac" password="<KAFKA_ADMIN_PASSWORD>";

For traffic that crosses an untrusted network, terminate TLS at an upstream Application Load Balancer, or switch the broker listener to SASL_SSL and supply a keystore. The Kafka documentation describes the SASL_SSL configuration in detail.

13

Tune the heap and performance

The KAFKA_HEAP_OPTS variable in /etc/default/kafka sets the broker heap. The image ships with a conservative heap suitable for development and light production. For a busier broker, raise the heap to roughly half of the instance memory, then restart the service:

sudo systemctl restart kafka.service

While the broker restarts, follow its logs with sudo journalctl -u kafka.service -f to confirm that it comes back cleanly.

14

Back up Kafka data

Kafka data lives under /var/lib/kafka/data on the dedicated EBS data volume. The simplest consistent backup is an EBS snapshot of that volume, which you can schedule with Amazon Data Lifecycle Manager. For a file-level copy, stop the broker first so the log segments are quiescent:

sudo systemctl stop kafka.service
sudo tar czf /var/tmp/kafka-data-backup.tgz -C /var/lib/kafka data
sudo systemctl start kafka.service

For zero-downtime backups, scale to a multi-broker cluster and rely on replication, or mirror topics to a second cluster.

15

Scale to a multi-broker cluster

This image is a single broker and controller. It suits development, testing, single-tenant production streaming, edge and IoT brokering, and proof-of-concept work.

To scale horizontally, launch additional brokers and give each a unique node.id. List every controller in controller.quorum.voters, and raise the replication factor on your topics so that partitions are spread across brokers. The Apache Kafka documentation describes multi-node KRaft cluster configuration step by step.

Troubleshooting

The web console does not load. Confirm that nginx.service and akhq.service are both active with sudo systemctl is-active nginx akhq. Check the console logs with sudo journalctl -u akhq.service --no-pager | tail -40. After a reboot, the console takes a few seconds to finish starting.

You need a health check. The image serves an unauthenticated health endpoint at http://<public-ip>/healthz. It returns the plain text ok with HTTP 200 once nginx is up. Point an Application Load Balancer target group health check or an external uptime monitor at /healthz. It confirms that the proxy is serving without exposing the management console.

A Kafka command hangs or is rejected. Confirm that /tmp/sac.properties exists and carries the current password from /root/kafka-credentials.txt. The file lives in /tmp and does not survive a reboot, so rebuild it with the Step 5 block after each reboot.

The broker does not start. Inspect sudo journalctl -u kafka.service --no-pager | tail -60. A common cause on a resized instance is insufficient memory for the configured heap. Lower KAFKA_HEAP_OPTS in /etc/default/kafka and restart.

Screenshots

The bundled web management console listing each Kafka topic with its message count, partitions, replication and consumer groups.

The Nodes view showing the broker as the cluster controller and its share of the cluster partitions.

The Consumer Groups view showing each group, its state, live members and per topic consumer lag.

Support

SecureAnyCloud publishes this image and provides 24/7 technical support by email and chat. Support covers Kafka deployment, broker tuning, topic and partition design, consumer group management, the web management console and scaling to a multi-broker cluster.

All product and company names are trademarks or registered trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them.

Deploy on AWS

Launch Apache Kafka on AWS with 24/7 support from SecureAnyCloud.

View on Marketplace

Need Help?

Our support team is available 24/7.

sales@secureanycloud.com

Deploy on AWS