# Self-host Apache Kafka

> A single broker Apache Kafka in KRaft mode (no ZooKeeper) on the official image, with a persistent volume. It is not published on the host and speaks plaintext, so reach it only from other services in this project at kafka:9092.

- Page: https://levelrail.com/templates/kafka/
- JSON: https://levelrail.com/templates/kafka.json
- Category: Infrastructure
- Licence: Apache-2.0 (Permissive license)
- Source: https://github.com/apache/kafka
- Upstream docs: https://kafka.apache.org/documentation/

## Requirements
- Memory: about 1 GiB
- amd64: unknown, arm64: unknown
- Needs configuration before start: no
- Pinned image tag: 3.8.0

## Services

| Service | Image | Tag | Ports | Volumes |
| --- | --- | --- | --- | --- |
| kafka | apache/kafka | 3.8.0 | 9092 | kafka_data -> /var/lib/kafka/data |

## Environment

| Service | Variable | Kind |
| --- | --- | --- |
| kafka | KAFKA_ADVERTISED_LISTENERS | preset |
| kafka | KAFKA_CONTROLLER_LISTENER_NAMES | preset |
| kafka | KAFKA_CONTROLLER_QUORUM_VOTERS | preset |
| kafka | KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS | preset |
| kafka | KAFKA_LISTENERS | preset |
| kafka | KAFKA_LISTENER_SECURITY_PROTOCOL_MAP | preset |
| kafka | KAFKA_LOG_DIRS | preset |
| kafka | KAFKA_NODE_ID | preset |
| kafka | KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR | preset |
| kafka | KAFKA_PROCESS_ROLES | preset |
| kafka | KAFKA_TRANSACTION_STATE_LOG_MIN_ISR | preset |
| kafka | KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR | preset |

## Deploy

### CLI

```bash
levelrail-cli templates deploy kafka --name my-kafka
```

### API

```bash
curl -X POST -H "Authorization: Bearer $TOKEN" \
  https://levelrail.example.com/api/v1/service-templates/kafka/deploy
```

Create a token in the dashboard first. This one-click route deploys it as a trial app you can keep or remove.

## First run
1. Point producers and consumers in the same project at kafka:9092. Topics are created on first use.

## Questions

### Can I deploy Apache Kafka on Dokploy or Dokku?

The services and pinned images on this page can be run on any Docker host. The public Dokploy templates list we compared does not have an entry with the same id for Apache Kafka, so on Dokploy you would use a Docker Compose application with the file from this page. Dokku deploys container images with its own commands, so the pinned image apache/kafka:3.8.0 is what you deploy there.

Self-host Apache Kafka, Apache Kafka docker compose file, deploy Apache Kafka on a VPS: this page lists the pinned image, ports, volumes and the commands for each.
