Skip to Content

Policies

Each ScaleOps product reads its own policy kind, so a policy written for one product cannot be attached to another. The kinds share an API group but not a schema: history windows, resource keys and update settings differ between them. Define a policy as a custom resource, commit it with the rest of your manifests, and attach it to workloads or namespaces by name.

Policy Kinds

ProductKindAttach with annotationYAML reference
Workload RightsizingPolicyscaleops.sh/default-rightsize-policyWorkload Rightsizing Policy
Replicas OptimizationHpaPolicyscaleops.sh/default-replicas-policyHpaPolicy YAML Reference
Replicas DownscaleDownscalerPolicyscaleops.sh/default-downscaler-scheduleDownscalerPolicy YAML Reference
Spot OptimizationSpotPolicyscaleops.sh/default-spot-policySpotPolicy YAML Reference
Automated Fractional GPUsGpuPolicyscaleops.sh/default-gpu-policyGpuPolicy YAML Reference
GPU Memory OptimizationGpuMemoryPolicyscaleops.sh/default-gpu-memory-policyGpuMemoryPolicy YAML Reference
Pod SchedulingPodSchedulingPolicyscaleops.sh/default-pod-scheduling-policyPolicies and configuration

Each kind also has a force- annotation and an AutomatedNamespace field. See Workload Actions and Namespace Actions.

Rules for Every Policy Kind

  • Namespace: Create the policy in the namespace ScaleOps is installed in (scaleops-system by default). ScaleOps ignores policies in any other namespace.
  • API version: Every kind uses apiVersion: analysis.scaleops.sh/v1alpha1.
  • Name: The annotation or AutomatedNamespace field refers to the policy by metadata.name.
  • Omitted fields: A field you leave out takes the product default. Set only the fields you want to change.
  • Helm: customPolicies creates Policy resources and customHpaPolicies creates HpaPolicy resources from your values file. Apply the other kinds as plain manifests.
⚠️

Do not manage built-in policies (labeled scaleops.sh/builtin-policy: "true") in Git. ScaleOps resets them, so your changes do not persist. Copy a built-in policy under a new name and edit the copy.

Workload Rightsizing Policy

Example:

apiVersion: analysis.scaleops.sh/v1alpha1 kind: Policy metadata: name: your-policy # name of the policy namespace: scaleops-system spec: type: Optimize policyOptimize: rightSizePolicy: ephemeralStorageOptimizationEnabled: true # Enable ephemeral storage optimization bootTimeOptimizationEnabled: true # Enable boot-time CPU optimization for workloads with startup spikes windowByResource: cpu: 24h # History window to maintain for CPU data samples memory: 24h # History window to maintain for Memory data samples ephemeral-storage: 48h requestsConfigs: cpu: headroomPercentage: 5 # The percent of headroom to add to the recommendation percentilePercentage: 85 # The percentile of the usage to base the recommendation on memory: headroomPercentage: 5 # The percent of headroom to add to the recommendation percentilePercentage: 90 # The percentile of the usage to base the recommendation on ephemeral-storage: headroomPercentage: 5 percentilePercentage: 90 limitConfigs: cpu: keepLimit: true memory: keepLimit: true ephemeral-storage: keepLimit: true autoHealing: enabledByResource: ephemeral-storage: true # Currently supports only ephemeral storage, CPU and memory is not supported yet by this field updatePolicy: updateByTypeMode: daemonSet: OnCreate # Update strategy for DaemonSets, allowed values are OnCreate or Ongoing deployment: Ongoing # Update strategy for Deployments, allowed values are OnCreate or Ongoing job: OnCreate # Update strategy for Jobs, allowed values are OnCreate or Ongoing statefulSet: OnCreate # Update strategy for StatefulSets, allowed values are OnCreate or Ongoing

Policy Structure

Top-Level Fields

FieldTypeDescription
spec.typestringPolicy type. Use Optimize for workload rightsizing.
spec.policyOptimizeobjectRequest/limit calculation and burst reaction settings.
spec.updatePolicyobjectHow and when ScaleOps applies optimizations (rollout strategy, schedules).
spec.autoHealingobjectAuto-healing for CPU stress, OOM, and disk evictions.
spec.policyScheduleobjectOptional schedule-based policy switching.
spec.autoDetectionRulesobjectRules for auto-detecting workloads.

Right-Size Policy

