@dmgnr/kuber 1.2.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +428 -85
  2. package/dist/index.js +196 -198
  3. package/package.json +4 -3
  4. package/types.d.ts +2 -7
package/README.md CHANGED
@@ -1,45 +1,280 @@
1
1
  # kuber
2
2
 
3
- `kuber` is Astral's internal Docker Compose to Kubernetes translation layer.
4
-
5
- It reads a local Compose file, renders Kubernetes resources, applies them to the cluster, and can build images remotely from your working tree without requiring Docker on your machine.
6
-
7
- ## What It Does
8
-
9
- - Reads `compose.yml` or `docker-compose.yml`
10
- - Converts supported Compose services into Kubernetes resources
11
- - Applies those resources into a namespace named after the current directory
12
- - Turns `env_file` entries into Kubernetes Secrets and mounts them through `envFrom`
13
- - Translates file mounts into ConfigMaps and directory/volume mounts into PVC-backed volumes
14
- - Builds images on the remote builder by syncing:
15
- - committed git state
16
- - tracked local diffs
17
- - untracked files
18
- - ignored `.env*` files
19
- - Supports host-based `ports` syntax that renders Kubernetes `Ingress` rules
20
- - Supports managed Postgres claims through special pseudo-volumes such as `postgresql:app`
21
- - Supports managed S3 buckets and credentials through pseudo-volumes such as `s3:app`
3
+ `kuber` is a Docker Compose to Kubernetes translation layer backed by a
4
+ self-hosted management service (`kuber-server`). It reads a local Compose file,
5
+ renders Kubernetes resources, and applies them to the cluster through an
6
+ authenticated v2 API. Image builds happen inside the cluster with rootless
7
+ BuildKit, so the workstation needs neither Docker nor `kubectl`.
22
8
 
23
- ## Environment Assumptions
9
+ ## Architecture
10
+
11
+ ```
12
+ workstation (kuber CLI) ──HTTPS──▶ kuber-server (in-cluster pod)
13
+ │
14
+ ├─ CAS (content-addressed blobs on RWX PVC)
15
+ ├─ BuildKit Jobs (rootless) ──▶ registry
16
+ └─ Kubernetes API (RBAC-scoped)
17
+ ```
24
18
 
25
- This tool is built for Astral's cluster and workstation setup. It is not intended to work unchanged outside that environment.
19
+ The CLI authenticates to the server with a Bearer token acquired by `kuber
20
+ login`. It snapshots the repository into a content-addressed workspace, uploads
21
+ only the blobs the server is missing, and submits a build request. The server
22
+ materializes that workspace onto a shared RWX PVC and runs a rootless BuildKit
23
+ Job that builds and pushes the image, then the CLI pins the resulting immutable
24
+ registry digest into the rendered Deployment.
25
+
26
+ The server also owns reconciliation: it plans, applies, and prunes resources in
27
+ a per-project namespace, reconciles managed Postgres and S3 claims, rolls
28
+ deployments back, streams logs, and exposes interactive `exec` sessions over a
29
+ WebSocket.
30
+
31
+ ## Environment Assumptions
26
32
 
27
- Expected local setup:
33
+ kuber targets a specific self-hosted cluster and workstation setup. It is not
34
+ intended to run unchanged against an arbitrary Kubernetes environment. The
35
+ expected setup:
28
36
 
