Skip to content
Docs

This guide connects an existing Amazon MSK cluster to Kubernetes and manages its users, topics and ACLs from there.

You describe the Kafka objects with three manifests: MSK, KafkaUser and Topic. The MSK object observes an existing cluster; the platform does not create or manage the MSK cluster itself. For each user the platform generates a password, stores it in a Kubernetes Secret and in AWS Secrets Manager, associates it with the cluster for SCRAM authentication, and creates the consumer group and topic ACLs you list. Topics are created directly in Kafka.

It is good practice to include the manifests in your application’s Helm chart, so users and topics are deployed together with the application that uses them.

You need an existing MSK cluster with IAM authentication enabled. Crossplane connects to it with the IRSA role created by the Infralib aws/crossplane module.

Kafka is not enabled by default. Your Infralib configuration needs:

Module Flag Default What it does
platform-apis platform-apis.kafka.install false Installs the MSK, KafkaUser and Topic APIs. Set to true.
platform-apis platform-apis.kafka.environmentConfig.kafkaNamespace crossplane-kafka Must equal the name of the crossplane-kafka module.
crossplane-aws global.extraProviders [] Add kafka to install the AWS provider for MSK.
crossplane-aws global.createObservers, global.createNamespacedObservers false Installs the Secrets Manager provider that stores user passwords. Set both to true.
crossplane-kafka — — Manages topics and ACLs inside the cluster. Add the module to the argocd-apps step, after crossplane-core and crossplane-aws.
aws/kms — — MSK SCRAM secrets must be encrypted with a customer-managed KMS key, so in practice this terraform module is required.

If extraProviders already lists other providers, add kafka to the list instead of replacing it. Helm replaces lists instead of merging them.

For the base modules every platform API needs, see Infralib Requirements. A full example is in Infralib Configuration Example at the end of this guide.

An MSK object needs only the ARN of the existing cluster:

apiVersion: kafka.entigo.com/v1alpha1
kind: MSK
metadata:
name: test-crossplane-cluster
spec:
clusterARN: "arn:aws:kafka:<region>:<account>:cluster/<msk-cluster-name>/<uuid>"

This also creates a ProviderConfig in the background, which the Kafka provider uses to manage topics and ACLs. Users and topics refer to this object by its name in spec.clusterName.

For every field, see the MSK API reference.

A minimal KafkaUser needs only the cluster:

apiVersion: kafka.entigo.com/v1alpha1
kind: KafkaUser
metadata:
name: user-a
namespace: default
spec:
clusterName: test-crossplane-cluster

This creates:

  • A Kubernetes Secret with a generated password for the Kafka user
  • An AWS Secrets Manager secret
  • A Secrets Manager secret policy
  • A Secrets Manager secret version
  • An MSK SCRAM secret association
Field Default What it does
consumerGroups unset Creates consumer group ACLs for the user, one per listed group.
acls unset Creates topic ACLs for the user. Each entry has a topic and an operation, for example Read or Write.

For example, a user that reads from two consumer groups and one topic:

apiVersion: kafka.entigo.com/v1alpha1
kind: KafkaUser
metadata:
name: user-a
namespace: default
spec:
clusterName: test-crossplane-cluster
consumerGroups:
- alpha
- gamma
acls:
- topic: topic-a
operation: Read

For every field, see the KafkaUser API reference.

A minimal Topic needs only the cluster:

apiVersion: kafka.entigo.com/v1alpha1
kind: Topic
metadata:
name: topic-a
namespace: team-a
spec:
clusterName: test-crossplane-cluster

This creates a Kafka topic in the cluster.

Field Default What it does
partitions 3 Number of partitions, minimum 1.
replicationFactor 3 Replication factor, minimum 1.
config unset Topic-level configuration, for example retention.ms.

For example, a single-partition topic with a custom retention:

apiVersion: kafka.entigo.com/v1alpha1
kind: Topic
metadata:
name: topic-a
namespace: team-a
spec:
clusterName: test-crossplane-cluster
partitions: 1
replicationFactor: 1
config:
retention.ms: "604800012"

For every field, see the Topic API reference.

$ kubectl get MSK.kafka.entigo.com
NAME SYNCED READY COMPOSITION AGE
test-crossplane-cluster-observed True True msk-observed 7d

The KafkaUser, its Kubernetes Secret, the Secrets Manager resources and the ACLs all show SYNCED and READY as True:

