Provider Connectors
Automation
The optional component that resizes running pods toward their targets and after OOM kills or throttling, configured with objects in your cluster, and stopped or reverted in one step.
The agent only reads your cluster. Automation is a separate, optional component that changes it, in the namespaces you allow. It installs with the agent's chart, runs with its own service account and permissions, and changes nothing until a configuration object or an admin in the dashboard turns it on.
It does four things:
- Fixes in place. After OOM kills or sustained CPU throttling, it gives the running container more memory or CPU without restarting it.
- Rightsizing steps. Where automation is on, it moves each container's requests toward the target LevelFour measured, one step at a time, on the running pods.
- Keeps the values on new pods. With the webhook on, a rollout or a scale-out starts its pods with the values already reached, with no change to your manifests.
- Auto-merge. It merges the LevelFour pull requests that fall in a class you opted a namespace into.
Where it acts
The component acts in a namespace only when all three of these hold:
- Your install allows it. The chart value
automation.allowedNamespaceslists the namespaces it may touch. The chart grants it permissions in those namespaces and nowhere else, so Kubernetes refuses anything outside the list. - The namespace is opted in to recommendations, with the
levelfour.ai/recommendations=enabledlabel, the switch on the namespace page, or a configuration object. An object that setsautomationModeopts in the namespaces it covers: its own for a namespace's or a workload's object, every namespace inautomation.allowedNamespacesfor a cluster's. A label or the switch that turns a namespace off still wins. Choose namespaces covers the label and the switch. - Automation is turned on for the workload, by a configuration object or by an admin on the cluster's Automation tab.
It never acts in kube-system, kube-public, kube-node-lease or the agent's own namespace, nor in a namespace labelled levelfour.ai/automation: "off". Quote "off", which YAML would otherwise read as false. To keep LevelFour to one cluster and two of its namespaces, install the component on that cluster only and list the two namespaces.
Install it
In-place resize needs Kubernetes 1.33 or later. Add the component to your install:
automation:
enabled: true
allowedNamespaces:
- payments
- checkout
webhook:
enabled: true
revert:
allowPodEviction: false
hardLimits:
maximumCores: 8
maximumGiB: 16helm upgrade levelfour-agent oci://public.ecr.aws/levelfour/charts/levelfour-agent \
--version 0.6.1 \
--namespace levelfour --reset-then-reuse-values -f values.yamlIf you turned the component on with chart 0.4.x, follow Upgrade instead, because reusing your values brings back the old automation keys and the chart refuses them.
| Value | Default | What it does |
|---|---|---|
automation.enabled | false | Installs the component and the configuration objects. On its own it changes nothing |
automation.allowedNamespaces | [] | The namespaces the component may change. Required with automation.enabled: true. ["*"] grants the whole cluster and makes the component watch every pod, so a list is lighter on a big cluster |
automation.webhook.enabled | false | Gives each new pod of a rightsized workload its values at creation |
automation.revert.allowPodEviction | false | Lets a revert evict a pod whose memory limit Kubernetes 1.33 and 1.34 will not lower in place |
automation.hardLimits.maximumCores | 8 | The most CPU, in cores, the component or the webhook sets on a container, request or limit, whatever an object or the dashboard asks for |
automation.hardLimits.maximumGiB | 16 | The same ceiling for memory, in GiB |
The chart refuses an empty automation.allowedNamespaces, a hard limit that is not positive, and any automation key it does not know. Configure the agent lists the component's own resources and priority class.
The webhook needs port 9443
The control plane must reach the webhook's pods on port 9443. On EKS, allow it from the cluster security group in your nodes' security groups, and for Karpenter in the EC2NodeClass's. Without it, the webhook times out, new pods start as their manifests say, and the component resizes them in place afterwards.
Configure it in the cluster
The chart defines six objects in the levelfour.ai/v1 API group. A team that keeps its configuration in Git applies them with kubectl or Argo CD like any other manifest.
| Kind | Scope | What it sets |
|---|---|---|
ClusterAutomationConfig | Cluster | When the automation may act and how much it may change, for the whole cluster |
NamespaceAutomationConfig | Namespace | The same, for one namespace |
WorkloadAutomationConfig | Namespace | The same, for one workload and its containers, named by targetRef |
ClusterRecommendationsConfig | Cluster | The sizing policy and the days of history a target reads |
NamespaceRecommendationsConfig | Namespace | The same, for one namespace |
WorkloadRecommendationsConfig | Namespace | The same, for one workload |
kubectl explain clusterautomationconfig.spec --recursive describes every field and its default, and kubectl get levelfour -A lists every object with its status.
A cluster object
The levelfour.ai/approved-by annotation names the person who approved turning automation on, and an object that sets automationMode: Enabled needs it. In this example:
stopAllAutomation: truewould pause the automation in the whole cluster, andcleanupAllAutomation: truewould stop it and put every changed pod back on its spec.duringRolloutInProgress: pauseholds new changes on a workload while it rolls out.workloadLabelSelectorsleaves out the workloads labelledcriticality: tier-0.wasteMaxAutomationFrequencysets the shortest time between two cuts on one workload, andfixResiliencyMaxAutomationFrequencybetween two raises.maintenanceWindowsets the hours, in UTC, for each weekday.00:00-00:00allows no change that day, here Saturday and Sunday. WithmaintenanceWindowIgnoredMinResiliencyLevel: High, an OOM fix may act outside the window.workloadMinWasteUSDPerMonth: 5cuts only when the waste passes 5 US dollars a month.maximumCores: -1sets no maximum of its own, soautomation.hardLimitsstill caps it.
apiVersion: levelfour.ai/v1
kind: ClusterAutomationConfig
metadata:
name: cluster
annotations:
levelfour.ai/approved-by: sre@levelfour.ai
spec:
automation:
operational:
stopAllAutomation: false
cleanupAllAutomation: false
duringRolloutInProgress: pause
workloadLabelSelectors:
- key: criticality
value: tier-0
allowAutomation: false
timeConstraints:
wasteMaxAutomationFrequency: "30m"
fixResiliencyMaxAutomationFrequency: "30m"
maintenanceWindow:
monday: ["09:00-18:00"]
tuesday: ["09:00-18:00"]
wednesday: ["09:00-18:00"]
thursday: ["09:00-18:00"]
friday: ["09:00-18:00"]
saturday: ["00:00-00:00"]
sunday: ["00:00-00:00"]
maintenanceWindowIgnoredMinResiliencyLevel: High
restrictions:
workloadMinWasteUSDPerMonth: 5
cpuManagement:
request:
increaseEnabled: true
decreaseEnabled: true
minimumCores: 0.1
maximumCores: -1
cpuRunawayDetection:
maxCpuRequestIncreaseIterations:
daily: 3
weekly: 6
limit:
keepLimit: true
memoryManagement:
request:
increaseEnabled: true
decreaseEnabled: true
minimumGiB: 0.25
maximumGiB: -1
limit:
increaseEnabled: true
decreaseEnabled: false
fastOOMReaction:
enabled: true
minimumGiB: -1
maximumGiB: -1
memoryLeakDetection:
maxMemoryIncreaseIterations:
daily: 3
weekly: 6
workloadTypes:
Deployment:
operational:
automationMode: Enabled
StatefulSet:
operational:
automationMode: Enabled
DaemonSet:
operational:
automationMode: DisabledAutomation turns on per kind of workload, under workloadTypes, which takes Deployment, StatefulSet and DaemonSet. Enabled lets the automation change those workloads. Disabled keeps them unchanged, and LevelFour still shows the step it would take. Each kind can also carry its own timeConstraints and restrictions under operational, which override the object's own for that kind.
A namespace object
This one never cuts a memory request in checkout and turns automation on for the namespace's Deployments.
apiVersion: levelfour.ai/v1
kind: NamespaceAutomationConfig
metadata:
name: checkout
namespace: checkout
spec:
automation:
operational:
restrictions:
memoryManagement:
request:
decreaseEnabled: false
workloadTypes:
Deployment:
operational:
automationMode: EnabledA namespace object takes duringRolloutInProgress, workloadLabelSelectors, timeConstraints, restrictions and workloadTypes. The two kill switches belong to the cluster object only.
A workload object
targetRef.kind takes Deployment, StatefulSet or DaemonSet. Each key under containers names one container and holds its override, here a minimum memory request of 2 GiB for the jvm container.
apiVersion: levelfour.ai/v1
kind: WorkloadAutomationConfig
metadata:
name: api
namespace: payments
annotations:
levelfour.ai/approved-by: sre@levelfour.ai
spec:
targetRef:
kind: Deployment
name: api
automation:
operational:
automationMode: Enabled
timeConstraints:
wasteMaxAutomationFrequency: "4h"
containers:
jvm:
operational:
restrictions:
memoryManagement:
request:
minimumGiB: 2The sizing policy
workloadPolicy takes MaxSavings, Balanced, ExtraHeadroom or MaxHeadroom. cpuPolicy and memoryPolicy set it for CPU or memory alone, and each defaults to workloadPolicy. customTimeWindowDays is how many days of usage a target reads, from 1 to 30. memoryRequestEqualsLimit: true would set the memory limit equal to the new request.
apiVersion: levelfour.ai/v1
kind: ClusterRecommendationsConfig
metadata:
name: cluster
spec:
policies:
workloadPolicy: Balanced
cpuPolicy: MaxSavings
memoryPolicy: Balanced
customTimeWindowDays: 14
memoryRequestEqualsLimit: falseNamespaceRecommendationsConfig takes the same policies, and WorkloadRecommendationsConfig adds a targetRef. A container takes no step before LevelFour has customTimeWindowDays of its usage. The component reads these objects too, so they need it installed, and they apply to recommendations whether or not automation is turned on.
Which value wins
The most specific value wins, field by field. In order:
- A container's override in its workload object.
- The workload object.
- The namespace object's settings for the workload's kind, then the namespace object.
- The cluster object's settings for the workload's kind, then the cluster object.
- A value saved on the Automation tab.
- The default.
-1 means none: no minimum, no maximum or no cap. It overrides a wider value, so a namespace can lift a minimum the cluster set. Each weekday of a maintenanceWindow is its own field, so a namespace that names Saturday leaves the cluster's Monday as it was. A field an object sets cannot be changed from the dashboard, and LevelFour refuses the change.
Defaults
Raising is on by default, because a cut is only safe when the automation may raise again after an OOM kill.
| Field | Default |
|---|---|
automationMode | Not set: the Automation tab decides |
stopAllAutomation, cleanupAllAutomation | false |
duringRolloutInProgress | pause |
wasteMaxAutomationFrequency, fixResiliencyMaxAutomationFrequency | 30m for a Deployment, 4h for a DaemonSet, 24h for a StatefulSet |
maintenanceWindow | Every day, all day |
maintenanceWindowIgnoredMinResiliencyLevel | None |
workloadMinWasteUSDPerMonth | 5 |
request.increaseEnabled, request.decreaseEnabled (CPU and memory) | true |
memoryManagement.limit.increaseEnabled | true |
memoryManagement.limit.decreaseEnabled | false |
fastOOMReaction.enabled | true |
keepLimit | true |
Every minimum* and maximum* | -1, capped by automation.hardLimits |
daily, weekly raise caps | 3 and 6 |
workloadPolicy | Balanced |
customTimeWindowDays | 14 |
memoryRequestEqualsLimit | false |
A few rules sit behind those fields:
- Windows. A span reads
"HH:MM-HH:MM"in UTC and includes both ends."00:00-00:00"keeps the automation out for the whole day, and a weekday an object leaves out allows the whole day.maintenanceWindowIgnoredMinResiliencyLevellets a fix act outside the window: an OOM kill counts asHighand throttling asMedium. A rightsizing step never leaves the window. - Bounds. A move toward a bound always goes ahead.
minimumCoresandminimumGiBstop a cut or a new request, andmaximumCoresandmaximumGiBstop a raise. The CPU limit follows the CPU request's switches and bounds. - CPU limits. The automation never removes a CPU limit, so
keepLimitmust betrue. - Guaranteed pods. A Guaranteed pod's memory request equals its limit, so cutting it lowers the limit too. That needs
memoryManagement.limit.decreaseEnabled: true, which is off by default, so a Guaranteed pod's memory is not cut until an object turns it on. - Rollouts. With
pause, a workload in the middle of a rollout takes no new step or raise: live pods from two of a Deployment's ReplicaSets, or a StatefulSet or DaemonSet its controller has not finished updating. A rollback or a revert still runs.continuelets them go ahead. - Labels.
workloadLabelSelectorsfrom the cluster and namespace objects add up, and the namespace wins on the same key and value. With onlyallowAutomation: trueentries, the automation acts on the workloads that match one. Withfalseentries, it leaves out the ones that match one, even when a workload object turns it on.
Turning it on, and who approved it
automationMode: Enabled, under workloadTypes in a cluster or namespace object or on a workload object, needs the email of the person who approved it in the levelfour.ai/approved-by annotation. Without it the object is not applied.
LevelFour records that email as the approver the object declares, together with the object's kind, namespace, name and generation, the way a commit names its author. Whoever may write the object may write any email there, so the approval itself is the review in your own repository. A change turned on from the dashboard records the admin who turned it on.
What the component made of each object
The component reads every object, sends the ones it accepted to LevelFour every minute, and writes its verdict to each object's Ready condition:
| Reason | Ready | Meaning |
|---|---|---|
Accepted | True | LevelFour applies it |
Conflict | False | An older object of the same kind covers the same scope: one per cluster, one per namespace, one per workload. The oldest stands. Delete one of the two |
MissingApproval | False | It turns automation on without an email in levelfour.ai/approved-by |
InvalidWindow | False | A maintenanceWindow span ends before it starts |
NamespaceNotAllowed | False | Its namespace is not in automation.allowedNamespaces, so the component cannot act there. Recommendations objects are exempt, since they change no pod |
TooManyObjects | False | Its namespace holds more than 100 workload objects, or the cluster more than 2,000, and this one came after them by name. Cluster and namespace objects always count |
The API server checks each object as it is applied, so a misspelled field, a minimum above its maximum, a window written 9:00-18:00 or an interval written 30s never gets in.
The component also holds the accepted objects itself, before it asks LevelFour. It refuses a change on a workload set to Disabled, outside its window, when the resource's increase or decrease is off, or past a minimum or maximum. stopAllAutomation pauses it at once, even when LevelFour cannot be reached, and cleanupAllAutomation reverts it.
Who may write the objects
| Objects | Who |
|---|---|
| Namespace and workload objects in a namespace | That namespace's admin role, which the chart extends |
| Cluster objects | Whoever may write cluster-scoped resources |
| Reading any of them | Anyone with the view role |
Whoever may write an object may turn automation on in the namespaces automation.allowedNamespaces lists. The install keeps its own limits above every object: that list, automation.hardLimits, stopAllAutomation in the cluster object, and the levelfour.ai/automation: "off" label on a Namespace.
What it changes
Fixes after OOM kills and throttling
| Trigger | What it raises | When |
|---|---|---|
| OOM kill | Memory | Two OOM kills of the same container within an hour, or one while it crash loops |
| CPU throttling | CPU | LevelFour measured the container throttled at its current limit |
Each raise adds up to 25% of memory or 50% of CPU, within the objects' maximums and automation.hardLimits, and never past double the workload's own spec. A JVM sized by MaxRAMPercentage gets more memory, so the room outside its heap still grows by the step. fastOOMReaction.enabled: false turns the memory raise off, and the daily and weekly caps stop raises in a row.
Rightsizing steps
Where automation is on for a workload, LevelFour plans steps toward each container's target, and the component takes them:
- Size of a step. A cut takes at most 20% of the request at a time, and a raise goes in one step.
- Pace. The next step waits the workload's interval:
wasteMaxAutomationFrequencyafter a cut,fixResiliencyMaxAutomationFrequencyafter a raise. - How. The component asks LevelFour to approve the step, dry-runs it, then moves every running pod of the workload in place, at most 10 pods a minute. A Burstable pod keeps its limit. A Guaranteed pod's limit moves with its request, which Kubernetes lowers in place only from 1.35.
- Checking it. Until the interval passes, an OOM kill, an eviction, two restarts within an hour or a pod that stops being ready puts the workload's pods back, with no approval, and reports it. They go back to the most recent value that held through the workload's daily peak, the hour of the day, in UTC, when the container uses the most of that resource. When no step has held through it, they go back to the manifest's value.
- After a rollback. For 14 days the automation does not cut that resource below the value it went back to. The other resource keeps moving.
- A workload that cannot create pods, because its ReplicaSet reports
ReplicaFailureor its controller loggedFailedCreate, drops out of the rightsized values at once. - No pull request for the same change. A container the component takes to its target in place gets no request recommendation or pull request for it.
The values reached go to ConfigMaps named levelfour-desired-<namespace>-<n> in the agent's namespace. A pod that starts on its workload's spec gets them in place, and with the webhook on, a new pod gets them at creation. The webhook changes a container only while its values equal the ones LevelFour planned from, so a change to your manifest wins at once.
When your team changes the manifest
Your manifest stays the source of truth. When a deploy changes a container's requests or limits:
- The new pods start with the values the manifest sets. The webhook leaves them as they are, and LevelFour approves no step planned from the old values.
- Within a day, at LevelFour's daily scan, the container starts over from the new values. The values new pods were given are withdrawn, and the steps it took and any floor a rollback left are cleared.
- LevelFour learns the container again for
customTimeWindowDays, counted from the change, before it plans the next step. The steps then go as before: a cut of at most 20% at a time, at the workload's interval, inside its window.
A new image with the same requests and limits does not start the container over.
To keep a workload where its manifest puts it, give it a workload object with automationMode: Disabled, and LevelFour keeps showing the steps it would take. To keep only one resource there, set decreaseEnabled: false for it, or a minimumCores or minimumGiB at the manifest's value. To keep a whole namespace out, label it levelfour.ai/automation: "off".
What it leaves alone
- BestEffort pods, and pods that set resources at the pod level.
- Init containers that are not sidecars, and containers other tools inject.
- Jobs and CronJobs, and pods with no Deployment, StatefulSet or DaemonSet behind them.
- Resources a Vertical Pod Autoscaler writes.
- A resource whose
resizePolicyisRestartContainer. - A change that would take a JVM across 2 CPUs or 1,792 MiB, where its garbage collector changes at the next start, or past a LimitRange's bounds.
Those changes reach you as recommendations and pull requests instead.
Before every change, the component sends it to Kubernetes as a dry run, so the API server checks it against quotas, LimitRanges and the QoS rules. Then LevelFour approves it against the objects, the switches and the window again. Nothing changes without both. When LevelFour cannot be reached for five minutes, the component writes nothing, reverts included, until it can.
Stop and revert
Two ways stop it, from the cluster or from the dashboard:
- Pause.
stopAllAutomation: truein the cluster object, or Stop all automation on the Automation tab, refuses every new change within a minute. Pods keep the values they have. - Stop and revert.
cleanupAllAutomation: true, or Stop and revert, also puts every pod the component changed back on its workload's own spec, read from its ReplicaSet, StatefulSet or DaemonSet, and deletes the rightsized values.
An object lifts only the pause or stop it set itself: clearing its switch never undoes a stop a person made on the tab.
On Kubernetes 1.33 and 1.34, a memory limit cannot go back down on a running pod. With automation.revert.allowPodEviction: true the component evicts the pod, so it restarts at its original size. Without it, the pod keeps the larger limit until its next rollout. A revert finishes once every pod is back, left to its next rollout, or left alone, and the component retries a pod whose revert failed, such as an eviction a PodDisruptionBudget refused.
Auto-merge
Auto-merge is set per namespace on the Automation tab, one class at a time. A pull request merges on its own only when every change in it belongs to a class that namespace allows.
| Class | Value | What it covers |
|---|---|---|
| Reliability fixes | reliability_fix | More memory after OOM kills, or more CPU after throttling, on a resource no VPA manages |
| Small request cuts | small_request_decrease | Requests cut by 25% or less, with limits untouched, from at least 14 days of data. Guaranteed pods, workloads that an HPA scales on CPU utilization, and containers that regressed recently never qualify |
| Autoscaler targets | autoscaler_target | An HPA or KEDA utilization target changed together with its request, keeping the scaling point where it was |
Replica counts, idle workloads, NodePools, node groups and volume claims never merge on their own.
LevelFour merges a pull request only when GitHub reports it mergeable with every check on its last commit passed, the base branch requires at least one status check, and the maintenance window is open. Your branch protection still applies. A regression after a merge turns that class off for the namespace and opens the revert pull request. After you merge covers the checks.
Who can do what in the dashboard
| Action | Who |
|---|---|
| Turn automation on for the cluster or a namespace, change a setting no object sets, resume after a stop, allow an auto-merge class | Admins, signed in to the dashboard. API keys and AI assistants cannot |
| Stop, stop and revert, turn a namespace off | Admins and members |
| See the settings, the objects and every change | Everyone who can see the cluster |
The Automation tab lists every change, stop and setting change with its time, its namespace and workload, the values before and after, and who approved it, as a person in the dashboard or as declared in an object.
Permissions
The component has its own service account, separate from the agent's, and holds no permission to change Deployments, StatefulSets or any other workload.
| Part | Privilege | Why |
|---|---|---|
| Role in each allowed namespace | get, list, watch on pods; patch on pods/resize; get, list, watch on ReplicaSets, StatefulSets and DaemonSets; list on events | To see OOM kills, resize a running container, read the spec a revert restores, and find a workload that cannot create pods |
Same Role, with automation.revert.allowPodEviction | create on pods/eviction | To revert a memory limit on Kubernetes 1.33 and 1.34 |
| ClusterRole | get on the kube-system namespace; list on namespaces | The cluster's identity, and the namespaces labelled levelfour.ai/automation: "off" |
| Same ClusterRole | get, list, watch on the six configuration objects; patch on their status | To read the configuration and write each object's Ready condition |
Roles aggregated to admin and view | Write on the namespace and workload objects for admin; read on all six for view | So a namespace's own team manages its configuration |
| Role in the agent's namespace | create, get, list, watch, update, delete on ConfigMaps | To write the rightsized values |
| Webhook Role in the agent's namespace | get, list, watch on ConfigMaps | To read those values |
| Webhook Role in each allowed namespace | list, watch on LimitRanges | To keep a changed pod within its namespace's LimitRanges |
MutatingWebhookConfiguration, with automation.webhook.enabled | Pod creation in the allowed namespaces | To give new pods the rightsized values |
With automation.allowedNamespaces: ["*"], the pod rules and the webhook's LimitRange rule come in ClusterRoles instead. The component talks to api.levelfour.ai on port 443, like the agent, with the same token. The webhook never calls LevelFour or the API server while it admits a pod, and with failurePolicy: Ignore and a 2-second timeout, a pod it cannot answer for starts as its manifest says.
Remove it
Set automation.enabled: false and upgrade the chart, or uninstall it. Either way removes the component, its permissions and the rightsized values.
The configuration objects and their definitions stay, so an uninstall never deletes a team's configuration. To remove them too:
kubectl delete crd -l app.kubernetes.io/part-of=levelfour-k8sNode optimization
The pods that keep your nodes running, a review of each NodePool, Spot interruptions, the cheapest node set your pods fit on, how each pool buys capacity, and the node and volume claim changes LevelFour recommends.
Configure the agent
Chart values for the LevelFour agent, and how to read Prometheus history, publish cost metrics, measure network by destination, send through a proxy, pull from a private registry and verify the release signatures.