Repository navigation
Description
Slice 1 of the P6-on-Kubernetes epic: the P6 process model on Kubernetes, container tier only
Part of epic #426. Written so a planner can start it in a fresh session.
Goal
Run the P6 runtime on Kubernetes as ordinary workloads: the supervisor with its forked worker pool, the relay, Redis, the MU1 control plane, and remote-worker container sandboxes. This adds a new kustomization (for example deploy/k8s-p6/) next to deploy/vm/ and deploy/compose/. It reuses the same harness image and the same environment variables. It does not revive the Knative path: no Knative Service, no KEDA, no KubectlTransport/pod-exec sandboxes. Execution goes through GrpcRelayTransport (SH_REMOTE_SANDBOX=1, SH_SANDBOX_DISCOVERY=records), as on the VM.
The closest precedent is deploy/compose/docker-compose.yml. It already runs these exact processes in containers. The VM path (deploy/vm/) carries the hardening and secret handling this slice has to translate.
Workload mapping
| Component | Workload | Notes |
|---|---|---|
| Supervisor + W forked workers | Deployment, one container | fork() cannot cross containers (ADR-0034, deploy/compose/README.md). W comes from SH_WORKERS; capacity comes from replicas. Not a Knative Service. |
| Relay | Deployment, replicas: 1, strategy: Recreate |
Presence-only: each Attach stream is held by one process. Start from deploy/knative/relay-deployment.yaml, but take tokens from Secrets and split the exec listener onto its own port (MOCA_RELAY_EXEC_ADDR). |
| Container sandboxes | StatefulSet of remote-worker |
Derive a unique, stable SANDBOX_ID from the pod name (downward API). Plain replicas share one id and collide on one sh:sandbox:records entry. |
| Redis | StatefulSet + PVC, with AUTH | It holds sh:sandbox:records: whoever can write it chooses the executor for every turn. Today's deploy/knative/redis.yaml is a Deployment with no auth. |
| Control plane | Deployment | Start from deploy/knative/control-plane.yaml (K8sSecretStore). Check whether the sh-control-plane-pods Role is still needed without the pod-exec path. |
Code changes
- The supervisor's admin listener is bound to loopback (
packages/supervisor/src/admin.ts:100,127.0.0.1), so kubelet probes and Prometheus cannot reach it. It also serves onlyGET /metrics. Add a bind-address setting (for exampleSH_ADMIN_HOST, defaulting to loopback so the VM and Compose paths keep their posture), and add a readiness endpoint that is ready once at least one worker is healthy. Restrict access with a NetworkPolicy, not the bind. - Optional: an init process (tini) as PID 1, or a written argument for why Node as PID 1 is enough.
Supervisor gotchas the manifests must encode
- The front door is L4 only. Routing and 429 admission happen once per connection (
packages/supervisor/src/routing.ts:21-25), never per request. An L7 proxy that pools upstream connections funnels many sessions' turns to one worker, which silently defeats the S cap and sticky routing. That includes an Ingress, an edge-terminated Route, an Istio/Ambient sidecar, and Knative's queue-proxy. Use a ClusterIP or LoadBalancer Service, or TLS passthrough, and keep the mesh off these pods. Document this prominently. - W comes from the CPU limit, not the request.
availableParallelism()readscpu.max. With no limit, W describes the whole node. Set a limit or pinSH_WORKERS. - Memory is roughly W × ~225 MiB at idle, because each worker compiles TypeScript with tsx at startup (see the measurement in
relay-deployment.yaml). Size requests to match. - Shutdown:
terminationGracePeriodSeconds: 120, matchingTimeoutStopSecinsh-supervisor.service. Kubernetes sends SIGTERM to PID 1 only, which is theKillMode=mixedbehaviourmain.ts::close()relies on. Add a shortpreStopsleep so the endpoint is removed beforedrainAll()stops accepting. - More than one replica is allowed with
leastInFlight. W workers are already separate processes sharing Redis, so pods add no new concurrency class.stickyBySessionaffinity holds only within a pod. Say so in the docs. An HPA on in-flight/S or the 429 rate is optional and out of scope for the first pass. HOME=/tmpon anemptyDir, plusreadOnlyRootFilesystem, as the existing manifests do.
Isolation: NetworkPolicy replaces nftables and isolate=strict (MI1 §5 R5/R8)
A pod has a single IP, so the VM's loopback bind for the exec listener does not carry over. Enforce by port, which needs a CNI that enforces NetworkPolicy:
- Relay exec port (9444): from supervisor pods only.
- Relay attach port (9443): from sandbox pods (and from the P4 CIDR in slice 2).
- Redis: from the supervisor, relay and control plane only. Never from sandboxes.
- Sandbox egress: the relay's attach port, plus whatever
deploy/knative/harness-egress-policy.yaml's successor permits. - Every token comes from a Secret:
SH_RELAY_TOKEN,MOCA_RELAY_EXEC_TOKEN, the MU1 keypair, the KEK, and the exchange token. A setup script, analogous tosetup-vm.shand toinstall.sh's use ofgenkeys.ts, generates them once and never rotates them on a re-run.
Acceptance
- On Kind (and on one real cluster with an enforcing CNI): a setup script brings the stack up. An authenticated
mocactl runturn executes in a sandbox pod, and an unauthenticated/turnis refused withSH_REQUIRE_AUTH=true. - A smoke test adapted from
deploy/compose/smoke.shpasses. - Negative tests: a sandbox pod cannot reach Redis or the relay's exec port.
- Rolling the supervisor Deployment lets in-flight turns finish (§3.9).
- A static test, in the spirit of
deploy/compose/tests/compose.test.sh, keeps the env vars aligned withdeploy/vm/env/*.env.example.
Out of scope
P4 (slice 2), tier selection and affinity (slice 3), autoscaling, and Vault.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
pdettori commentedon Oct 4, 2026
Slice 1 acceptance on OpenShift: #370 demo parity on the container tier
The acceptance run,
deploy/k8s/README.md§9, ran against PR #427 atf3b4f62. Every step passed. No fallback was needed.Environment
us-east-1. Apps domainapps.moca1.kubestellar.org. Default StorageClassgp3-csi.f3b4f62(OpenShift binary Docker build, pi-fork included) asimage-registry.openshift-image-registry.svc:5000/moca-build/moca-harness@sha256:ba53ffca6e28c52f072c7882bd2e61df7a15ab143383b5e46b1ab7e3c1412694. Not published outside the cluster.ghcr.io/rossoctl/moca-remote-worker:latest; this branch does not change remote-worker.--tls-cert, sosetup.shgenerated a self-signed certificate for the supervisor Route. The cluster's default ingress CA is not publicly trusted either, soNODE_EXTRA_CA_CERTSholds both.github:6678093(Paolo Dettori) and user 2github:228572680(ingpaolodettori-dev): one laptop, twoXDG_CONFIG_HOMEs, a private browser window. Each user stored the same Anthropic key under its own credential name.9.1 Bring-up
redis-0undernonroot-v2with UID 999 and GID 1000, so the Redis SCC fallback was not needed./readyzanswers 200 through the edge Route;token_requiredthrough the passthrough Route and the ghostunnel sidecar, with TLS verified both times.9.2 Live smoke, with a real model (
api.anthropic.com, kindapi-key)PASS=11 FAIL=0. On OpenShift, claim 7 also proves the kube-API carve-out that Kind cannot:
redis, relay exec, kube API and metadata BLOCKED; relay attach OPEN. Claim 9 drained a turn across a supervisor pod deletion, and claim 10 survived aredis-0restart.Re-checks Kind could not prove, probed from
moca-sandbox-0:10.0.112.96:644310.0.64.91:1025010.0.112.96:1025010.0.64.91:22623https://example.com9.3 The acts
Act 1, login and doctor:
logged in as Paolo Dettoriandlogged in as ingpaolodettori-dev;mocactl doctorgave 7/7 ✓ for both, including "harness reachable" and "harness trusts this control plane" through the passthrough Route.Act 2, own credentials: each user ran
credentials addand then a turn (uname -a, which ran inmoca-sandbox-1on the RHCOS kernel5.14.0-570.73.1.el9_6.x86_64). The auditsh:cp:auditshows:github:6678093:session_createdandcredential_issuedwith credentialanthropic-user1;github:228572680:session_createdandcredential_issuedwith credentialanthropic-user2;Act 3, disjoint sessions:
mocactl sessionslists only that user's own session;fec4362e-…getsthat session no longer exists, or is not yours, exit 1;sess-does-not-existgets the same text, exit 1;resumed, exit 0.Act 4, research from the sandbox: both users ran the VM demo's 2a prompt at the same time. Both clones and both fetches ran in the sandbox:
COMMITd94eb3047631git ls-remote … HEAD→d94eb3047631NODE_VERSION/NODE_DATEv26.10.0/2026-09-21index.json[0]→v26.10.0 2026-09-21The honest beat:
moca-sandbox-0holdsresearch-user1(and the smoke'sproof.txt);moca-sandbox-1holdsresearch-user2. Both users lease the same pool, with no per-user sandbox isolation, as README §7 states (MI1 S5).L4 check, spec §10 risk 3
These are established connections inside the supervisor pod, counted from
/proc/net/tcpand/proc/net/tcp6:The connections are 1:1 for two concurrent clients, so the passthrough Route does not pool.
Counters, as context:
restarts0,handoff_retries0,handoff_failures0,over_admission0 → 7.over_admissionrises once per turn, as it did in the Kind spike.Fallbacks applied
None: no Redis SCC patch, no node-CIDR policy, no LoadBalancer.
Notes for follow-ups
mocactl loginshould either say how long the code is valid, or re-issue a code by itself.NODE_EXTRA_CA_CERTStherefore needs the ingress CA as well as the supervisor CA. README §9.1 says this already;setup.shcould write the combined file.docs(specs): P6 on Kubernetes, slice 1 design (#423)
feat(supervisor): SH_ADMIN_HOST selects the admin listener's bind add…
feat(supervisor): /healthz and /readyz on the admin listener, bindabl…
test(deploy/vm): the loopback admin guard also checks the shipped env…
fix(harness): redact credentials from Redis URLs in errors (#423)
fix: redact Redis credentials in session-backend and work-queue error…
feat(deploy/k8s): base namespaces, default-deny NetworkPolicy and Red…
feat(deploy/k8s): relay Deployment with split attach/exec Services an…
feat(deploy/k8s): supervisor Deployment — one container, pinned W, dr…
feat(deploy/k8s): control plane with file-mounted MU1 secrets and no …
feat(deploy/k8s): sandbox StatefulSet, egress policy, isolation cover…
test(deploy/k8s): env parity with the VM env templates (#423)
21 remaining items
fix(harness): RedisRecordStore re-arms after an established connectio…
fix(deploy/k8s): setup.sh inputs are sticky; value flags and kind ver…
fix(deploy/k8s): smoke.sh keeps its logs on every failed run (#423)
chore: pnpm-lock.yaml differs from upstream/main only by supervisor's…
docs(deploy/k8s): restricted-v2 fallback drops fsGroup too; sandbox S…
feat(supervisor): admin_listening log line carries the bind address (#…
test(deploy/k8s): render setup.sh's generated OCP overlay through kub…
test(harness): type the re-arm test's RESP buffer so harness typechec…
fix(deploy/k8s): write_overlay takes its output directory explicitly (#…
Merge pull request #427 from pdettori/docs/423-p6-on-kubernetes-spec
pdettori commentedon Oct 4, 2026
Done: merged in #427 (0573a82) and accepted on OpenShift 4.20.8 (results). Follow-ups #428–#435; the epic is #426.
fix(mocactl): say how long the login code lasts, and re-issue an expi…
fix(deploy/k8s): combined trust file, trust line on every run, settab…