Created
April 4, 2023 09:57
-
-
Save langerma/42f0ad7152a5221f38bf9b95565148f6 to your computer and use it in GitHub Desktop.
deploy kafka kraft cluster with nomad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
job "kafka" { | |
datacenters = ["yourdatacenter"] | |
type = "service" | |
update { | |
stagger = "5s" | |
max_parallel = 3 | |
} | |
group "kafka" { | |
constraint { | |
attribute = "${attr.unique.hostname}" | |
operator = "regexp" | |
value = "^kf1|kf2|kf3$" | |
} | |
count = 3 | |
service { | |
name = "kafka-plain" | |
port = "kafka_plain" | |
tags = ["kafka", "log"] | |
meta { | |
allocation = "${NOMAD_ALLOC_INDEX}" | |
} | |
check { | |
type = "tcp" | |
port = "kafka_plain" | |
interval = "10s" | |
timeout = "2s" | |
} | |
} | |
service { | |
name = "kafka-controller" | |
port = "kafka_controller" | |
tags = ["kafka-controller"] | |
meta { | |
allocation = "${NOMAD_ALLOC_INDEX}" | |
} | |
} | |
service { | |
name = "kafka-jmx-exporter" | |
port = "kafka_jmx_exporter" | |
tags = ["metric"] | |
check { | |
type = "tcp" | |
port = "kafka_jmx_exporter" | |
interval = "10s" | |
timeout = "2s" | |
} | |
} | |
network { | |
port "kafka_plain" { | |
static = 9092 | |
} | |
port "kafka_controller" { | |
static = 9093 | |
} | |
port "kafka_jmx_exporter" { | |
static = 17777 | |
} | |
mode = "host" | |
} | |
volume "kafka" { | |
type = "csi" | |
source = "kafka-data-" | |
attachment_mode = "file-system" | |
access_mode = "multi-node-multi-writer" | |
per_alloc = true | |
read_only = false | |
} | |
task "kafka" { | |
artifact { | |
source = "https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.16.0/jmx_prometheus_javaagent-0.16.0.jar" | |
destination = "local/jmx_prometheus_javaagent.jar" | |
mode = "file" | |
} | |
artifact { | |
source = "https://raw.githubusercontent.com/prometheus/jmx_exporter/master/example_configs/kafka-2_0_0.yml" | |
destination = "local/config.yml" | |
mode = "file" | |
} | |
driver = "docker" | |
volume_mount { | |
volume = "kafka" | |
destination = "/bitnami" | |
} | |
config { | |
image = "bitnami/kafka:3.4" | |
ports = [ | |
"kafka_plain", | |
"kafka_controller", | |
"kafka_jmx_exporter" | |
] | |
network_mode = "host" | |
} | |
template { | |
data = <<EOT | |
KAFKA_CFG_CONTROLLER_QUORUM_VOTERS={{ range $index, $element := service "kafka-controller|any" }}{{- $allocation := (index .ServiceMeta "allocation") -}} {{if ne $index 0}},{{end}}{{$allocation | parseInt | add 1}}@{{$element.Address}}:{{$element.Port}}{{end}} | |
KAFKA_BROKER_ID={{ env "NOMAD_ALLOC_INDEX" | parseInt | add 1 }} | |
EOT | |
destination = "secrets/file.env" | |
env = true | |
change_mode = "noop" | |
} | |
env { | |
BITNAMI_DEBUG = "true" | |
KAFKA_ENABLE_KRAFT = "yes" | |
KAFKA_KRAFT_CLUSTER_ID = "createyourid" | |
KAFKA_CFG_PROCESS_ROLES = "broker,controller" | |
KAFKA_CFG_CONTROLLER_LISTENER_NAMES = "CONTROLLER" | |
KAFKA_CFG_LISTENERS = "PLAINTEXT://:9092,CONTROLLER://:9093" | |
KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP = "CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT" | |
KAFKA_CFG_ADVERTISED_LISTENERS = "PLAINTEXT://:9092" | |
KAFKA_CFG_INITIAL_BROKER_REGISTRATION_TIMEOUT_MS = "48000" | |
ALLOW_PLAINTEXT_LISTENER = "yes" | |
KAFKA_HEAP_OPTS = "-Xmx768m -Xms768m" | |
KAFKA_OPTS = "-javaagent:/local/jmx_prometheus_javaagent.jar=${NOMAD_PORT_kafka_jmx_exporter}:/local/config.yml" | |
} | |
resources { | |
memory = 1024 | |
cpu = 2000 | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment