kafka

by cagriekin

Helm chartv0.2.0App 4.1.0Verified publisher

Apache Kafka with KRaft mode, SASL authentication, TLS encryption, and topic management

About this chart

Kafka Helm Chart

This chart installs an Apache Kafka KRaft controller, brokers, and supporting components.

Components

  • Kafka controller StatefulSet (single controller node)
  • Kafka broker StatefulSet (configurable replica count)
  • ConfigMaps for runtime configuration and JAAS credentials
  • Kafka SASL secret
  • Topic initialization job with documented topic metadata
  • Kafka exporter Deployment, Service, and optional ServiceMonitor

Values

Key options are summarized below; see values.yaml for the complete list.

KeyDescriptionDefault
fullnameOverrideBase name applied to every rendered resource. REQUIRED and must be unique per namespace."" (chart fails when left empty)
kafka.controller.replicaCountKafka controller replicas (KRaft mode)1
kafka.controller.persistence.storageClassStorageClass for controller PVC (empty uses cluster default)""
kafka.controller.persistence.sizeRequested storage capacity for the controller PVC1Gi
kafka.broker.replicaCountKafka broker replicas2
kafka.broker.persistence.storageClassStorageClass for broker PVCs (empty uses cluster default)""
kafka.broker.persistence.sizeRequested storage capacity for each broker PVC1Gi
kafka.auth.usernameSASL/PLAIN username for broker and clientsuser1
kafka.auth.passwordSASL/PLAIN password (auto-generated when empty)""
kafka.auth.existingSecretName of an existing secret providing SASL credentials (skips chart-managed secret; falls back to inline values when absent)""
kafka.auth.existingSecretKeys.usernameKey in the existing secret that stores the usernameusername
kafka.auth.existingSecretKeys.passwordKey in the existing secret that stores the passwordpassword
kafka.autoCreateTopicsEnableAllow brokers to auto-create topicstrue
kafka.deleteTopicEnableAllow topic deletiontrue
kafka.bootstrapServerExternal Kafka bootstrap server for topic initialization (when deploying against existing cluster)""
kafka.topicsMap of topic definitions keyed by topic name (supports partitions, replicationFactor, optional config map, and optional metadata){}
exporters.kafka.enabledDeploy the Kafka metrics exportertrue
serviceMonitors.enabledCreate a Prometheus ServiceMonitorfalse
serviceMonitors.labelsExtra labels applied to the ServiceMonitor when enabled{ release: kube-prometheus-stack }
kafka.controller.podSecurityContext / kafka.broker.podSecurityContextEnforced pod-level security settings (restricted profile defaults)see values.yaml
networkPolicy.enabledRestrict ingress/egress with generated NetworkPoliciestrue
autoscaling.broker.* / exporters.kafka.autoscaling.*HorizontalPodAutoscaler settings for brokers and exporterdisabled
keda.broker.*Optional KEDA ScaledObject configuration for custom metrics based scalingdisabled
kafka.*.jvmJVM heap and performance tuning options applied via environment variablessee values.yaml

Topic Specification

Each entry under kafka.topics follows this structure:

AttributeTypeDescription
partitionsintegerPartition count for the topic. Defaults to 1 when omitted.
replicationFactorintegerReplication factor applied at creation time. Defaults to 1 when omitted.
configmap<string,string>Optional per-topic broker configs mapped to the --config flags (e.g. retention.ms, segment.ms, cleanup.policy).
metadata.descriptionstringHuman-friendly summary of the topic’s purpose.
metadata.producersstring[]List of producer service names.
metadata.consumersstring[]List of consumer service names.
metadata.messageTypestringMessage schema identifier documented alongside the topic.
metadata.partitioningstringDescription of the partitioning strategy.
metadata.purposestringConcise explanation of how the topic is used end-to-end.

All metadata is surfaced in kafka-topics-configmap.yaml, and every topic is created/validated by the kafka-topic-init job using the defined partitions, replicationFactor, and config values.

Minimal Configuration Examples

Deploy with chart-managed credentials and a couple of declarative topics:

# values-minimal.yaml
fullnameOverride: platform-kafka
kafka:
  auth:
    username: my-service
    password: superSecret123
  topics:
    user-events:
      partitions: 3
      replicationFactor: 2
      metadata:
        description: User-triggered lifecycle events
        producers:
          - webapp
        consumers:
          - audit-service
    dead-letter:
      partitions: 1
      replicationFactor: 2

exporters:
  kafka:
    enabled: false

Deploy pointing at an existing secret that already carries SASL credentials:

# values-existing-secret.yaml
fullnameOverride: shared-message-bus
kafka:
  auth:
    existingSecret: kafka-shared-creds
    existingSecretKeys:
      username: sasl-user
      password: sasl-pass

Security Hardening

  • Pods for the controller, brokers, and exporter default to the Kubernetes restricted PodSecurity profile (non-root UID/GID 1000, RuntimeDefault seccomp) with container-level safeguards (no privilege escalation, all capabilities dropped).
  • Each workload has an opt-in PodDisruptionBudget enabled by default; adjust maxUnavailable (or minAvailable) under the corresponding values block when tuning availability.
  • Namespaced NetworkPolicies are rendered when networkPolicy.enabled is true, scoping ingress to namespace-local producers/consumers. Override the ingress/egress arrays per component to allow cross-namespace clients or additional control-plane access.

Scaling and JVM Guidance

  • JVM heap and performance flags are controlled via kafka.controller.jvm and kafka.broker.jvm. Defaults align with the bundled resource requests/limits (512Mi for the controller, 1Gi for brokers). Update these values alongside resources when sizing brokers for larger workloads.
  • autoscaling.broker enables an autoscaling/v2 HPA targeting the broker StatefulSet. Set CPU and/or memory utilisation thresholds explicitly; the template fails fast if neither is provided.
  • The Kafka controller template currently supports a single controller replica. Setting kafka.controller.replicaCount to anything other than 1 now fails fast to avoid producing an invalid KRaft layout.
  • exporters.kafka.autoscaling mirrors the HPA support for the exporter Deployment.
  • A keda.broker block allows hooking Kafka into custom metrics-based scaling. Supply at least one trigger definition (for example a Prometheus alert on consumer lag) and ensure the KEDA CRDs are installed in the target cluster.

Operational Runbooks

Bootstrap

  1. Set fullnameOverride to the release-specific base name; the chart fails fast when it is left empty.
  2. Provision the target namespace with restricted PodSecurity labels (enforce=restricted, audit=restricted) before installing the chart.
  3. Either leave kafka.auth.password empty to let the chart derive a deterministic password, or provide kafka.auth.password/kafka.auth.existingSecret. When existingSecret is supplied, the chart attempts to lookup the secret during template rendering. If lookup fails (e.g., due to RBAC restrictions in ArgoCD's repo server), fallback values are used for ConfigMaps; the secret will be mounted at runtime and used by pods.
  4. Confirm storage classes exist for the requested controller and broker persistence.storageClass values (or leave empty to use the cluster default).
  5. Override kafka.topics with the initial topic catalogue, including metadata to drive the topic-init job and documentation configmap.
  6. Run helm install with the desired overrides, then wait for the controller and brokers to become Ready before onboarding producers/consumers.
  7. The topic init job runs as both a Helm hook (post-install,post-upgrade) and an Argo CD PostSync hook; it keeps a content-hashed name and the controller deletes any previous run before creating a new one, so upgrades always launch a fresh job without immutable selector issues.

Topic Management

  • Declaratively manage topics through values.yaml overrides; each change triggers the topic-init job to reconcile topic partitions, replication factor, and broker configs.
  • Update metadata fields to keep the topics configmap authoritative for producers/consumers and schema references.
  • Disable kafka.autoCreateTopicsEnable in production to avoid drift from untracked, automatically created topics; rely on chart-driven reconciliation instead.

Disaster Recovery

  • Take periodic volume snapshots for controller and broker PVCs using your storage provider’s tooling; record the cluster ID output from include "kafka.kafka.clusterId".
  • Before restore, scale the StatefulSets to zero, recover PVCs from snapshot, and ensure secrets/configmaps match the backed-up state.
  • For cross-cluster migrations, seed a new cluster with identical clusterId and credentials, then replicate topics via MirrorMaker2 or consumer-driven replay.

Troubleshooting

  • Pods stuck in CrashLoopBackOff due to filesystem permission errors typically indicate custom images incompatible with the restricted security context; override the *.containerSecurityContext values as needed.
  • If clients cannot reach brokers after install, review the generated NetworkPolicies and extend networkPolicy.broker.ingress to include the producing namespaces.
  • Autoscaling template failures during helm template or helm install usually mean CPU/memory targets were omitted—set at least one threshold for each enabled autoscaler.
  • KEDA scaling requires the CRDs and operator to be present; verify kubectl get scaledobjects works cluster-wide before enabling keda.broker.

Testing

Tests require Kind and Helm installed locally.

# Run everything (creates cluster, runs tests, deletes cluster)
make test

# Template/lint tests only (no cluster needed)
make test-template

# Create cluster, then run individual suites
make cluster-create
make test-minimal    # 1 controller + 1 broker, produce/consume
make test-full       # 2 brokers + exporter + declarative topics
make cluster-delete

Compatibility Matrix

Chart VersionKafka VersionKubernetes VersionsNotes
0.1.24.1.01.27 – 1.30Validated with restricted PodSecurity admission, requires Helm 3.9+ for fail templating

Deploy kafka with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has kafka on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartkafka is pinned at v0.2.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply