KubeCon EUBooth 1151, Amsterdam. March 23-26
Terraform

Workload Policies

Configure workload rightsizing policies and attach them to clusters with Terraform.

Workload Policies

devzero_workload_policy defines how workloads should be rightsized -- CPU and memory vertical scaling, horizontal scaling, and the triggers that activate them. devzero_workload_policy_target attaches a policy to one or more clusters with optional namespace, kind, and workload filters.

WorkloadPolicy

Example

resource "devzero_workload_policy" "cost_saving" {
  name        = "cost-saving-policy"
  description = "Aggressively rightsize non-critical workloads"

  action_triggers    = ["on_detection"]
  detection_triggers = ["pod_creation", "pod_update"]

  cpu_vertical_scaling {
    enabled                  = true
    target_percentile        = 0.95
    min_request              = 50
    max_request              = 4000
    overhead_multiplier      = 1.1
    limits_adjustment_enabled = true
  }

  memory_vertical_scaling {
    enabled                  = true
    target_percentile        = 0.95
    min_request              = 64
    max_request              = 8192
    overhead_multiplier      = 1.15
    limits_adjustment_enabled = true
  }
}

Arguments

ParameterTypeRequiredDescription
namestringYesUnique name for the policy
descriptionstringNoHuman-readable description
action_triggerslist(string)NoWhen to act: "on_detection", "on_schedule"
cron_schedulestringNo5-field cron expression (used with "on_schedule" trigger)
detection_triggerslist(string)NoWhat triggers detection: "pod_creation", "pod_update"
loopback_period_secondsnumberNoHistorical data window in seconds
startup_period_secondsnumberNoGrace period after pod starts before scaling
cooldown_minutesnumberNoMinimum wait time between scaling applications
live_migration_enabledboolNoEnable live migration of workloads
scheduler_pluginslist(string)NoScheduler plugins to use (e.g. ["dz-scheduler"])
defragmentation_schedulestringNoCron expression for background optimization
min_change_percentnumberNoMinimum resource change to trigger scaling
drift_delta_percentnumberNoAllowed drift before re-evaluation
stability_cv_maxnumberNoMaximum coefficient of variation for stability
cpu_vertical_scalingblockNoCPU vertical scaling configuration (see below)
memory_vertical_scalingblockNoMemory vertical scaling configuration (see below)
gpu_vertical_scalingblockNoGPU vertical scaling configuration (see below)
gpu_vram_vertical_scalingblockNoGPU VRAM vertical scaling configuration (see below)
horizontal_scalingblockNoHorizontal scaling configuration (see below)

Vertical Scaling Block

Used by cpu_vertical_scaling, memory_vertical_scaling, gpu_vertical_scaling, and gpu_vram_vertical_scaling.

ParameterTypeRequiredDescription
enabledboolYesWhether vertical scaling is active
target_percentilefloatNoUsage percentile to target (e.g. 0.95)
min_requestnumberNoMinimum request value (millicores for CPU, MiB for memory)
max_requestnumberNoMaximum request value
overhead_multiplierfloatNoSafety margin multiplier applied to recommendations
limits_adjustment_enabledboolNoWhether to adjust limits alongside requests

Horizontal Scaling Block

ParameterTypeRequiredDescription
enabledboolYesWhether horizontal scaling is active
min_replicasnumberNoMinimum number of replicas
max_replicasnumberNoMaximum number of replicas
overhead_multiplierfloatNoSafety margin multiplier applied to recommendations
limits_adjustment_enabledboolNoWhether to adjust limits alongside requests

WorkloadPolicyTarget

devzero_workload_policy_target attaches a devzero_workload_policy to one or more clusters. You can optionally filter by workload kind, namespace, and name patterns.

Example

resource "devzero_workload_policy_target" "production" {
  name        = "production-target"
  policy_id   = devzero_workload_policy.cost_saving.id
  cluster_ids = [devzero_cluster.production.id]

  kind_filter      = ["Deployment", "StatefulSet"]
  enabled          = true
}

Arguments

ParameterTypeRequiredDescription
namestringYesUnique name for the target
policy_idstringYesID of the devzero_workload_policy to attach
cluster_idslist(string)YesList of cluster IDs to apply the policy to
descriptionstringNoHuman-readable description
enabledboolNoWhether the target is active (default: true)
prioritynumberNoPriority when multiple targets match a workload
workload_nameslist(string)NoSpecific workload names to match
node_group_nameslist(string)NoNode groups to scope the policy to
kind_filterlist(string)NoWorkload kinds to include (see below)
name_patternblockNoRegex-based name matching (pattern, flags)
namespace_selectorblockNoLabel selector for namespaces (match_labels, match_expressions)
workload_selectorblockNoLabel selector for workloads (match_labels, match_expressions)

Supported kind filter values: Pod, Deployment, StatefulSet, DaemonSet, Job, CronJob, ReplicaSet, ReplicationController, Rollout

name_pattern Block

ParameterTypeDescription
patternstringRegular expression to match workload names
flagsstringRegex flags: "i" (case-insensitive), "m" (multiline)

namespace_selector / workload_selector Block

ParameterTypeDescription
match_labelsmap(string)Key-value pairs that must all match
match_expressionslist(block)Label selector expressions (key, operator, values)

On this page