Let tasks act on a Kubernetes cluster
Run a runner in your cluster so tasks can look at what's wrong, start on their own when a workload breaks and propose a fix for people to approve. The runner connects out to Marmot, holds the cluster credentials and decides what it will do. Runners explains what it trusts.
Before you start
- You can install a Helm chart in the cluster and create a namespace.
- The cluster can reach Marmot on port 443 and on the serve port, 8443.
- You have a Marmot service account with Serve ingestion (
ingestion:serve) and its API key. See Serve queries from your network. - Tasks are turned on for your instance.
How it works
A chart gives the runner's service account only the access each tool needs, and an admission policy refuses any other change from it. The runner's policy file then names the reads, tools and triggers it serves and how many people must approve each change.
Set it up
Install the tools chart
The chart creates the runner's service account, a Role in each namespace you list and the admission policy. List the namespaces tasks may touch:
helm install marmot-tools marmotdata/marmot-kubernetes-tools \--namespace marmot --create-namespace \--set 'namespaces={payments,checkout}'Scale, restart, the reads and namespaced triggers are on by default. Cordoning nodes, and triggers that watch nodes or every namespace, are off until you turn them on with
tools.cordonandtriggers.clusterWide. Every value is in the runner reference.Write the pipeline
The pipeline catalogs the cluster and sets the plugin's own limits on tools. Keep
tools.namespacesthe same as the chart'snamespaces:name: prod-clusterruns:- kubernetes:cluster_name: prod-clusternamespaces: [payments, checkout]tools:namespaces: [payments, checkout]max_replicas: 10queryable: trueThe source takes the pipeline's name, so tasks see it as
prod-cluster. Run in the cluster as the chart's service account, the plugin needs no host or token.Write the runner's policy
The policy names every read, tool and trigger the runner serves. Anything it leaves out is refused, whatever Marmot asks:
approvals:trust: marmotmax_age: 15msources:prod-cluster:query: falsetools:workload_status: {}pod_logs: {}recent_events: {}rollout_restart:approvals: 1scale:approvals: 2params:namespace: {values: [payments]}replicas: {min: 1, max: 5}triggers:workload_unhealthy:params:namespaces: [payments, checkout]conditions: [crash_looping, oom_killed]for_minutes: 10cooldown: 30mThis runner lets tasks read status, logs and events, restart a workload with 1 approval and scale one in
paymentsbetween 1 and 5 replicas with 2 approvals. It tells Marmot when a workload has been crash looping or running out of memory for 10 minutes.Start the runner
Run it as a Deployment in the
marmotnamespace with the chart's service account,marmot-tools. Keep the API key in a Secret and the pipeline and policy in a ConfigMap:apiVersion: apps/v1kind: Deploymentmetadata:name: marmot-runnernamespace: marmotspec:replicas: 1selector:matchLabels: {app: marmot-runner}template:metadata:labels: {app: marmot-runner}spec:serviceAccountName: marmot-toolscontainers:- name: runnerimage: ghcr.io/marmotdata/marmot:<version>args:- plugin- -c=/etc/marmot/pipeline.yaml- --serve- --allow-tools- --policy=/etc/marmot/policy.yaml- --audit-log=/var/log/marmot/audit.jsonlenv:- name: MARMOT_HOSTvalue: https://<instance>.marmotdata.cloud- name: MARMOT_API_KEYvalueFrom:secretKeyRef: {name: marmot-runner, key: api-key}volumeMounts:- {name: config, mountPath: /etc/marmot}- {name: audit, mountPath: /var/log/marmot}volumes:- name: configconfigMap: {name: marmot-runner}- name: auditpersistentVolumeClaim: {claimName: marmot-runner-audit}--allow-toolsturns on reads, tools and triggers, and needs--audit-log. Keep the audit log on a volume that outlives the pod, because the runner uses it to refuse an approval used before a restart.Optional: pin the plugin's tools
When the runner starts, it logs the digest of the plugin's tools. Copy it into the policy so a plugin upgrade that changes any tool, down to one bound, is refused until you review it:
sources:prod-cluster:manifest: sha256:<digest>
Check that it worked
- Open Tasks and select New task. For your cluster offers Restart crash-looping deployments.
- Select Start from scratch, then choose When something happens. Under Where from,
prod-clustershows Set up. - Continue to What may it do?. It lists Offered by the runner for prod-cluster, with the reads and the tools your policy allows.
To check the runner's own record:
marmot ingest verify-audit-log /var/log/marmot/audit.jsonl
Troubleshooting
| What you see | What to do |
|---|---|
--allow-tools needs --audit-log | Add --audit-log with a writable path. |
tool "<name>" is not in the plugin's manifest or has no parameter | The policy names something the plugin doesn't offer. Check the spelling against the plugin's tools. |
no approvers configured: the policy has no approvals section | Add approvals: {trust: marmot} to the policy. |
the plugin's manifest is sha256:…, and the policy pins sha256:… | The plugin's tools changed since you pinned them. Review what changed, then copy the new digest into manifest. |
| A tool is listed under Not allowed by the runner | The policy doesn't name it. Add it and restart the runner. |
An approved change fails with forbidden | The chart doesn't grant it, or the namespace isn't in the chart's namespaces. Upgrade the chart with the same namespaces as the pipeline. |
An approved change fails with denied request from the admission policy | The change touches more than the tool may, or the object lacks a label in selector. |
| A change is refused because the object is managed by Flux or Argo CD | Make the change in Git. |
| A change is marked stale | The object changed since the plan. Select Plan again on the change, then approve the new plan. |
Next steps
- Create a task: start a task when a workload keeps crashing.
- Approve changes: review, approve and undo what tasks propose.
- Runner reference: every trigger, policy key and chart value.