29
- - Tailscale access to the remote builder and Kubernetes network
30
- - a working `~/.kube/config`
31
- - `ssh` available locally
37
+ - an account on the `kuber-server` management API
38
+ - a working ClusterRole/Role (see [Server Deployment](#server-deployment))
39
+ - a registry the in-cluster BuildKit can push to
32
40
 
33
41
  Not required locally:
34
42
 
35
43
  - Docker
36
44
  - `kubectl`
37
45
 
38
- Docker is not required because builds happen on the remote builder after `kuber` syncs your repo state there. `kubectl` is not required because cluster access is handled through the bundled Kubernetes client.
46
+ ## API Origin
47
+
48
+ The v2 management API has one hard-coded origin:
49
+
50
+ ```text
51
+ https://kuber.astrxl.dev/api/v2
52
+ ```
53
+
54
+ ## Authentication
55
+
56
+ ```bash
57
+ kuber login dmgnr
58
+ kuber login dmgnr --persist
59
+ kuber whoami
60
+ kuber logout
61
+ ```
62
+
63
+ The default login is stored with mode `0600` under
64
+ `$XDG_RUNTIME_DIR/kuber/session.json` and disappears with the user runtime
65
+ directory. `--persist` instead uses `$XDG_CONFIG_HOME/kuber/session.json`, or
66
+ `~/.config/kuber/session.json` when `XDG_CONFIG_HOME` is unset. Password input
67
+ is never echoed. Runtime sessions last 24 hours and persistent sessions last 30
68
+ days; `logout` revokes the server-side session. `readSession` falls back to the
69
+ persistent file when no runtime session exists.
70
+
71
+ The default login is scoped to the current user and the authenticated identity
72
+ is available to every v2 command. `login`, `logout`, and `whoami` are the only
73
+ commands that run without a loaded project configuration.
74
+
75
+ ### Roles and Authorization
76
+
77
+ The server grants capabilities through three roles:
78
+
79
+ - `viewer` — read-only cluster access (`kubernetes:read`)
80
+ - `operator` — `viewer` plus `kubernetes:write` and `kubernetes:exec`
81
+ - `admin` — all capabilities, including user administration
82
+ (`users:read`, `users:write`, `sessions:revoke`)
83
+
84
+ Administer users with the `users` command tree:
85
+
86
+ ```bash
87
+ kuber users ls
88
+ kuber users add dmgnr --roles admin
89
+ kuber users update dmgnr --roles operator
90
+ kuber users update dmgnr --password
91
+ kuber users disable dmgnr
92
+ kuber users enable dmgnr
93
+ kuber users delete dmgnr
94
+ kuber users revoke dmgnr
95
+ ```
96
+
97
+ `users add`, `update --password`, and `delete` prompt for password / written
98
+ confirmation on an interactive terminal. Passwords are hashed with Argon2id on
99
+ the server and never stored in plaintext. Updating a user's roles or password
100
+ revokes all of that user's active sessions.
101
+
102
+ Inspect server-side operations and the audit trail:
103
+
104
+ ```bash
105
+ kuber operations ls
106
+ kuber operations get <operation-id>
107
+ kuber audit ls
108
+ ```
109
+
110
+ ## Server Deployment
111
+
112
+ The repository's `compose.yml` owns the `kuber-system` namespace, the
113
+ `kuber-server` image, its Deployment, Service, and Ingress. `.kuberrc.ts`
114
+ extends the rendered manifests with the server's ServiceAccount and RBAC:
115
+
116
+ - a namespaced `Role`/`RoleBinding` (`kuber-server-auth`) for the `kuber-system`
117
+ Secrets, ConfigMaps, Pods, Jobs, and Leases the server itself reads and writes
118
+ - a `ClusterRole`/`ClusterRoleBinding` (`kuber-server-manager`) granting the
119
+ cross-namespace verbs it needs to manage user projects
120
+
121
+ `compose.yml` runs the server as a non-root user (`runAsUser`/`runAsGroup`
122
+ `1000`), drops all Linux capabilities, uses a read-only root filesystem with a
123
+ `RuntimeDefault` seccomp profile, and backs `/data` with a Longhorn PVC
124
+ (`kuber-build-data`). The PVC hosts the CAS, materialized workspaces, and
125
+ resumable upload bytes, and is shared with BuildKit Jobs.
126
+
127
+ Deploy the server with kuber itself:
128
+
129
+ ```bash
130
+ KUBER_BOOTSTRAP_PASSWORD='replace-me' kuber up
131
+ ```
132
+
133
+ The server creates an `admin` user (from `KUBER_BOOTSTRAP_USERNAME`, default
134
+ `dmgnr`) on first boot only if that user does not already exist. The bootstrap
135
+ Secret is only rendered while `KUBER_BOOTSTRAP_PASSWORD` is set. After logging
136
+ in successfully, reconcile without that variable and restart once so kuber
137
+ removes the stale bootstrap Secret and the password leaves the pod environment:
138
+
139
+ ```bash
140
+ kuber up --no-b
141
+ kuber restart kuber-server
142
+ ```
143
+
144
+ See [Account Recovery](#account-recovery) for what to do if you are locked out.
145
+
146
+ ### Security Constraints
147
+
148
+ Because the server's ServiceAccount is scoped by the RBAC in `.kuberrc.ts`, it
149
+ can only act on the resources kuber manages. The management layer additionally
150
+ enforces ownership, so the server refuses to mutate resources that do not carry
151
+ kuber's workspace labels. Deleting a resource requires its UID as an optimistic
152
+ concurrency precondition, and workspace deletion also requires the namespace
153
+ UID. Namespaces that are not owned by kuber, or owned by a different workspace,
154
+ are never mutated (see [Workspaces and Migration](#workspaces-and-migration)).
155
+
156
+ ## Workspaces and Migration
157
+
158
+ Each project maps to a Kubernetes namespace derived from the current working
159
+ directory. The CLI records a "workspace" on the server keyed by project name and
160
+ borrows the namespace UID to guarantee it owns the namespace before reconciling.
161
+ Adopting existing resources relabels them (Server-Side Apply) only when they are
162
+ already managed by kuber and not owned by another workspace.
163
+
164
+ `up` refuses to mutate a namespace when:
165
+
166
+ - the namespace already exists but does not carry kuber's managed-by label
167
+ (`external`), or
168
+ - the namespace is labeled for a different workspace UID
169
+ (`different-workspace`)
170
+
171
+ In those cases the CLI prints a hint to `POST
172
+ /workspaces/<project>/adopt` with the namespace UID to complete a safe,
173
+ explicit adoption. The platform namespace (`kuber-system`) is adopted through
174
+ the admin-only platform adoption route.
175
+
176
+ Workspace state, revisions, operations, and audit events are stored as Secrets
177
+ and ConfigMaps in `kuber-system` keyed by kuber's `kuber.astrxl.dev/type`
178
+ label. Workspace updates are optimistic (If-Match on resource version) and
179
+ immutable revisions are recorded so history survives. Expired sessions are
180
+ cleaned up on an interval, and stale operations are marked failed on server
181
+ startup recovery.
182
+
183
+ ### Migration Behavior
184
+
185
+ `kuber up` is idempotent and safe to re-run. Each run:
186
+
187
+ 1. snapshots the workspace and uploads missing blobs to the server CAS,
188
+ 2. ensures the workspace record (creating or updating it with an optimistic
189
+ If-Match),
190
+ 3. adopts the namespace and its kuber-managed resources,
191
+ 4. reconciles managed Postgres and S3 claims,
192
+ 5. renders manifests, plans the diff, applies desired resources, waits for
193
+ rollout, and deletes stale resources.
194
+
195
+ Because resource references are immutable digests, re-running `up` only restarts
196
+ deployments whose image content actually changed. `start` re-resolves published
197
+ digests without building.
198
+
199
+ ## Registry Authentication
200
+
201
+ Building and pushing images from inside the cluster typically requires
202
+ credentials for the target registry. These are read from a Docker config file
203
+ (`KUBER_REGISTRY_CONFIG`, default `/etc/kuber/registry/config.json`) and mounted
204
+ as an image pull secret named by `KUBER_REGISTRY_SECRET`.
205
+
206
+ Registry authentication is optional. If `KUBER_REGISTRY_SECRET` is unset, the
207
+ server warns at startup and BuildKit uses anonymous registry access. This is
208
+ intended for registries that allow anonymous push/pull. The same credentials are
209
+ used when the server resolves a published image digest (`start` / `export`).
210
+
211
+ The server supports both standard registry bearer-token (`WWW-Authenticate:
212
+ Bearer`) and pre-emptive Basic auth when resolving digests.
213
+
214
+ ### Build Registry Environment
215
+
216
+ The server's registry behavior is driven by a few closely related environment
217
+ variables:
218
+
219
+ - `KUBER_BUILD_REGISTRY` (default `registry.neko-piranha.ts.net`): the registry
220
+ the in-cluster BuildKit pushes built images to and `kuber` uses as the image
221
+ namespace. It also supplies the registry host for authentication.
222
+ - `KUBER_INTERNAL_REGISTRY_HOST`: the host of an internal registry (for example
223
+ the in-cluster distribution service) used for the BuildKit cache image and,
224
+ when set, the image direct push target. When unset, push and cache fall back
225
+ to `KUBER_BUILD_REGISTRY`.
226
+ - `KUBER_INTERNAL_REGISTRY_INSECURE`: set to `"true"` to push to the internal
227
+ registry over plain HTTP instead of HTTPS. Only meaningful when
228
+ `KUBER_INTERNAL_REGISTRY_HOST` is set.
229
+ - `KUBER_PUSH_IMAGE_PREFIX` (default `kuber/`): a prefix applied to project
230
+ images pushed to the internal registry when `KUBER_INTERNAL_REGISTRY_HOST` is
231
+ configured.
232
+ - `KUBER_REGISTRY_RESOLVE_ORIGIN`: an explicit origin used to resolve a
233
+ published image digest (used by `start` / `export`). Useful when the digest
234
+ must be resolved from a different endpoint than the build/push registry, such
235
+ as an internal HTTP registry.
236
+ - `KUBER_REGISTRY_CONFIG`: path to the Docker config file with registry
237
+ credentials (see above).
238
+ - `KUBER_REGISTRY_SECRET`: the image pull Secret mounted for BuildKit's
239
+ registry access.
240
+ - `KUBER_BUILDKIT_IMAGE`: override the BuildKit runner image used for builds.
241
+ - `KUBER_BUILD_DATA_CLAIM`: the PVC claim backing builds.
242
+
243
+ See [Server Deployment](#server-deployment) for how `compose.yml` wires the
244
+ internal registry variables for the kuber-server pod.
245
+
246
+ ## Account Recovery
247
+
248
+ If you lose your credentials and cannot log in:
249
+
250
+ 1. Recreate the bootstrap admin by deploying with
251
+ `KUBER_BOOTSTRAP_PASSWORD` set again:
252
+ ```bash
253
+ KUBER_BOOTSTRAP_PASSWORD='new-password' kuber up --no-b
254
+ kuber restart kuber-server
255
+ ```
256
+ 2. The server only creates the bootstrap user if the account does not already
257
+ exist, so a fresh `kuber login <username>` with the new password works, or
258
+ use the newly created admin to reset other accounts:
259
+ ```bash
260
+ kuber users update <username> --password
261
+ ```
262
+ 3. After recovering, reconcile without `KUBER_BOOTSTRAP_PASSWORD` and restart
263
+ so the bootstrap Secret is removed and the password leaves the pod
264
+ environment.
265
+
266
+ Because user records and session hashes are stored as Secrets in
267
+ `kuber-system`, recovery relies on cluster administrators being able to redeploy
268
+ the server with bootstrap credentials. `users revoke <username>` forcibly logs a
269
+ user out across all devices.
39
270
 
40
271
  ## Next.js Example
41
272
 
42
- [`example/`](example/) contains a documented deployment template for adding kuber to an existing Bun-powered Next.js project without initializing or bundling an application in this repository. It includes a standalone-output Dockerfile, `.dockerignore`, `compose.yml`, and the required Next.js configuration.
273
+ [`example/`](example/) contains a documented deployment template for adding
274
+ kuber to an existing Bun-powered Next.js project without initializing or
275
+ bundling an application in this repository. It includes a standalone-output
276
+ Dockerfile, `.dockerignore`, `compose.yml`, and the required Next.js
277
+ configuration.
43
278
 
44
279
  ## Running
45
280
 
@@ -66,20 +301,29 @@ bun run index.ts exec app sh
66
301
  bun run index.ts start
67
302
  bun run index.ts stop
68
303
  bun run index.ts restart
304
+ bun run index.ts rollback
305
+ bun run index.ts fuck app
69
306
  bun run index.ts db ls
70
307
  bun run index.ts s3 ls
71
308
  bun run index.ts s3 creds app
72
309
  bun run index.ts s3 ui app
310
+ bun run index.ts login dmgnr
311
+ bun run index.ts users ls
312
+ bun run index.ts operations ls
313
+ bun run index.ts audit ls
73
314
  ```
74
315
 
75
316
  All commands accept `--config` to use a configuration file other than
76
317
  `.kuberrc.ts`:
77
318
 
78
319
  ```bash
79
- kuber --config deploy/production.kuberrc.ts up
80
- kuber up --config deploy/production.kuberrc.ts
320
+ kuber --config production.kuberrc.ts up
321
+ kuber up --config production.kuberrc.ts
81
322
  ```
82
323
 
324
+ `login`, `logout`, and `whoami` are context-free and do not require a
325
+ configuration.
326
+
83
327
  ### Shell Completion
84
328
 
85
329
  Generate and load completions for your shell:
@@ -89,25 +333,43 @@ source <(kuber complete zsh)
89
333
  source <(kuber complete bash)
90
334
  ```
91
335
 
92
- For a permanent setup, write the generated script to a file and source it from your shell configuration. Fish and PowerShell are also supported through `kuber complete fish` and `kuber complete powershell`.
336
+ For a permanent setup, write the generated script to a file and source it from
337
+ your shell configuration. Fish and PowerShell are also supported through
338
+ `kuber complete fish` and `kuber complete powershell`.
93
339
 
94
340
  ## Commands
95
341
 
96
- - `up`: build images if needed, render manifests, apply them, restart deployments whose image content changed, and wait for rollout
97
- - `start`: same as `up` but skips image builds
342
+ - `up [--no-b]`: build images if needed, ensure the workspace, reconcile managed
343
+ Postgres/S3, render manifests, apply them, wait for rollout, and delete stale
344
+ resources
345
+ - `start`: like `up` but re-resolves the currently published image digests
346
+ instead of building
347
+ - `login [username] [--persist]`: authenticate with the kuber API
348
+ - `logout`: revoke and remove the current API session
349
+ - `whoami`: show the authenticated API user and roles
350
+ - `users`: administer user accounts and roles
351
+ - `operations`: inspect server-side reconciliation operations
352
+ - `audit`: inspect the audit trail
353
+ - `ps [-a]`: print an ANSI graph of the current project namespace, hiding stopped
354
+ deployments by default
355
+ - `logs [deployment] [-f]`: print (or follow) logs for one deployment or all
356
+ managed deployments
357
+ - `exec <deployment> <command...>`: execute a command inside a running
358
+ deployment pod over an interactive WebSocket
359
+ - `restart [deployment]`: roll out a restart across managed deployments
98
360
  - `stop`: scale managed deployments to zero
99
- - `restart`: roll out a restart across managed deployments
100
- - `down`: delete managed resources while keeping ingress, PVCs, managed databases, and managed S3 storage
101
- - `down -f`: also delete ingress, PVCs, managed database and S3 resources, and the namespace
102
- - `ps`: list deployments in the current project namespace
103
- - `logs [deployment]`: print logs for one deployment or all managed deployments
104
- - `logs -f [deployment]`: follow logs continuously
105
- - `exec <deployment> <command...>`: execute a command inside a running deployment pod
106
- - `db ls`: list managed Postgres claims declared in the current Compose file
107
- - `db creds <service>`: print the generated connection details for a managed Postgres claim
108
- - `s3 ls`: list managed S3 claims declared in the current Compose file
109
- - `s3 creds <service>`: print all generated S3 environment variables for a service
110
- - `s3 ui <service>`: print the Garage UI object-browser URL for a service bucket
361
+ - `rollback` (alias `fuck`) `[deployment]`: roll one deployment back to its
362
+ previous release, or all managed deployments when no name is given
363
+ - `down [-f]`: delete managed resources while keeping ingress, PVCs, managed
364
+ databases, and managed S3 storage; `-f` also deletes those and the namespace
365
+ - `db ls` / `db creds <service>`: list or print credentials for managed Postgres
366
+ claims
367
+ - `s3 ls` / `s3 creds <service>` / `s3 ui <service>`: list managed S3 claims,
368
+ print their credentials, or print the Garage UI URL for a bucket
369
+ - `export [-o file]`: render manifests to a YAML file without applying them
370
+
371
+ Lifecycle commands (`restart`, `stop`, `rollback`, `down`) are idempotent:
372
+ identical requests are deduplicated server-side and tracked as operations.
111
373
 
112
374
  ## Configuration
113
375
 
@@ -121,11 +383,6 @@ export default {
121
383
  project: "my-app",
122
384
  composeFile: "compose.production.yml",
123
385
  registry: "registry.example.com",
124
- builders: {
125
- amd64: "kuber@amd-builder",
126
- arm64: "kuber@arm-builder",
127
- remoteRoot: "kuber-build",
128
- },
129
386
  rolloutTimeoutMs: 10 * 60_000,
130
387
 
131
388
  async compose(compose) {
@@ -143,37 +400,50 @@ export default {
143
400
 
144
401
  Operational defaults:
145
402
 
146
- - `project`: Compose top-level `name`, falling back to the current working directory name
403
+ - `project`: Compose top-level `name`, falling back to the current working
404
+ directory name
147
405
  - `composeFile`: the first recognized Compose filename in the working directory
148
406
  - `registry`: `registry.neko-piranha.ts.net`
149
- - `builders.amd64`: `kuber@astral-th`
150
- - `builders.arm64`: `kuber@astral`
151
- - `builders.remoteRoot`: `kuber-build`
152
407
  - `rolloutTimeoutMs`: `300000`
153
408
 
154
409
  Project-name precedence is `.kuberrc.ts project`, Compose top-level `name`, then
155
410
  the current working directory name.
156
411
 
412
+ The `registry` value controls which registry the CLI requests build images from
413
+ and which the server uses to resolve published digests. `rolloutTimeoutMs`
414
+ bounds how long `up` and `rollback` wait for a Deployment rollout.
415
+
157
416
  Configuration hooks can be synchronous or asynchronous and receive mutable
158
417
  values:
159
418
 
160
- - `compose(compose, context)`: once after parsing and validation; affects every command that reads Compose
161
- - `preBuild(compose, context)`: before build eligibility is evaluated when builds are enabled
162
- - `postBuild(result, context)`: after images are built; `result` contains `built` and `changed` service names
163
- - `postRender(resources, context)`: after rendering and before reconciliation planning; also runs for `export`
164
- - `postApply(resources, context)`: after desired resources are successfully applied
419
+ - `compose(compose, context)`: once after parsing and validation; affects every
420
+ command that reads Compose
421
+ - `preBuild(compose, context)`: before build eligibility is evaluated when
422
+ builds are enabled
423
+ - `postBuild(result, context)`: after images are built; `result` contains
424
+ `built` and `changed` service names
425
+ - `postRender(resources, context)`: after rendering and before reconciliation
426
+ planning; also runs for `export`
427
+ - `postApply(resources, context)`: after desired resources are successfully
428
+ applied
165
429
 
166
430
  Hook context contains the resolved `cwd`, `project`, `composeFile`, and optional
167
431
  `configFile`. A hook error aborts the command and is reported by the normal CLI
168
432
  error handler.
169
433
 
434
+ Registry and rollout configuration remain part of the CLI-facing contract.
435
+ Image builder selection is not configurable: builds are scheduled, executed, and
436
+ owned entirely by the server.
437
+
170
438
  ## Compose Conventions
171
439
 
172
- `kuber` supports a few project-specific Compose conventions on top of normal service translation.
440
+ `kuber` supports a few project-specific Compose conventions on top of normal
441
+ service translation.
173
442
 
174
443
  ### Host-Based Ports
175
444
 
176
- If a `ports` entry uses a hostname instead of a numeric published port, `kuber` treats it as an ingress host and routes traffic to the target container port.
445
+ If a `ports` entry uses a hostname instead of a numeric published port, `kuber`
446
+ treats it as an ingress host and routes traffic to the target container port.
177
447
 
178
448
  Example:
179
449
 
@@ -184,9 +454,11 @@ services:
184
454
  - somedomain.astrxl.dev:3000
185
455
  ```
186
456
 
187
- That produces a Kubernetes `Ingress` rule for `somedomain.astrxl.dev` pointing at the service port for container port `3000`.
457
+ That produces a Kubernetes `Ingress` rule for `somedomain.astrxl.dev` pointing
458
+ at the service port for container port `3000`.
188
459
 
189
- Single-level wildcard subdomains are supported. Quote wildcard entries so YAML does not treat the leading `*` as an alias:
460
+ Single-level wildcard subdomains are supported. Quote wildcard entries so YAML
461
+ does not treat the leading `*` as an alias:
190
462
 
191
463
  ```yml
192
464
  services:
@@ -196,7 +468,8 @@ services:
196
468
  - "*.secure.astrxl.dev:3001:protected"
197
469
  ```
198
470
 
199
- Protected routes use the kuber dialect and render Traefik `IngressRoute` resources instead of plain Kubernetes `Ingress`:
471
+ Protected routes use the kuber dialect and render Traefik `IngressRoute`
472
+ resources instead of plain Kubernetes `Ingress`:
200
473
 
201
474
  ```yml
202
475
  services:
@@ -232,7 +505,12 @@ services:
232
505
  - postgresql:user/database
233
506
  ```
234
507
 
235
- This creates or reuses the managed CNPG role secret, reconciles the database resource, and injects `DATABASE_URL` into the generated app secret in Kubernetes.
508
+ This creates or reuses the managed CNPG role secret, reconciles the database
509
+ resource, and injects `DATABASE_URL` and
510
+ `REDIS_URL=redis://redis.database.svc.cluster.local` into the generated app
511
+ secret in Kubernetes. `REDIS_URL` is only added to services with a managed
512
+ Postgres claim. Running `kuber db creds <service>` performs the same focused
513
+ Secret, role, and Database reconciliation before printing credentials.
236
514
 
237
515
  ### Managed S3
238
516
 
@@ -245,7 +523,8 @@ services:
245
523
  - s3:app
246
524
  ```
247
525
 
248
- This creates `GarageBucket/app` and `GarageKey/app` in `garage-system`. To use different key and bucket names:
526
+ This creates `GarageBucket/app` and `GarageKey/app` in `garage-system`. To use
527
+ different key and bucket names:
249
528
 
250
529
  ```yml
251
530
  services:
@@ -254,7 +533,8 @@ services:
254
533
  - s3:app-key/shared-assets
255
534
  ```
256
535
 
257
- The Garage operator generates the credentials. `kuber` reads its generated Secret and injects these values into the service's `<service>-env` Secret:
536
+ The Garage operator generates the credentials. `kuber` reads its generated
537
+ Secret and injects these values into the service's `<service>-env` Secret:
258
538
 
259
539
  - `AWS_ACCESS_KEY_ID`
260
540
  - `AWS_SECRET_ACCESS_KEY`
@@ -262,7 +542,9 @@ The Garage operator generates the credentials. `kuber` reads its generated Secre
262
542
  - `AWS_REGION`
263
543
  - `S3_BUCKET`
264
544
 
265
- One service can declare both `postgresql:...` and `s3:...`; all generated values are merged into the same service Secret. Managed Garage buckets and keys are retained by normal `down` and deleted by `down -f`.
545
+ One service can declare both `postgresql:...` and `s3:...`; all generated
546
+ values are merged into the same service Secret. Managed Garage buckets and keys
547
+ are retained by normal `down` and deleted by `down -f`.
266
548
 
267
549
  Inspect a claim, print its generated credentials, or get its Garage UI URL:
268
550
 
@@ -278,9 +560,11 @@ assignments. `s3 ui` only prints the URL; it does not open a browser.
278
560
 
279
561
  ### Environment Files
280
562
 
281
- `env_file` entries are read locally and turned into a Kubernetes `Secret` named `<service>-env`. Deployments then consume that secret through `envFrom`.
563
+ `env_file` entries are read locally and turned into a Kubernetes `Secret` named
564
+ `<service>-env`. Deployments then consume that secret through `envFrom`.
282
565
 
283
- This is also where generated values such as `DATABASE_URL` and the managed S3 environment are injected.
566
+ This is also where generated values such as `DATABASE_URL` and the managed S3
567
+ environment are injected.
284
568
 
285
569
  ### Volumes
286
570
 
@@ -293,7 +577,11 @@ This is also where generated values such as `DATABASE_URL` and the managed S3 en
293
577
  - `postgresql:...` is treated as a managed database claim, not as a filesystem mount
294
578
  - `s3:...` is treated as a managed object-storage claim, not as a filesystem mount
295
579
 
296
- Named volumes also support kuber-specific storage hints.
580
+ Named volumes also support kuber-specific Longhorn storage hints. Kuber renders
581
+ each distinct placement policy as a deterministic, reusable Longhorn
582
+ `StorageClass`, then references that class from the PVC. The generated class
583
+ uses Longhorn's `numberOfReplicas`, `diskSelector`, and `dataLocality`
584
+ parameters; placement fields are never written directly to the PVC.
297
585
 
298
586
  Default behavior:
299
587
 
@@ -325,8 +613,8 @@ services:
325
613
  Meaning:
326
614
 
327
615
  - `name(20Gi):/path` -> PVC size `20Gi`
328
- - `name(20Gi on archive):/path` -> PVC size `20Gi`, `diskTag: ["archive"]`, `dataLocality: "none"`
329
- - `name(20Gi on 1 archive):/path` -> PVC size `20Gi`, `replicaCount: 1`, `diskTag: ["archive"]`, `dataLocality: "none"`
616
+ - `name(20Gi on archive):/path` -> PVC size `20Gi`, with a StorageClass using `diskSelector: "archive"` and disabled data locality
617
+ - `name(20Gi on 1 archive):/path` -> PVC size `20Gi`, with a StorageClass using one replica and `diskSelector: "archive"`
330
618
 
331
619
  Explicit extensions are also supported.
332
620
 
@@ -364,25 +652,80 @@ Precedence:
364
652
  - top-level `volumes.<name>.x-*`
365
653
  - fallback default `1Gi on 2 fast`
366
654
 
367
- ## Building
368
-
369
- Image builds and image-digest checks run through the selected SSH builder. If a pushed image has the same content fingerprint as the existing registry image, `up` does not restart that deployment.
370
-
371
- To build distributable binaries:
655
+ StorageClasses are cluster-scoped and content-addressed by policy. They are
656
+ shared across projects and intentionally retained when a project is removed.
372
657
 
373
- ```bash
374
- bun run build.ts
375
- ```
658
+ ## Building
376
659
 
377
- If you only want a plain JavaScript bundle for quick local use in another workspace, build `index.ts` directly:
660
+ When a service declares `build`, the CLI:
661
+
662
+ 1. snapshots the repository into a content-addressed workspace
663
+ (committed git state, tracked changes, untracked files, and ignored `.env*`
664
+ files),
665
+ 2. negotiates with the server and uploads only the blobs it is missing,
666
+ 3. submits a build request; the server materializes the workspace from the CAS
667
+ onto a shared RWX PVC and runs a rootless BuildKit Job that builds and pushes
668
+ the configured image with registry cache.
669
+
670
+ Build containers are restricted: they run as non-root (`runAsUser`/`runAsGroup`
671
+ `1000`), do not mount the service account token, and only read the workspace
672
+ (read-only mount) and a writable BuildKit state `emptyDir`. After a push, the
673
+ registry's manifest digest is captured and embedded into the rendered Deployment
674
+ as an immutable `:latest@sha256:...` reference, so a changed image naturally
675
+ triggers a rollout. `start` and `export` look up the currently published digest
676
+ without rebuilding, and fail if a buildable service has no published image yet.
677
+
678
+ `export` is side-effect-free: it refuses to render managed Postgres or S3 claims
679
+ (because it cannot call the server to generate credentials) and instead tells
680
+ you to run `kuber up` or remove the managed provider claims.
681
+
682
+ ## Rollback
683
+
684
+ `kuber rollback [deployment]` (alias `fuck`) rewinds managed Deployments to the
685
+ previous release. ReplicaSets carry a `deployment.kubernetes.io/revision`
686
+ annotation, and rollback restores the complete pod template from the next-older
687
+ ReplicaSet via a JSON Patch, then waits for the rollout to complete. With no
688
+ argument every managed Deployment is rolled back; pass a deployment name to
689
+ target a single one.
690
+
691
+ Notes and limitations:
692
+
693
+ - Kubernetes only keeps its most recent ReplicaSets, so an older release may no
694
+ longer be reachable after enough successful rollouts/rollbacks.
695
+ - Rollback restores the pod template (including image and environment), not live
696
+ Secret, ConfigMap, PVC, database, or S3 state.
697
+ - A later `kuber up` or `kuber start` re-resolves `:latest` and returns the
698
+ Deployment to the current desired state anyway, so rollback is the right tool
699
+ for responding to a bad deploy, not for permanently pinning an old version.
700
+ - Rollback only considers Deployments managed by kuber
701
+ (`app.kubernetes.io/managed-by=kuber`) and only runs within a workspace whose
702
+ namespace kuber owns.
703
+
704
+ ## Workspace State and Operations
705
+
706
+ The server persists per-workspace state, revisions, operations, and audit
707
+ events as Secrets/ConfigMaps in `kuber-system`. Mutations are idempotent:
708
+
709
+ - operations carry an idempotency key so retries do not double-apply,
710
+ - resource deletion requires a UID precondition,
711
+ - workspace replacement is guarded by If-Match.
712
+
713
+ The CLI is built with the normal `build` script for distribution and local
714
+ use:
378
715
 
379
716
  ```bash
380
- bun build index.ts --target bun --minify --sourcemap --outdir dist
717
+ bun run build
381
718
  ```
382
719
 
383
720
  ## Notes
384
721
 
385
722
  - Resource names and namespaces are derived from the current working directory.
386
- - The remote build flow is optimized for local iteration, not for producing a perfectly clean export of the repository.
387
- - Managed database support is Kubernetes-only. It injects `DATABASE_URL` into the generated app secret and does not rewrite local `.env` files.
388
- - `kuber` operates on managed resources in the namespace matching the current directory name.
723
+ - The workspace snapshot is optimized for local iteration, not for producing a
724
+ perfectly clean export of the repository.
725
+ - Managed database support is Kubernetes-only. It injects `DATABASE_URL` into
726
+ the generated app secret and does not rewrite local `.env` files.
727
+ - `kuber` operates on managed resources in the namespace matching the current
728
+ directory name.
729
+ - Builds are scheduled, executed, and owned by the server. There is no local
730
+ SSH/daemon builder configuration; `registry` and `rolloutTimeoutMs` remain
731
+ CLI-facing settings.