$ kubectl get KafkaUser.kafka.entigo.com
NAME SYNCED READY CONNECTION-SECRET AGE
user-a True True 18h
$ kubectl get secret
NAME TYPE DATA AGE
test-crossplane-cluster-user-a-k8s Opaque 1 18h
$ kubectl get secret.secretsmanager.aws.m.upbound.io
NAME SYNCED READY EXTERNAL-NAME AGE
test-crossplane-cluster-user-a True True arn:aws:secretsmanager:us-east-1:xxxxxxxxxxxx:secret:AmazonMSK_test-cluster-name-user-a-U0dDJe 18h
$ kubectl get secretpolicy.secretsmanager.aws.m.upbound.io
NAME SYNCED READY EXTERNAL-NAME AGE
test-crossplane-cluster-user-a-policy True True arn:aws:secretsmanager:us-east-1:xxxxxxxxxxxx:secret:AmazonMSK_test-cluster-name-user-a-U0dDJe 18h
$ kubectl get secretversion.secretsmanager.aws.m.upbound.io
NAME SYNCED READY EXTERNAL-NAME AGE
test-crossplane-cluster-user-a-version True True 18h
$ kubectl get accesscontrollists
NAME READY SYNCED EXTERNAL-NAME AGE
user-a-alpha-cg True True {"ResourceName":"alpha","ResourceType":"Group","ResourcePrincipal":"User:user-a","ResourceHost":"*","ResourceOperation":"Read","ResourcePermissionType":"Allow","ResourcePatternTypeFilter":"Literal"} 18h
user-a-gamma-cg True True {"ResourceName":"gamma","ResourceType":"Group","ResourcePrincipal":"User:user-a","ResourceHost":"*","ResourceOperation":"Read","ResourcePermissionType":"Allow","ResourcePatternTypeFilter":"Literal"} 18h
topic-a-user-a-read True True {"ResourceName":"topic-a","ResourceType":"Topic","ResourcePrincipal":"User:user-a","ResourceHost":"*","ResourceOperation":"Read","ResourcePermissionType":"Allow","ResourcePatternTypeFilter":"Literal"} 19h

The user’s secret appears in AWS Secrets Manager:

  1. Secrets Manager secret
  2. Secret version
  3. Secret version password, taken from the generated Kubernetes Secret
  4. Secret policy

The secret is associated with the cluster for SCRAM authentication:

The user’s consumer group ACLs:

The user’s topic ACLs:

$ kubectl get Topic.kafka.entigo.com -A
NAMESPACE NAME SYNCED READY CONNECTION-SECRET AGE
team-a topic-a True True 19h
$ kubectl get topic.topic.kafka.m.crossplane.io
NAME READY SYNCED EXTERNAL-NAME AGE
topic-a True True team-a 19h

The topic in Kafka:

Symptom Cause / fix
no matches for kind "KafkaUser" (or MSK, Topic) The API is not installed. Check the Prerequisites.
SYNCED is False The platform could not create a resource. kubectl describe KafkaUser.kafka.entigo.com <name> (or Topic.kafka.entigo.com) shows the error under Conditions and Events.
Topics or ACLs are never created The Kafka provider manages them. Check that the crossplane-kafka module is installed and that kafkaNamespace matches its name.
The Secrets Manager secret is not created Check that createObservers and createNamespacedObservers are on and that a customer-managed KMS key exists, see Prerequisites.

There are no Kafka-specific defaults for developers to worry about. The cluster-wide settings are set once by the platform administrator.

Setting Default What it does
kafkaNamespace crossplane-kafka Namespace of the crossplane-kafka module. Must equal the module name.
tags {} Cloud tags added to the cloud resources created for Kafka users and topics. See Resource Tagging.
steps:
- name: net
type: terraform
modules:
...
- name: kms
source: aws/kms
...
- name: apps
type: argocd-apps
modules:
...
- name: crossplane-aws
source: crossplane-aws
inputs:
global:
createObservers: true
createNamespacedObservers: true
extraProviders:
- kafka
- name: crossplane-kafka
source: crossplane-kafka
...
- name: platform-apis
source: platform-apis
inputs:
platform-apis:
kafka:
install: true
environmentConfig:
kafkaNamespace: crossplane-kafka # = the crossplane-kafka module name
tags:
cost-center: CC-12345