Under spec.policyOptimize.rightSizePolicy, configure how requests and limits are calculated per resource. Supported resource keys are cpu, memory, and ephemeral-storage.

windowByResource

History window (duration) used for recommendations per resource. Examples: 24h, 48h, 168h (7 days). On versions earlier than v1.35.6, use h (hours) or m (minutes).

Available in v1.35.6+ d, w, and y (for example 1d, 7d, or 1w) are also accepted (a day is 24 hours, a week is 7 days, and a year is 365 days).

KeyDescription
cpuHistory window for CPU recommendations.
memoryHistory window for memory recommendations.
ephemeral-storageHistory window for ephemeral storage (requires ephemeral storage optimization enabled).
requestsConfigs

Per-resource request calculation settings.

FieldTypeDescription
headroomPercentageintegerExtra buffer percentage added on top of the recommendation (e.g., 5).
percentilePercentageintegerPercentile of usage histogram used for the recommendation (e.g., 90).
minAllowedstring (quantity)Minimum allowed request (e.g., "10m" for CPU, "20Mi" for memory, "10Mi" for ephemeral storage).
maxAllowedstring (quantity)Maximum allowed request. Use "0" or empty for no maximum.
keepRequestbooleanIf true, preserve the workload’s original request for this resource.
limitConfigs

Under spec.policyOptimize.rightSizePolicy.limitConfigs.<cpu | memory | ephemeral-storage>:

Per-resource limit strategy.

FieldTypeDescription
keepLimitbooleanPreserve the workload’s original limit.
noLimitbooleanRemove the limit (no cap).
setLimitstring (quantity)Set a fixed limit.
keepLimitRequestRatiobooleanMaintain original limit/request ratio.
setLimitRequestRatiofloatSet limit as a multiplier of the recommendation (e.g., 2).
minLimitstring (quantity)Optional. Minimum hard bound for the limit (e.g., "1Gi"). Applies only with keepLimitRequestRatio or setLimitRequestRatio. The limit will never be set below this value.
maxLimitstring (quantity)Optional. Maximum hard bound for the limit (e.g., "10Gi"). Applies only with keepLimitRequestRatio or setLimitRequestRatio. The limit will never exceed this value.
maxRecommendedLimitToOriginalLimitRatiofloatOptional. Caps the limit as a multiple of the original limit (e.g., 3 means the limit will not exceed 3× the original). Applies only with keepLimitRequestRatio or setLimitRequestRatio. If both maxLimit and maxRecommendedLimitToOriginalLimitRatio are set, the smaller effective value is used.
Other Right-Size Fields
FieldTypeDescription
ephemeralStorageOptimizationEnabledbooleanEnable ephemeral storage optimization. Default: true.
bootTimeOptimizationEnabledbooleanEnable boot-time CPU optimization. Accounts for startup CPU spikes, reacts to startup CPU stress, and adds Karpenter node affinity guidance. Enabled by default in all built-in policies. See Boot-Time Optimization.
nodeCappingPolicy.nodeCappingAutobooleanCap recommendations by node allocatable.
cpuIntegerbooleanRound CPU requests to integers.
initContainers.enabledbooleanEnable init container optimization.

Auto-Healing

Under spec.autoHealing:

FieldTypeDescription
enabledV2booleanMaster toggle for auto-healing.
enabledByResourcemapPer-resource auto-healing. Keys: cpu, memory, ephemeral-storage.

Update Policy

Under spec.updatePolicy:

FieldTypeDescription
updateByTypeModeobjectRollout strategy per workload type. Keys: deployment, statefulSet, daemonSet, job, deploymentConfig, argoRollout. Values: Ongoing or OnCreate.
minReplicasintegerMinimum replicas to ensure during optimization.
evictionScheduleobjectCron expressions for when to allow evictions (scaleDown, scaleUp).
podMinReadySecondsintegerBuffer for pods to become ready.
requiredWindowCoveragePercentageintegerRequired data coverage before applying changes.
binPackUnEvictablePodsbooleanBin-pack unevictable pods for better consolidation.

Resource Keys Summary

Use these keys in windowByResource, requestsConfigs, and limitConfigs:

KeyResource
cpuCPU requests and limits
memoryMemory requests and limits
ephemeral-storageEphemeral storage (disk). Requires ephemeralStorageOptimizationEnabled: true.

For ephemeral storage auto-healing (disk evictions), set spec.autoHealing.enabledByResource["ephemeral-storage"]: true. See Ephemeral Storage for more details.