Skip to content

Kubernetes

Custom resources, the operator and the kubectl plugin

Resources are stored in Redis by default, which lets Cloud Streams run anywhere. On Kubernetes, they can be Kubernetes custom resources instead, managed with kubectl, GitOps tools and Kubernetes RBAC, as well as with the API and the dashboard (see #274).

Architecture

Component Deployed by Role
CustomResourceDefinitions the chart’s crds/, then the operator the kinds of Cloud Streams: gateways, brokers, subscriptions, sinks, feeds and schemas
Operator (cloud-streams-operator image) the chart, 2 replicas deploys a gateway or a broker from its resource, reports its conditions, and validates resources with an admission webhook. One replica, elected with a Lease, reconciles; every replica serves the webhook
API the chart a gateway that serves the management API and the dashboard, for every namespace or for those of api.namespaces
Gateways and brokers the operator, from their resources each runs in the Kubernetes namespace of its resource, with rights in that namespace only
KurrentDB and Redis you Redis still holds the partition index, the deduplication keys, the rate limits and the leases of the subscriptions

Installation

Kubernetes 1.30 or later is required.

helm install cloud-streams oci://ghcr.io/neuroglia-io/charts/cloud-streams --version <release> -n cloud-streams --create-namespace \
  --set resources.store=kubernetes \
  --set kurrentdb.connectionString='kurrentdb://kurrentdb:2113?tls=false' \
  --set redis.connectionString='redis:6379' \
  --set gateways[0].name=orders,gateways[0].namespace=tenant-a \
  --set brokers[0].name=orders,brokers[0].namespace=tenant-a
  • Declared gateways and brokers: gateways and brokers declare resources, which the operator creates once, with their namespaces, when they’re missing. It never updates nor deletes them, so that they may be changed with kubectl or the dashboard. One deleted with kubectl isn’t created again, unless its declaration changes: the operator records the declarations it created in the <release>-operator-declarations ConfigMap. An item’s replicaCount, resources, scheduling settings and endpoints become the workload of its spec, and its spec is the rest of it.
  • Certificates of the webhook: by default, the operator issues them with a CA of its own, stores them in the <release>-operator-tls secret, sets the webhook’s CA bundle, and rotates them before they expire, without downtime. With operator.webhook.certManager.enabled, cert-manager issues them instead, with operator.webhook.certManager.issuerRef or a self-signed issuer, and its CA injector sets the bundle. GitOps tools should ignore the caBundle of the ValidatingWebhookConfiguration, which the chart doesn’t set.
  • Defaults of the workloads: operator.workloads.gateway and operator.workloads.broker set the replicas, resources, ingress class and environment variables of the workloads the operator deploys, e.g. to configure authentication.
  • Not supported in this mode: secrets.files, and the env, envFrom and fullnameOverride of the items of gateways and brokers. The chart refuses them.

Without the chart, the processes choose the store with their configuration:

CloudStreams:
  Resources:
    Store: kubernetes                  # redis (default) or kubernetes
    Kubernetes:
      DefaultNamespace: cloud-streams  # the Kubernetes namespace of the 'default' namespace of Cloud Streams; 'default' by default
      CreateNamespaces: true           # whether creating a namespace of Cloud Streams creates its Kubernetes namespace, or only labels an existing one
      Namespaces: []                   # the namespaces the process serves, by default all of them (see 'Restricted processes' below)
      Context: docker-desktop          # outside of a cluster only: the kubeconfig context, or KubeConfigPath. In a cluster, the pod's service account is used

Workloads

The operator deploys a gateway or a broker in the Kubernetes namespace of its resource, with objects named <name>-gateway or <name>-broker:

  • Objects: a deployment, a service, a pod disruption budget, the ingresses and HTTPRoutes gateways ask for, a service account and its role binding, and a copy of the connection strings. They’re owned by the resource: deleting the resource deletes them.
  • spec.workload: sets the replicas, the resources, the node selector, tolerations, affinity and topology spread constraints, and the pods’ labels and annotations. autoscaled leaves the replicas to an autoscaler (see Autoscaling). For gateways, endpoints serves and exposes their endpoints (see Exposure). The image, the command, the environment and the service account can’t be set there: whoever may edit a gateway could otherwise run any code with its rights.
  • Status: the operator reports Ready, Progressing and Degraded conditions, and the available replicas, which kubectl get gateways and the dashboard show, e.g. kubectl wait --for=condition=Ready gateway/orders -n tenant-a. It records how they change as events (see Events below).
  • External workloads: a gateway or a broker that creates its own resource annotates it cloud-streams.io/workload: external, and the operator doesn’t deploy it. The chart’s API is one.
apiVersion: cloud-streams.io/v1
kind: Gateway
metadata:
  name: orders
  namespace: tenant-a
spec:
  workload:
    replicas: 3
    resources: { requests: { cpu: 250m, memory: 256Mi } }
    endpoints:
      public:
        ingress: { hosts: [ orders.example.com ], tlsSecretName: orders-tls }

Events

The operator and the brokers record what happens to resources as Kubernetes events, events.k8s.io/v1, which kubectl describe and kubectl events list:

Recorded by Of Events
the operator, cloud-streams.io/operator gateways and brokers Provisioned, when it creates a declared one. RollingOut, for a new generation of the spec. Ready, and NotReady when it stops being ready other than for a rollout. ApplyFailed, at every failed attempt, and the other reasons of the Degraded condition, e.g. ProgressDeadlineExceeded
the brokers, cloud-streams.io/broker subscriptions SubscriberUnreachable and SubscriberReachable. Suspended, Faulted and Resumed. DeadLettered, DeadLetterFailed, and EventDropped for a subscription without an offset
Events:
  Type     Reason                 Age                From                     Message
  ----     ------                 ----               ----                     -------
  Warning  SubscriberUnreachable  3m                 cloud-streams.io/broker  Connection refused (unreachable.tenant-a.svc:80)
  Warning  DeadLettered           2m (x41 over 3m)   cloud-streams.io/broker  Dead-lettered cloud events it failed to deliver, to the subscription's dead letters
  • Repeats: the repeats of an event within 6 minutes are counted by the series of the first one, which is updated at most every 30 seconds. A DeadLettered event counts the dead letters of a subscription, which tell the cloud events apart.
  • Rate limit: an object records at most 25 new events at once, then one every 5 minutes. The others are dropped, and so are those that can’t be written: events are a diagnostic, never a reason for a process to fail.
  • Retention: the API server deletes events after an hour by default (--event-ttl). Conditions, metrics and logs are the lasting record.
  • Rights: the operator and the brokers may create and patch events, a broker in its own namespace only. In Redis mode, none are recorded.

Admission webhook

Resources written to Kubernetes directly, e.g. with kubectl, are validated by the validators of the API, and refused with the same errors:

Error from server: admission webhook "resources.cloud-streams.io" denied the request: The subscription 'orders' is invalid: Exactly one of 'spec.subscriber.endpoint', 'spec.subscriber.sink' and 'spec.subscriber.ref' must be set
  • Namespaces: resources may only be created in a namespace of Cloud Streams.
  • Availability: its failurePolicy is Fail by default, so that no invalid resource is admitted while it’s down. The API and the operator validate in process, and aren’t intercepted.

Namespaces

A namespace of Cloud Streams is a Kubernetes namespace labelled cloud-streams.io/enabled=true:

  • Creating a namespace labels its Kubernetes namespace, or creates it.
  • Deleting one removes the label, and keeps the Kubernetes namespace.
  • Default namespace: resources.kubernetes.defaultNamespace, by default the release’s namespace, is the default namespace of Cloud Streams.
  • Restricted processes: CloudStreams:Resources:Kubernetes:Namespaces, e.g. [ tenant-a, tenant-b ], restricts a process to those namespaces, by default all of them. Its API, dashboard, hubs and MCP tools then only show and change their resources, and refuse the others with 403 Forbidden. The chart’s api.namespaces sets it for the API, and the operator sets it for the workloads it deploys.
    • Rights: the process lists and watches each namespace on its own, never the whole cluster, so it only needs rights in those Kubernetes namespaces, e.g. from a RoleBinding in each. It still reads the CRDs, the schemas and the namespaces it serves.
    • Default namespace: it only labels or creates the default namespace if it serves it.

Kubernetes RBAC

The chart’s ClusterRoles match the roles of Cloud Streams (see Roles). They’re aggregated to Kubernetes’ own, and bound with a RoleBinding, they grant access to one namespace, as Namespaced roles do:

Role of Cloud Streams ClusterRole Aggregated to Rights on the kinds of Cloud Streams
reader <release>-reader view get, list and watch
operator <release>-operator edit the reader’s, and editing subscriptions, e.g. to suspend or resume them
admin <release>-admin admin every verb
  • Operations that aren’t plain verbs: skipping an event, replaying from a time, resuming a faulted subscription, and reading or redelivering dead letters. The Kubernetes API server serves them as subresources of the aggregated API, which Kubernetes RBAC authorizes (see kubectl plugin below). They’re also calls to the management API, which authorizes them with the roles of Cloud Streams.
  • Field-level rights: Kubernetes RBAC can’t restrict the fields a user edits: the operator ClusterRole may edit subscriptions as a whole, whereas the API only lets an operator suspend, resume, replay and skip.
  • Components: each one has only the rights it needs. The API manages the resources of the namespaces it serves. A gateway reads and writes those of its own namespace, and a broker reads its subscriptions, writes their status and records their events. Both read the CRDs, the schemas and the namespaces across the cluster. The operator manages the workloads’ objects, and may write, but not read, the secrets of other namespaces, since it copies the connection strings there.

Secrets

With the kubernetes secret provider, the secrets of a namespace of Cloud Streams are those of its Kubernetes namespace, labelled cloud-streams.io/secret=true (see Transports):

  • Own secrets: a gateway or a broker the operator deploys reads those of its own Kubernetes namespace, with no cloud-streams.io/namespace label needed: where a secret lives tells whose it is.
  • Shared secrets: those of the release’s namespace, not labelled with a namespace, are read by the namespaces secrets.sharedWith lists, by default default. The operator binds the service accounts of their gateways and brokers to the <release>-shared-secrets Role, which lets them get the secrets of the release’s namespace.
  • Default namespace: when it’s the release’s namespace, as by default, its own secrets are told apart from the shared ones with the cloud-streams.io/namespace: default label, as in Redis mode.
  • Rights: the operator only binds a workload to the secrets of its own namespace, and to the shared ones it’s allowed. Kubernetes can’t restrict reads by label: a gateway may read every secret of its namespace, so keep the others out of the namespaces of Cloud Streams, or use Vault.

Coordination

  • Health monitors: a single process at a time probes a gateway or a broker, which holds a Lease named cloud-streams-health-<kind>-<name>.<namespace> in the namespace of the monitored resource. The API and the gateways of that namespace compete for it.
  • Data-protection keys: the keys that encrypt the dashboard’s cookies are kept in the cloud-streams-data-protection secret of the process’ namespace, shared by the replicas that serve the dashboard.
  • Subscriptions: broker replicas keep sharing subscriptions with leases in Redis, which Redis is required for anyway: a Lease per subscription would cost the API server a write every few seconds per subscription.

Usage

kubectl get gateways,brokers -A               # with their readiness and available replicas
kubectl get subscriptions -A                  # with their phase, subscriber state and acknowledged offset
kubectl apply -f subscription.yaml            # the same YAML as the dashboard and the API
kubectl -n orders patch subscription billing --type merge -p '{"spec":{"suspended":true}}'

kubectl plugin

kubectl cloud-streams lists subscriptions with their lag, describes them with their fault and their events, and operates them: it suspends, resumes, skips the event that faulted a subscription, replays it from a time, and reads and redelivers its dead letters. It reads the stream of a namespace too. See its documentation for how to install it, with krew or from the binaries of a release.

kubectl cloud-streams get subscriptions -n orders           # with their phase, lag and faulted offset
kubectl cloud-streams skip billing -n orders                # the event that faulted it, read from its status
kubectl cloud-streams replay billing -n orders --from 2026-11-28T00:00:00Z
kubectl cloud-streams dead-letters billing -n orders
kubectl cloud-streams trace order-42 -n orders             # where's my event: what each subscription did with it

It calls the subresources of the aggregated API subresources.cloud-streams.io/v1, which the API serves to the Kubernetes API server, with api.aggregation.enabled, true by default in Kubernetes mode:

  • Authentication: the API server authenticates the user, with any credentials of their kubeconfig, and proxies the request over TLS with its front-proxy client certificate. The API trusts the user that certificate vouches for, and no one else: it reads the CA and the allowed names from the kube-system/extension-apiserver-authentication ConfigMap.
  • Authorization: the API asks the API server, with a SubjectAccessReview, whether the user may get what reads, i.e. subscriptions/health, subscriptions/deadletters, cloudevents, cloudevents/trace and asyncapi, and create what acts, i.e. subscriptions/suspend, resume, skip, replay and redeliver. The reader ClusterRole grants the former, and the operator and admin ClusterRoles both. kubectl auth can-i can’t name a subresource of a group that serves no parent resource: use --as instead, e.g. kubectl get --raw <path> --as=<user>. Failures are Kubernetes Status objects, as for any resource.
  • Paths: /apis/subresources.cloud-streams.io/v1/namespaces/{namespace}/subscriptions/{name}/{subresource}, and .../namespaces/{namespace}/cloudevents, e.g. kubectl get --raw /apis/subresources.cloud-streams.io/v1/namespaces/orders/subscriptions/billing/health, or echo '{}' | kubectl create --raw .../billing/suspend -f -.
  • Certificates: the API serves the aggregated API on port 8443, api.aggregation.port, with a certificate the operator issues with the CA of its webhook, and sets the CA bundle of the APIService. With operator.webhook.certManager.enabled, cert-manager issues it, and its CA injector sets the bundle. The API reloads a renewed certificate without restarting.
  • One per cluster: the v1.subresources.cloud-streams.io APIService is cluster-wide: a single release may enable it.
  • Availability: while the API is down, the APIService is unavailable. Discovery then warns about its group, and Kubernetes can’t finish deleting namespaces, as with any aggregated API, e.g. metrics-server.

CustomResourceDefinitions

  • Source: they’re generated from the definitions of Cloud Streams, and shipped in the chart’s crds/ directory. A test fails if they drift from the definitions. CLOUDSTREAMS_UPDATE_CRDS=true dotnet test --filter CustomResourceDefinitionTests regenerates them.
  • Installation: helm install installs them. helm upgrade doesn’t update them, so the operator does:
    • Upgrades: its leader applies the definitions of its version when it starts leading, with server-side apply, so upgrading the operator upgrades them, whichever tool deploys it. Gateways, brokers and declared resources are only reconciled once they’re applied, so that no field is pruned.
    • Versions: each definition carries the version that applied it, in its cloud-streams.io/version annotation. A definition applied by a newer version is kept as it is, so that an older operator, e.g. of another release in the cluster, never removes its fields.
    • Rights: the operator may get, create and patch the six definitions of Cloud Streams, and no other. On a cluster where it may not, set operator.manageCustomResourceDefinitions=false, and have an administrator run kubectl apply --server-side --force-conflicts -f deployments/helm/cloud-streams/crds on every upgrade.
    • Redis mode: there’s no operator to update them, and nothing uses them: on a cluster where you may not create CRDs, install with --skip-crds.
  • Startup check: gateways, brokers and the API never create nor update them, and fail at startup if they aren’t installed.
  • Schemas: Kubernetes only accepts structural schemas. Fields that can be an address or an object, such as endpoints and feeds, are kept as they are by Kubernetes, and checked by the validators of Cloud Streams. The API and the dashboard keep serving the richer definitions.

From the Redis mode

The operator’s image copies the namespaces and the resources of Redis into Kubernetes, with their status, so that subscriptions resume from their offsets:

  1. Install the CRDs: kubectl apply --server-side --force-conflicts -f deployments/helm/cloud-streams/crds.

  2. Scale the brokers to 0, so that no offset moves during the copy.

  3. Copy the resources, with a kubeconfig whose user may create namespaces and the resources of Cloud Streams. --dry-run only tells what would be copied, and resources that already exist are skipped, so the copy may be run again:

    docker run --rm -v ~/.kube:/home/app/.kube:ro ghcr.io/neuroglia-io/cloud-streams-operator:<release> \
      migrate --redis redis.example.com:6379 --context my-cluster --default-namespace cloud-streams

    The resources of the default namespace go to --default-namespace, which must be the chart’s resources.kubernetes.defaultNamespace, by default the release’s namespace.

  4. Upgrade the release with resources.store=kubernetes. The operator then deploys the gateways and brokers of the copied resources: the chart no longer does. In Redis mode, they’re marked as deployed outside the operator (cloud-streams.io/workload: external): the copy drops that annotation.