Skip to content

Latest commit

 

History

History
336 lines (272 loc) · 12.4 KB

quickstart.md

File metadata and controls

336 lines (272 loc) · 12.4 KB

Kafscale Quickstart

For a first local run, start with the Docker Compose quick start. This guide covers a minimal installation on a cloud Kubernetes cluster using the Helm chart in this repo. Connect your S3 explains bucket, region, endpoint and credentials settings across Helm, Compose and the native CLI.

Prerequisites

  • Kubernetes 1.26+
  • Helm 3.14+
  • kubectl access to your cluster
  • jq (used to build the login request and the optional session token patch)
  • An S3-compatible bucket and credentials
  • Optional: external etcd endpoints (or let the operator manage etcd)

1) Create a Namespace

kubectl create namespace kafscale

2) Create an S3 Credentials Secret

The operator passes the secret through to broker pods as environment variables. Use AWS-style keys.

(
  set -euo pipefail
  umask 077
  credentials_dir=$(mktemp -d)
  trap 'rm -rf "$credentials_dir"' EXIT
  printf 'AWS access key ID: '
  IFS= read -r AWS_ACCESS_KEY_ID
  printf 'AWS secret access key: '
  IFS= read -rs AWS_SECRET_ACCESS_KEY
  printf '\n'
  : "${AWS_ACCESS_KEY_ID:?Access key ID must not be empty}"
  : "${AWS_SECRET_ACCESS_KEY:?Secret key must not be empty}"
  printf '%s' "$AWS_ACCESS_KEY_ID" > "$credentials_dir/AWS_ACCESS_KEY_ID"
  printf '%s' "$AWS_SECRET_ACCESS_KEY" > "$credentials_dir/AWS_SECRET_ACCESS_KEY"
  unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY
  kubectl -n kafscale create secret generic kafscale-s3 \
    --from-file=AWS_ACCESS_KEY_ID="$credentials_dir/AWS_ACCESS_KEY_ID" \
    --from-file=AWS_SECRET_ACCESS_KEY="$credentials_dir/AWS_SECRET_ACCESS_KEY"
)

If you need a session token:

printf 'AWS session token: '
read -rs AWS_SESSION_TOKEN
echo
printf '%s' "$AWS_SESSION_TOKEN" | jq -n --rawfile t /dev/stdin \
  '{data:{AWS_SESSION_TOKEN:($t|@base64)}}' | \
  kubectl -n kafscale patch secret kafscale-s3 --type=merge --patch-file=/dev/stdin
unset AWS_SESSION_TOKEN

3) Install the Operator (Cloud Kubernetes)

Option A: Operator-managed etcd

Leave etcd endpoints empty in both the Helm values and the cluster spec. The operator will create a 3-node etcd StatefulSet and use it.

helm upgrade --install kafscale deploy/helm/kafscale \
  --namespace kafscale --create-namespace \
  --set 'operator.etcdEndpoints={}'

Image tags follow the chart appVersion unless you override them. If you install from a checkout of main, that tag may be older than the branch; set useLatest=true on each image the install runs. For a full list of image keys, including useLatest and tag for the operator, broker, etcd-tools, console, proxy, schema registry, MCP and the operator-managed LFS proxy, see Installing with Helm.

Option B: External etcd

Provide reachable etcd endpoints.

helm upgrade --install kafscale deploy/helm/kafscale \
  --namespace kafscale --create-namespace \
  --set 'operator.etcdEndpoints[0]=http://etcd.kafscale.svc:2379'

http://etcd.kafscale.svc:2379 is an example external etcd Service, not the operator-managed etcd client. Managed etcd is <cluster>-etcd-client.<namespace>.svc.cluster.local:2379. For the image tags, see the note under Option A and Installing with Helm.

4) Create a KafscaleCluster

This creates the broker deployment and wires S3 + etcd into the broker env.

cat <<'EOF' | kubectl apply -n kafscale -f -
apiVersion: kafscale.io/v1
kind: KafscaleCluster
metadata:
  name: demo
spec:
  brokers:
    replicas: 3
  s3:
    bucket: kafscale-demo
    region: us-east-1
    credentialsSecretRef: kafscale-s3
  etcd:
    endpoints: []
