# Manage Pulse with the Kubernetes operator

Apply one namespaced `PulseCluster` to run Pulse 0.2.5 on three Kubernetes workers. The Pulse controller translates that resource into a Flux `HelmRelease`. Flux installs the database chart and runs its quorum check before upgrades. The custom resource reports how many voters are ready and whether they run the desired revision.

## Upgrade an existing operator-managed cluster

For an existing Pulse 0.2.4 cluster managed by operator 0.1.0, upgrade the operator Helm release in its current namespace. Keep its PulseCluster, Secrets, seed and PVCs. The commands assume the Helm release is named `pulse-operator` and the PulseCluster is named `pulse`. Set the namespace to the one shown by `helm list -A`.

```sh
PULSE_NAMESPACE=pulse
helm upgrade pulse-operator oci://registry-1.docker.io/simplemagic/pulse-operator --version 0.1.1 -n "$PULSE_NAMESPACE" --reuse-values --wait
kubectl -n "$PULSE_NAMESPACE" wait helmrelease/pulse --for=jsonpath='{.status.lastAttemptedRevision}'=0.2.5 --timeout=10m
kubectl -n "$PULSE_NAMESPACE" wait helmrelease/pulse --for=condition=Ready --timeout=10m
kubectl -n "$PULSE_NAMESPACE" get pods -l app.kubernetes.io/name=pulse -o custom-columns='POD:.metadata.name,READY:.status.containerStatuses[0].ready,IMAGE:.spec.containers[0].image'
```

Helm waits for the operator. Flux upgrades the database asynchronously. Before resuming a load test, confirm all three voters show `READY=true` and `docker.io/simplemagic/sm-pulse:0.2.5`. Run a known query against pre-upgrade data and verify a fresh write. Go applications gain automatic writer recovery after rebuilding and deploying with SDK v0.2.5. [Release notes](/smts/docs/release-notes/)

## Prepare the cluster

Use a fresh namespace, three schedulable Linux amd64 workers, an SSD StorageClass and a CNI that enforces NetworkPolicy. Each namespace supports one cluster named `pulse`. Use a separate namespace if you already have a directly managed Helm installation. The operator refuses to adopt existing releases or retained volumes.

