With worker.runtime: kubernetes, the backend starts one Job per run in a
single namespace, using the Kubernetes API. Supervision is the same as
with Podman or Docker (supervision): the backend watches
the Job, stops it on cancellation or at the deadline, records the outcome
when the worker cannot, and deletes the Job afterwards. The worker image
and the reporting protocol do not change. No container runtime socket is
needed. The run report records the digest of the image that ran
(worker image).
worker:
runtime: kubernetes
image: ghcr.io/orpiske/saci-worker:0.1.0
kubernetes:
namespace: saci # default: the backend pod's namespace
service_account: saci-worker # default: none, see Identities
image_pull_policy: IfNotPresent
llm:
api_key: env:SACI_LLM_API_KEY
api_key_secret: { name: saci-llm, key: api-key }
environments:
same-namespace:
secrets:
SERVICE_TOKEN: { secret: demo-service, key: token }
Inside a pod, the backend uses its own service account: the token, CA and
namespace mounted at /var/run/secrets/kubernetes.io/serviceaccount. It
reads the token again for every request, so rotated tokens keep working.
Outside the cluster, for development, set worker.kubernetes.api_url and
worker.kubernetes.namespace. The backend sends requests to that URL
without credentials of its own, so point it at kubectl proxy, which adds
yours:
kubectl proxy --port=8001 &
worker:
runtime: kubernetes
kubernetes:
api_url: http://127.0.0.1:8001
namespace: saci-dev
Workers must then reach the backend at backend.worker_url from inside
the cluster.
At start-up the backend lists Jobs once. If that fails, it logs why and
keeps serving, and every run ends error with the reason, as with a
missing container runtime. For example:
the worker could not be launched: the Kubernetes API refused GET /apis/batch/v1/namespaces/saci/jobs?limit=1
(403 Forbidden): jobs.batch is forbidden: ...; grant the backend's service account the Role in
docs/operate/kubernetes-jobs.md#permissions
The backend’s service account needs this Role in the workers’ namespace, and nothing cluster-wide:
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: saci-launcher
rules:
- apiGroups: ["batch"]
resources: ["jobs"]
verbs: ["create", "get", "list", "patch", "delete"]
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "list", "delete"]
- apiGroups: [""]
resources: ["pods/log"]
verbs: ["get"]
- apiGroups: [""]
resources: ["secrets"]
verbs: ["create"]
The backend never reads Secrets. It creates one per run, and the environment’s Secrets are referenced by name and read only by the worker’s pod.
The backend and the workers use different service accounts:
worker.kubernetes.service_account. When it
is set, the account’s token is mounted in the worker pod, so a test
environment can be given exactly the cluster access its plans need,
through that account’s own RoleBindings. When it is not set, worker pods
run as the namespace’s default account with no token mounted
(automountServiceAccountToken: false), so plans cannot use the
Kubernetes API.For run run-1a2b… the backend creates a Job and a Secret, both named
saci-run-1a2b… and labelled io.saci.managed=true and
io.saci.run=run-1a2b…:
backoffLimit: 0 and restartPolicy: Never. A worker
that fails is recorded, not repeated, because its actions may already
have run. A second launch for the same run fails on the Job name instead
of creating a duplicate.activeDeadlineSeconds is the run’s
limits.run_timeout_secs plus 300 seconds, plus
limits.cleanup_timeout_secs when the policy has after_stop: cleanup.
Kubernetes enforces it even
when the backend is not running.runAsNonRoot: true, drops
all capabilities, disallows privilege escalation and uses the
RuntimeDefault seccomp profile. It does not set runAsUser: the image
runs as UID 10001 by default, and OpenShift’s restricted-v2 SCC may
assign another UID. The image works with any UID in group 0
(worker).SACI_BACKEND_URL and SACI_RUN_ID are plain values.{ env: VAR } secrets, or an LLM key without api_key_secret) are in
the run’s Secret.{ secret, key } secrets and llm.api_key_secret are secretKeyRefs
to Secrets in the namespace, which only the pod reads.No value appears in the Job. The run’s Secret is owned by the Job.
environments.<env>.worker.cpu and .memory become both
requests and limits, in Kubernetes quantities (500m, 512Mi).enableServiceLinks: false keeps other Services’
addresses out of the worker’s environment.| Event | What happens |
|---|---|
| The pod is pending or running | The run is watched. A pod that cannot start (an image pull failure, for example) is ended by the run deadline, and its waiting reason is added to the recorded reason. |
| The worker reports the run’s end | The backend deletes the Job with background propagation. Kubernetes then removes the pod and the run’s Secret. |
| Cancellation or the backend’s deadline | The backend suspends the Job (patch), so its controller starts no replacement pod, then deletes the pod with gracePeriodSeconds: 30: SIGTERM, then SIGKILL. On SIGTERM the worker cancels and reports. The Job is then removed. |
| The worker exits without reporting | The run ends error with the exit code and the last 40 lines of the pod’s log, redacted. |
| The Job disappears | The run ends error (the worker disappeared). |
| The backend restarts | Jobs of unfinished runs are watched again. Runs never handed to a worker are launched. Other unfinished runs end error and are not repeated. Jobs of runs that had finished are deleted. Jobs of runs this backend does not know are left alone. |