EOF

If you are using external etcd, set spec.etcd.endpoints instead:

cat <<'EOF' | kubectl apply -n kafscale -f -
apiVersion: kafscale.io/v1
kind: KafscaleCluster
metadata:
  name: demo
spec:
  brokers:
    replicas: 3
  s3:
    bucket: kafscale-demo
    region: us-east-1
    credentialsSecretRef: kafscale-s3
  etcd:
    endpoints:
      - http://etcd.kafscale.svc:2379
EOF

For broker autoscaling, see Scaling brokers. The HPA needs a metrics server and CPU/memory requests in spec.brokers.resources; <unknown> utilization targets mean these requirements are not met or metrics are not ready. Apply the current CRD before setting resource requests.

For S3-compatible endpoints (MinIO, etc), add:

  s3:
    endpoint: http://minio.kafscale.svc:9000

The S3 bucket must already exist. Create it if needed. For MinIO and other in-cluster S3-compatible endpoints, apply this Job so the Service name resolves and the Job reads credentials from the kafscale-s3 Secret created in step 2:

cat <<'EOF' | kubectl apply -n kafscale -f -
apiVersion: batch/v1
kind: Job
metadata:
  name: s3-mb
spec:
  backoffLimit: 0
  template:
    spec:
      restartPolicy: Never
      containers:
        - name: s3-mb
          image: amazon/aws-cli:2.15.0
          args:
            - s3
            - mb
            - s3://kafscale-demo
            - --endpoint-url
            - http://minio.kafscale.svc:9000
          envFrom:
            - secretRef:
                name: kafscale-s3
          env:
            - name: AWS_DEFAULT_REGION
              value: us-east-1
EOF
kubectl -n kafscale wait --for=condition=complete job/s3-mb --timeout=120s
kubectl -n kafscale logs job/s3-mb
kubectl -n kafscale delete job s3-mb

BucketAlreadyOwnedByYou means the bucket already exists.

For AWS S3, drop --endpoint-url, or run aws s3 mb s3://kafscale-demo --region us-east-1.

5) Create a Topic

cat <<'EOF' | kubectl apply -n kafscale -f -
apiVersion: kafscale.io/v1
kind: KafscaleTopic
metadata:
  name: orders
spec:
  clusterRef: demo
  partitions: 3
EOF

6) Produce and Consume

The cluster in step 4 has spec.brokers.replicas: 3. Metadata advertises each broker as <cluster>-broker-<n>.<cluster>-broker-headless.<namespace>.svc.cluster.local:9092, which is only reachable from inside the cluster. For the quickstart cluster demo in namespace kafscale, that is demo-broker-0.demo-broker-headless.kafscale.svc.cluster.local:9092. kubectl port-forward to svc/demo-broker cannot work with this cluster.

Run a long-lived client pod and execute kcat after the pod is ready. This keeps output attached even when kcat exits immediately:

kubectl -n kafscale run kcat-client --restart=Never --image=edenhill/kcat:1.7.1 --command -- sleep 86400
kubectl -n kafscale wait --for=condition=Ready pod/kcat-client --timeout=120s
kubectl -n kafscale exec kcat-client -- kcat -b demo-broker:9092 -L
printf '%s\n' hello | kubectl -n kafscale exec -i kcat-client -- kcat -b demo-broker:9092 -t orders -P
kubectl -n kafscale exec kcat-client -- kcat -b demo-broker:9092 -t orders -C -o beginning -e
kubectl -n kafscale delete pod kcat-client

Or enable the Kafka proxy (proxy.enabled=true) and set proxy.advertisedHost / proxy.advertisedPort to an address the client can reach. For local clusters, pin proxy.service.nodePort (see docs/operations.md).

Port-forward to svc/<cluster>-broker only works when spec.brokers.replicas is 1 and spec.brokers.advertisedHost is set to an address the client can reach, for example 127.0.0.1.

Default nontransactional idempotent producers are supported. Leave transactional.id unset and use acks=all; transactions remain unsupported. Both isolation levels are supported for nontransactional records. Upgrade all brokers and proxies before enabling idempotence on older deployments.

