In both cases, the scaling settings are on the agent in KAOP, not in git (see Set the scaling in
KAOP). Koperator sets the replica count of the Deployment from the queue
of the agent:
- When the agent is idle, it can go to 0 replicas.
- When a run arrives for an agent at 0, koperator usually wakes it in about one second. If that fast wake is not available, koperator wakes the agent at its next poll. The first run then waits until the pod is ready.
- When more runs wait, koperator adds replicas, up to the maximum that you set.
- When the queue is empty, koperator removes replicas after a cooldown.
spec.replicas and one annotation on that Deployment. It does not change the pod template, so it
does not restart pods.
How it works for an agent that you deploy
When your own tool deploys the agent, the Deployment and the agent must both opt in. If only one of them opts in, nothing scales.- Koperator finds each Deployment that opts in, in the namespaces that it scales. It reports each one to KAOP at least one time each minute.
- KAOP binds the agent to the management cluster that reports it. One management cluster scales an agent. If another management cluster already scales the agent, KAOP does not change the binding.
- Koperator reads the queue and the scaling settings of each bound agent from KAOP. It then sets the replica count through the scale subresource of the Deployment.
Before you start
You need:- A management cluster. This is a cluster where koperator is installed and connected to KAOP. The Deployment must be in a namespace that koperator scales.
- A self-hosted agent in KAOP. Copy its Agent ID from the agent page. KAOP must not also deploy the agent to a management cluster: an agent that KAOP deploys is scaled by KAOP already.
- No other scaler on the Deployment. Remove each HorizontalPodAutoscaler or KEDA ScaledObject that targets it.
Install koperator for scaling only
If koperator is already on the cluster and its namespaces include the namespace of the Deployment, you can use that install. Go to Do you need an ignore rule?. To scale agents and deploy nothing, install koperator with only the autoscaling module on:1
Create a management cluster
In KAOP, create a management cluster. Keep the install key: KAOP shows it one time.
2
Create the Secret for the install key
3
Install the chart
Set The page of the management cluster also shows the install command. Add the two
namespaces to the namespaces of your agent Deployments:modules values
to it.autoscaler.mode is. It claims no
namespace, so it can run in the same namespaces as another koperator install. helm uninstall does
not change the replica counts.
Permissions of a scaling-only install
In each namespace innamespaces, the chart gives koperator only these permissions:
Koperator also gets a Role for leader election in its own namespace. Its only cluster-wide
permissions are read-only and limited by name: the two KEDA CRDs and the
kube-system namespace. It
gets no access to Secrets, ConfigMaps, Services, ServiceAccounts, Pods or Events in the scaled
namespaces. It cannot create or delete an object. With namespaces: ["*"], the chart gives the same
permissions in one ClusterRole.
Koperator connects out to KAOP over HTTPS. Nothing connects in to your cluster.
Do you need an ignore rule?
The ignore rule in your deploy tool is optional. You need it only when your tool applies areplicas value to the Deployment. With the recommended installation, the KAOP agent chart with
autoscaling.native.enabled: true, you do not need it.
We tested Argo CD with no ignore rule only with server-side apply (
ServerSideApply=true). If your
Application uses client-side apply, add the rule.
After the change that removes replicas, the rule is only a safety net: if a later chart change
renders replicas again, the rule stops a reset. You can keep it or remove it.
Do the steps in this order
If you do step 1, let it sync before you do step 2. You can do step 2 and step 3 in the same change.
If you deploy the KAOP agent chart, one chart value does step 2 and step 3 (see If you deploy the
KAOP agent chart).
Step 1: tell your deploy tool to ignore spec.replicas
Do this step only if your chart rendersreplicas now. See Do you need an ignore
rule?.
Argo CD Application
Add the ignore rule and the sync optionRespectIgnoreDifferences=true:
ignoreDifferencesalone stops self-heal. But a sync from a git change still resetsreplicas. You must also setRespectIgnoreDifferences=true.- The rule works with server-side apply on or off.
- Use
jsonPointers. Do not usemanagedFieldsManagers: when your chart does not renderreplicas, the scale writes of koperator do not show as a field manager. - The
autoscaler-stateannotation does not need an ignore rule.
Argo CD ApplicationSet
Use atemplatePatch. It needs goTemplate: true. Put the full syncOptions list in the patch:
autoscaling: false keeps its rendered replicas, and self-heal keeps that count.
With missingkey=error, each generator element must set autoscaling to true or false. If one
element does not set it, the ApplicationSet does not render any of its elements.
Flux HelmRelease
Tell drift detection to ignore/spec/replicas:
replicas. So you must
also do step 3. Flux upgrades with Helm, so read Plain Helm or kubectl
too.
Plain Helm or kubectl
There is no ignore rule to set. A Helm upgrade, and a client-sidekubectl apply, overwrite a
replicas that the chart or the manifest contains. They do not change a field that they never
applied. So you must do step 3. Until you do it, koperator and each upgrade change the replica count
in turn.
The upgrade that removes replicas can set each agent to 1 replica one time. Helm deletes a field
that it applied before, and Kubernetes then sets the default, 1. Koperator can see this as another
writer. It then waits up to 10 minutes before it scales the agent again. To decrease the effect, do
step 3 when the agents are idle.
Step 2: label the Deployment
Add the two labels to the metadata of the Deployment. Do not add them to the pod template:AGENTOPS_AGENT_ID, it must have the same value as the
label. If it does not, koperator does not scale the Deployment.
If you do step 1 with Argo CD, the ignore rule is on the Application and the labels are on the
Deployment. One commit does not make sure that Argo CD applies the rule first. So make sure that
step 1 has synced before you push the labels.
Step 3: remove replicas from your chart
Renderreplicas only when autoscaling is off. For example, in a Helm template:
autoscaling.enabled is an example. Use the value that your chart has for this.
In a plain manifest, remove the replicas line.
If you deploy the KAOP agent chart
The KAOP agent chart (oci://ghcr.io/komodorio/charts/agentops-agent-base, version 0.1.8 or later)
does step 2 and step 3 for you. Set this value:
- The chart adds the label
agentops.komodor.io/autoscale: "true"to the Deployment, not to the pod template. It always sets theagentops.komodor.io/agent-idlabel. - The chart does not render
replicas, soreplicaCounthas no effect. - The chart does not render a KEDA ScaledObject. The chart fails if
autoscaling.keda.enabledis alsotrue.
replicas. For an agent that is already deployed, the upgrade that sets the value removes
replicas. With Argo CD, do step 1 first. With Helm, Flux or kubectl, do the upgrade when the agent
is idle.
Rollout results
When Argo CD creates a new Deployment, it does not use the ignore rule. The new agent starts at the
rendered count, or at 1 when the chart has no
replicas. A Scale to zero agent then goes to 0
after its cooldown.
To stop autoscaling, remove the agentops.komodor.io/autoscale label. Koperator stops, and the
replica count stays as it is.
Set the scaling in KAOP
The scaling settings are on the agent in KAOP, not in git, whoever deploys the agent. Set them in the run settings of the agent:- Run behaviour. Scale to zero: no replica runs while the agent is idle. Always on: at least one replica always runs. To scale an Always on agent, turn on its autoscaling.
- Max replicas. Koperator never sets more replicas than this.
- Queue depth per replica. The number of waiting runs for each replica. Koperator sets the replicas to the waiting runs divided by this number, rounded up, between the minimum and the maximum.
- Min replicas. For an Always on agent with autoscaling, the replicas that always run. A Scale to zero agent has a minimum of 0.
Check that it works
On the agent page. The Overview tab shows a Scaling card. It shows the state (Bound, Not scaled or Released) and a line such as “Deployed by Argo CD, scaled by the Komodor operator on<management cluster>”. It also shows the management cluster, the Deployment
(namespace/name), how KAOP bound the agent, and when.
The card has two buttons:
- Move. Bind the agent to another management cluster. That management cluster must report an opted-in Deployment for the agent. You need permission to update the agent and to deploy to that management cluster.
- Release. Remove the binding. After a release, no koperator scales the agent, and a new report does not bind it again. To scale it again, use Move. You need permission to update the agent.
In your deploy tool. Argo CD shows the Application as
Synced and Healthy, also at 0 replicas.
In the cluster. This command shows the state that koperator writes:
GET /api/v1/agents/<agent ID> returns the binding in scaled_by: state, the
management cluster, namespace, object_name, deployed_by (argocd, flux, helm or
unknown), and reason_code with message when koperator does not scale the agent.
Why an agent does not scale
When koperator does not scale an opted-in Deployment, it reports a reason code. The Scaling card on the agent page shows the reason code, a message and the fix.
Koperator also does not scale a Deployment that KAOP deployed. KAOP scales that agent on its own
path.
If the agent has no binding and no reason code, examine these items:
- Autoscaling is off on the agent in KAOP.
- KAOP deploys the agent to a management cluster.
- A person released the binding. Use Move to bind it again.
Waking from zero needs koperator
When no koperator replica can connect to KAOP, a bound agent does not wake or scale. Pods that run keep their count. A run that waits for an agent at 0 fails withcold_start_timeout at the end of
its hold timeout.
Security
A person who can label a Deployment in a namespace that koperator scales can bind a free, opted-in agent. That koperator can then read the queue counts and the run settings of the agent. It cannot read the runs or the secrets of the agent. The Scaling card on the agent page shows the binding. KAOP writes each bind, move, release and end to the audit log. A user with permission to update the agent can release the binding.Next steps
Argo CD and Flux
Install and upgrade koperator itself with Argo CD or Flux.
Scale agents to zero
Choose between Scale to zero and Always on.