Skip to content

Dynamic Kubernetes Agents

A dynamic Kubernetes agent is a pod provisioned on-demand for a single build and torn down after, assembled from modular templates rather than pre-provisioned as a static machine.

jenkins-k8sagent-lib is a good reference implementation of the pattern: pipelines request an agent by a concatenated label (small+postgres+privileged), and the library composes a pod spec at runtime from separate template fragments — size, containers, security mode — stored independently instead of as one monolithic YAML per agent type. I run a modified version of this template-composition approach for dynamic agent provisioning; the fragment-based structure is what makes it worth adopting over a handful of hand-maintained static pod specs — a new tool requirement becomes a new small fragment, not a new full template to keep in sync with every other one.

This is the concrete mechanism behind agents are cattle: a pod that only exists for the duration of one build can’t accumulate the kind of drift a long-lived static agent does, because there’s no lifespan for drift to accumulate over.

Related