Service names for a KafscaleCluster named <cluster> in namespace <namespace> are documented in Service names. The operator-managed etcd client is <cluster>-etcd-client.<namespace>.svc.cluster.local:2379, and the broker Service is <cluster>-broker.<namespace>.svc.cluster.local:9092 (metrics on port 9093).

7) Delete a topic

Deleting a KafscaleTopic custom resource does not delete the Kafka topic. The operator does not call DeleteTopics and does not write a /kafscale/deleted-topics record, so the topic stays in Kafka metadata and its S3 data is not recorded for kafscale-cli prune.

If you created the topic with a KafscaleTopic, delete that resource first.

kubectl -n kafscale delete kafscaletopic orders

Then use the Kafka DeleteTopics API from a client that can reach the brokers, or the console DELETE /ui/api/status/topics/<topic> endpoint after signing in (see Console). The console needs console.etcdEndpoints set to the cluster's etcd and console.s3Namespace set to the cluster namespace. Without console.etcdEndpoints, that delete returns 503 with metadata store not configured. Without console.s3Namespace, it returns 503 with console S3 namespace not configured; set KAFSCALE_S3_NAMESPACE to the KafscaleCluster namespace. Without console.auth.existingSecret, and without both console.auth.username and console.auth.password, login returns 503 and every other /ui/api call returns 503 with ui auth disabled. The chart sets those from the Secret named by console.auth.existingSecret (keys username and password). Use that Secret, as shown below. Never pass the console password with --set or any other command-line flag: it would end up in shell history and the process list. If you must keep console.auth.username and console.auth.password in Helm values, put them in a values file readable only by you (mode 600) and pass it with -f.

For the quickstart cluster demo in namespace kafscale, when etcd is operator-managed, first create the console login Secret. Enter the console password when prompted, and keep this shell open: the login below runs here and reads $CONSOLE_PASSWORD. If kafscale-console-auth already exists, delete it first with kubectl -n kafscale delete secret kafscale-console-auth.

printf 'Console password: '
read -rs CONSOLE_PASSWORD
echo
printf '%s' "$CONSOLE_PASSWORD" | kubectl -n kafscale create secret generic kafscale-console-auth \
  --from-literal=username=kafscaleadmin --from-file=password=/dev/stdin

Upgrade the existing release while retaining its image tags, proxy settings, and other install values. --reuse-values applies to this existing release; if you manage values in a file, pass that same file with -f instead:

helm upgrade --install kafscale deploy/helm/kafscale \
  --namespace kafscale --reuse-values \
  --set 'console.etcdEndpoints[0]=http://demo-etcd-client.kafscale.svc.cluster.local:2379' \
  --set 'console.s3Namespace=kafscale' \
  --set 'console.auth.existingSecret=kafscale-console-auth'

If you used the external etcd option in step 4, set console.etcdEndpoints to that etcd endpoint instead, for example --set 'console.etcdEndpoints[0]=http://etcd.kafscale.svc:2379'.

The Helm release named kafscale exposes the console as Service kafscale-console on port 80. Port-forward it in a second terminal and leave it running:

kubectl -n kafscale port-forward svc/kafscale-console 8080:80

Back in the first shell, where you entered the password, sign in with POST /ui/api/auth/login and delete topic orders:

printf '%s' "$CONSOLE_PASSWORD" | jq -cRs '{username:"kafscaleadmin",password:.}' | \
  curl -sS -c console.cookies -X POST -H 'Content-Type: application/json' \
  -d @- http://127.0.0.1:8080/ui/api/auth/login

curl -sS -b console.cookies -X DELETE \
  http://127.0.0.1:8080/ui/api/status/topics/orders

unset CONSOLE_PASSWORD

curl -c stores the kafscale_ui_session cookie from login; curl -b sends it with the delete. If the CR still exists, the next operator reconcile publishes the topic again.

Next Steps

  • docs/operations.md for etcd/S3 HA and backup guidance
  • docs/development.md for build/test workflows
  • docs/user-guide.md for runtime behavior and limits