Skip to main content
Version: Preview

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​

  1. 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.cordon and triggers.clusterWide. Every value is in the runner reference.

  2. Write the pipeline

    The pipeline catalogs the cluster and sets the plugin's own limits on tools. Keep tools.namespaces the same as the chart's namespaces:

    name: prod-cluster
    runs:
    - kubernetes:
    cluster_name: prod-cluster
    namespaces: [payments, checkout]
    tools:
    namespaces: [payments, checkout]
    max_replicas: 10
    queryable: true

    The 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.

  3. 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: marmot
    max_age: 15m
    sources:
    prod-cluster:
    query: false
    tools:
    workload_status: {}
    pod_logs: {}
    recent_events: {}
    rollout_restart:
    approvals: 1
    scale:
    approvals: 2
    params:
    namespace: {values: [payments]}
    replicas: {min: 1, max: 5}
    triggers:
    workload_unhealthy:
    params:
    namespaces: [payments, checkout]
    conditions: [crash_looping, oom_killed]
    for_minutes: 10
    cooldown: 30m

    This runner lets tasks read status, logs and events, restart a workload with 1 approval and scale one in payments between 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.

  4. Start the runner

    Run it as a Deployment in the marmot namespace 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/v1
    kind: Deployment
    metadata:
    name: marmot-runner
    namespace: marmot
    spec:
    replicas: 1
    selector:
    matchLabels: {app: marmot-runner}
    template:
    metadata:
    labels: {app: marmot-runner}
    spec:
    serviceAccountName: marmot-tools
    containers:
    - name: runner
    image: 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.jsonl
    env:
    - name: MARMOT_HOST
    value: https://<instance>.marmotdata.cloud
    - name: MARMOT_API_KEY
    valueFrom:
    secretKeyRef: {name: marmot-runner, key: api-key}
    volumeMounts:
    - {name: config, mountPath: /etc/marmot}
    - {name: audit, mountPath: /var/log/marmot}
    volumes:
    - name: config
    configMap: {name: marmot-runner}
    - name: audit
    persistentVolumeClaim: {claimName: marmot-runner-audit}

    --allow-tools turns 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.

  5. 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​

  1. Open Tasks and select New task. For your cluster offers Restart crash-looping deployments.
  2. Select Start from scratch, then choose When something happens. Under Where from, prod-cluster shows Set up.
  3. 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 seeWhat to do
--allow-tools needs --audit-logAdd --audit-log with a writable path.
tool "<name>" is not in the plugin's manifest or has no parameterThe policy names something the plugin doesn't offer. Check the spelling against the plugin's tools.
no approvers configured: the policy has no approvals sectionAdd 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 runnerThe policy doesn't name it. Add it and restart the runner.
An approved change fails with forbiddenThe 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 policyThe 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 CDMake the change in Git.
A change is marked staleThe object changed since the plan. Select Plan again on the change, then approve the new plan.

Next steps​