自动化的 Kubernetes 工作负载资源跟踪和调整
Ballast is a Kubernetes operator that automatically right-sizes workload resource requests and limits based on real operational history. It is a more active alternative to Fairwinds Goldilocks: rather than suggesting changes, it applies them — at admission time and on running pods via in-place resize (Kubernetes 1.35+).
This is one cluster's CPU over three days. The purple line is allocatable capacity; the blue line is the sum of pod requests — what the scheduler believes is claimed; the red line is what those pods actually burn.
For the first two days requests ride right up against the ceiling. On paper the cluster is full and can't schedule another pod, yet real usage runs at less than half the reservation. That gap is pure waste: capacity paid for, reserved, and never used.
Partway through 7/3 the workloads are enrolled in Ballast. Requests drop to track observed usage, freeing roughly half the cluster's schedulable CPU without touching a single running workload. That reclaimed headroom is the point: the same nodes now fit far more work, or you run the same work on fewer nodes.
The Vertical Pod Autoscaler is the obvious tool for this job, and for a single stable, long-lived workload it works well. Ballast exists because VPA ties a workload's usage history to that one workload's identity in one namespace, and three everyday situations throw that history away and drop you back to guessing:
(namespace, container name, pod labels), and that key is not adjustable — it is derived automatically, and a VPA object is itself namespaced, so it physically cannot aggregate pods from another namespace. Deploy the same app (service: billing, component: backend-api, profile: dev) into a second namespace, say a different developer's own test namespace, and the namespace in that key changes, so VPA sees a brand-new workload and starts from zero. Every namespace relearns the same app independently. Cold start, again.VerticalPodAutoscalerCheckpoint resources owned by the VPA object). Delete the workload and its VPA object, as any GitOps teardown or helm uninstall does, and Kubernetes garbage-collects the checkpoints along with it. Redeploy a minute later and there is no history left to recover. Cold start, a third time.Ballast fixes all three by decoupling history from the workload object. It keys usage on a workload identity tuple you choose (a set of pod labels; see WorkloadProfile Identity) and stores it cluster-wide in Redis/Valkey, independent of namespace and independent of any single workload's lifecycle. Forty dev namespaces running the same app all feed one well-sampled profile, so a brand-new deployment — in a fresh namespace, or right after a teardown — inherits the fleet's accumulated history and is sized correctly from its very first admission instead of relearning from scratch.
Workloads opt in with a single label on their pod templates. Ballast observes real CPU, memory, and ephemeral-storage utilization, accumulates a rolling history keyed to a workload identity tuple (a set of pod labels you configure), and uses that history to right-size all three resources across an escalating ladder of behaviors:
You choose a rung with the ballast.tightlinesoftware.com/mode label; each rung includes everything below it. Nothing is applied or resized until the WorkloadProfile meets its readiness threshold — that is normal behavior for any resize-enabled workload.
Pod eviction for cluster rebalancing is handled by Kubernetes Descheduler — see the Enrollment section for details.
valkey: block in values.yaml).cert-manager must already be installed in the cluster (Ballast does not install it):
helm install ballast oci://ghcr.io/tight-line/charts/ballast \
--namespace ballast-system \
--create-namespaceThis pulls the latest signed chart from the GitHub Container Registry. To pin a version, add --version (the Releases page lists every version). For supply-chain-sensitive clusters, verify the chart's signature before installing, and consider enforcing that verification at admission time (examples/admission).
The chart ships with a sensible default for ballastConfig.identityLabels (app.kubernetes.io/name + app.kubernetes.io/component). Read the section below before overriding it — the choice has cluster-wide consequences.
Upgrades are helm upgrade --install ballast oci://ghcr.io/tight-line/charts/ballast with no extra steps. CRDs are kept in sync automatically: Helm itself never upgrades the crds/ directory, so the chart runs a pre-install/pre-upgrade hook Job (ballastd apply-crds) that server-side-applies the CRD manifests baked into the operator image. Set crds.upgradeHook.enabled: false to opt out if external tooling manages CRDs; you are then responsible for applying config/crd/bases/ on every upgrade.
Both the container image (ghcr.io/tight-line/ballast) and the Helm chart (ghcr.io/tight-line/charts/ballast) are keyless-signed with cosign via GitHub OIDC and the public sigstore infrastructure. There is no public key to manage; verification checks that the artifact was signed by Ballast's release workflow.
IDENTITY='^https://github\.com/Tight-Line/ballast/\.github/workflows/release\.yml@refs/tags/v'
ISSUER=https://token.actions.githubusercontent.com
# container image
cosign verify ghcr.io/tight-line/ballast: \
--certificate-identity-regexp "$IDENTITY" \
--certificate-oidc-issuer "$ISSUER"
# Helm chart
cosign verify ghcr.io/tight-line/charts/ballast: \
--certificate-identity-regexp "$IDENTITY" \
--certificate-oidc-issuer "$ISSUER"The image also carries a SLSA build-provenance attestation and an SBOM; SECURITY.md has the full set of verification commands. To make the cluster admit only images that pass this check, see examples/admission.
Ballast is distributed as signed OCI artifacts from the GitHub Container Registry: the operator image at ghcr.io/tight-line/ballast and the Helm chart at ghcr.io/tight-line/charts/ballast. Releases through v0.4.x were also published to a GitHub Pages Helm repo at https://tight-line.github.io/ballast. That repo is now frozen: existing helm repo add users and already-published versions keep resolving, but new versions ship only via the OCI chart above, so migrate to the helm install oci://… flow when you upgrade.
Every release, with its notes and the packaged chart attached, is on the Releases page.
Ballast groups pods into WorkloadProfile objects by matching a configurable set of pod label keys called the identity tuple. The tuple is defined once in BallastConfig.spec.identityLabels and applies to every namespace in the cluster.
WorkloadProfiles are cluster-scoped. Every pod in every namespace that shares the same label values for the identity keys feeds measurements into the same profile. This is intentional: forty dev namespaces all running the same billing app produce one well-sampled WorkloadProfile, not forty thin ones.
The one thing that splits an identity tuple is the policy governing it. A profile holds a single set of recommendations, and the policy is what decides how they are measured and sized, so pods that resolve to different policies get different profiles (see policy precedence). With only the default cluster-wide policy in place, nothing splits and the tuple is the whole story.
name + componentballastConfig:
identityLabels:
- app.kubernetes.io/name
- app.kubernetes.io/componentThis works well for clusters that run a single environment class. The frontend and backend of the same app get separate profiles; forty developers' copies of billing all contribute to the same (billing, api) profile.
If your cluster runs dev, staging, and production side-by-side and you want separate profiles per environment, add ballast.tightlinesoftware.com/resource-profile to the identity tuple and apply it to your pods:
# BallastConfig / Helm values
ballastConfig:
identityLabels:
- app.kubernetes.io/name
- app.kubernetes.io/component
- ballast.tightlinesoftware.com/resource-profile# Pod template labels
labels:
app.kubernetes.io/name: billing
app.kubernetes.io/component: api
ballast.tightlinesoftware.com/resource-profile: prodNow (billing, api, prod) and (billing, api, dev) are measured independently. Pods without the ballast.tightlinesoftware.com/resource-profile label get a placeholder value in the profile name (noresourceprofile) rather than being skipped, so opted-in pods always produce a profile.
Changing
identityLabelswipes your operational history. It redefines what constitutes a workload identity, so all existingWorkloadProfileobjects are renamed and their accumulated Redis history is orphaned. Ballast starts fresh from zero samples. Plan your tuple before enrolling workloads.
Enroll a workload by setting the ballast.tightlinesoftware.com/mode label on its pod template. Ballast never acts on a workload without explicit opt-in. The value is a single rung on an escalating ladder; each rung includes everything below it.
ballast.tightlinesoftware.com/mode |
Behavior |
|---|---|
measure |
Collect metrics only |
apply |
measure, plus patch requests/limits at admission time |
resize |
apply, plus adjust resources on running pods via in-place resize |
Enrollment is a label, not an annotation, so the API server can filter on it server-side. Ballast's controllers watch and its admission webhook fires only for pods that carry the label, which keeps the operator's footprint proportional to the number of enroll
暂无开放 Issues,或尚未同步最近议题。