Install Flux source-controller and helm-controller with a compatible Flux CLI, or have the platform team verify them in the existing Flux installation. The local qualification uses Flux 2.7.5. Check the target context before making changes. [Flux installation](https://fluxcd.io/flux/installation/)

```sh
kubectl config current-context
# For a fresh cluster with the Flux 2.7.5 CLI
flux install --components=source-controller,helm-controller
kubectl -n flux-system rollout status deployment/source-controller
kubectl -n flux-system rollout status deployment/helm-controller
kubectl get crd helmcharts.source.toolkit.fluxcd.io helmreleases.helm.toolkit.fluxcd.io
kubectl get storageclass
kubectl create namespace pulse
```

Prepare a protected `auth.toml` with your secret manager. Give the bootstrap database owner a strong password and generate a separate random peer token of 16–256 characters. All voters need the same peer token. The example uses `owner` as the database username.

```toml
[auth]
peer_token = "<shared-random-peer-token>"

[auth.admin]
name = "owner"
password = "<database-owner-password>"
```

Create the Secret from the protected file. An optional licensed installation also needs a Secret with the key `license.json`. Keep the signing key with the license issuer.

```sh
kubectl -n pulse create secret generic pulse-access \
  --from-file=auth.toml="$PULSE_INPUTS/auth.toml"
# For a licensed installation
kubectl -n pulse create secret generic pulse-license \
  --from-file=license.json="$PULSE_INPUTS/license.json"
```

## Install the controller and create the database

Install the public Pulse operator chart from Docker Hub in the namespace it will watch. Version 0.1.1 manages Pulse 0.2.5 and supports anonymous pulls. Cluster administrators install the CRD once. The controller and the account Flux uses to install Pulse have separate namespace Roles. Restrict who can manage Secrets, PulseClusters, HelmReleases and workloads in that namespace.

```sh
helm install pulse-operator oci://registry-1.docker.io/simplemagic/pulse-operator --version 0.1.1 -n pulse --wait
kubectl -n pulse rollout status deployment/pulse-operator
```

Save this as `pulse-cluster.yaml`. The free configuration requests three 50 GiB volumes and two data shards. An empty storage class uses the cluster default. To select an SSD class explicitly, set `spec.storageClass` before applying.

```yaml
apiVersion: pulse.simplemagic.com/v1alpha1
kind: PulseCluster
metadata:
  name: pulse
  namespace: pulse
spec:
  authSecret: pulse-access
  replicas: 3
  shards: 2
  storageGi: 50
  # storageClass: premium-rwo
  # licenseSecret: pulse-license
```

```sh
kubectl apply -f pulse-cluster.yaml
kubectl -n pulse get pulsecluster -w
# In another terminal
kubectl -n pulse wait --for=condition=Ready pulsecluster/pulse --timeout=20m
kubectl -n pulse get pods -l app.kubernetes.io/name=pulse -o wide
kubectl -n pulse get pvc
kubectl -n pulse port-forward svc/pulse-client 9070:9070
```

Expect `Ready=True`, three ready voters on distinct nodes and three bound data claims. In another terminal run the authenticated smoke test. Curl prompts for the owner password. Use a fresh table name if you repeat the test.

```sh
curl -fsS http://127.0.0.1:9070/readyz
curl -fsS -u owner -H 'Content-Type: application/json' \
  --data-binary '{"name":"operator_probe","columns":{"device":"tag","value":"integer"},"shard_keys":["device"]}' \
  http://127.0.0.1:9070/admin/tables
curl -fsS -u owner -H 'Content-Type: text/plain' \
  --data-binary 'operator_probe,device=one value=7i' http://127.0.0.1:9070/write
curl -fsS -u owner -H 'Content-Type: application/json' \
  --data-binary '{"sql":"SELECT COUNT(*) FROM operator_probe"}' http://127.0.0.1:9070/query
```

The query should return one row with a count of 1.

## Configure access and monitoring

| Field in `spec` | Behavior |
| --- | --- |
| `authSecret` | Required Secret with key `auth.toml`. Rotate by mounting a new Secret under a new name and changing this reference. Keep the peer token stable during a rolling password change. |
| `licenseSecret` | Optional Secret with key `license.json`. Use a new Secret name when renewing. The free edition permits two shards and 50 GiB of stored data per voter. |
| `replicas` | Defaults to 3. This API accepts up to 32 and rejects decreases. Growth requires a license with the membership feature, spare workers and enough data shards to distribute replicas. |
| `shards`, `storageGi`, `storageClass` | Fixed when the cluster is created. Plan storage and shard count before the first write. |
| `clientsNamespace` | Allows HTTP and PostgreSQL connections from one additional namespace. Same-namespace clients are allowed by default. The raw ILP/TCP listener is disabled. |
| `console.adminSecret`, `console.nodeAuthSecret` | Set both to enable the web console. Once enabled, the API preserves its account volume by rejecting removal of the console setting. The first Secret contains `name` and `password` for browser login. The second contains `node-auth` with the single value `username:password` for database access. Port-forward `svc/pulse-console` on port 7070. |
| `podMonitor`, `metricsNamespace` | Set `podMonitor: true` when Prometheus Operator is installed. Set `metricsNamespace` to the collector namespace to allow access to the HTTP metrics port. Configure Prometheus to select this namespace and its PodMonitor. Verify three `/metrics` targets in Prometheus before using Grafana. |

Reapply the whole manifest after editing it. The operator polls every ten seconds. After an update, wait for the operator to observe your edit before waiting for Ready. This prevents the previous generation’s Ready condition from satisfying the check. During a roll, wait for all voters before making another change.

```sh
generation=$(kubectl -n pulse get pulsecluster pulse -o jsonpath='{.metadata.generation}')
kubectl -n pulse wait pulsecluster/pulse --for="jsonpath={.status.observedGeneration}=$generation" --timeout=2m
kubectl -n pulse wait pulsecluster/pulse --for=condition=Ready --timeout=20m
```

```sh
kubectl -n pulse get pulsecluster pulse -o yaml
kubectl -n pulse get helmchart.source.toolkit.fluxcd.io,helmrelease
kubectl -n pulse describe helmrelease pulse
kubectl -n pulse get events --sort-by=.metadata.creationTimestamp
kubectl -n pulse logs deploy/pulse-operator
kubectl -n pulse get pods,pvc,podmonitor
```

`ReleasePending` means Flux has yet to report success for the requested configuration. Inspect its events for registry, RBAC, hook or scheduling failures. `VotersPending` means the release was applied and Pulse is waiting for the desired voters and revision. Check pod events, disk attachment and readiness. After repairing a failed Flux action, use `flux reconcile helmrelease pulse -n pulse --reset` to retry. Enable an alert for the controller Deployment being unavailable as well as database health. A stopped controller cannot refresh the last reported Ready condition.

## Ownership and recovery

Make declarative changes on the PulseCluster. The controller restores the HelmRelease specification from it. Workload restarts and readiness are managed by Kubernetes and Pulse. The operator pins the database chart to 0.2.5. A newer database version requires an operator release that selects it. Back up and verify recovery before upgrading. Helm installs CRDs on initial install. Apply reviewed CRD updates separately before upgrading the operator chart.

Deleting the PulseCluster retains its HelmRelease, StatefulSet, seed, provisioning record and data. A replacement PulseCluster receives a new UID and reports `OwnershipConflict`; recovery needs an explicit operator decision. Deleting the HelmRelease triggers a Flux uninstall. Deleting the namespace can delete the data volumes according to the StorageClass reclaim policy. Preserve the namespace, seed and provisioning record during recovery. Automatic volume replacement, restoring a backup, shrinking membership and converting an existing Helm installation are outside this API.

For Prometheus discovery and Grafana dashboards, see the [monitoring guide](/smts/docs/kubernetes/monitoring/). For backups and recovery procedures, see [cluster operations](/smts/docs/kubernetes/operations/).
