Description
An HPA Object metric requires a correctly configured described_object, metric name and target value. The measured object serves a different purpose from scale_target_ref, which identifies the workload whose replica count changes. Other metric types, such as Resource and Pods, are also valid when appropriate.
Even an existing referenced object is not enough if the metrics adapter does not supply the required value. Verify both collection and scaling status.
Potential impact
- Incorrect references or unavailable metrics can prevent required scaling.
- Unsuitable target values can cause excessive scaling or failure to handle load.
Remediation
- Match the Object metric’s described_object name, kind and API version, metric name, and target type and value to actual resources. Separately set scale_target_ref to the correct workload.
- Check the metrics adapter, units and replica bounds. Test HPA conditions, events and actual scaling under load.
Examples
These partial examples use older HPA and Ingress formats. Use kubernetes_horizontal_pod_autoscaler_v2 and a supported Ingress API in current environments. Required scale_target_ref and the workload, Ingress and metrics adapter are omitted. The 50–100 replicas and latency target of 100 are illustrative.
Before
resource "kubernetes_horizontal_pod_autoscaler" "example" {
metadata {
name = "test"
}
spec {
min_replicas = 50
max_replicas = 100
metric {
type = "Object"
object {
target {
type = "Value"
value = "100"
}
}
}
}
}
After
resource "kubernetes_horizontal_pod_autoscaler" "example" {
metadata {
name = "test"
}
spec {
min_replicas = 50
max_replicas = 100
metric {
type = "Object"
object {
metric {
name = "latency"
}
described_object {
name = "main-route"
api_version = "networking.k8s.io/v1beta1"
kind = "Ingress"
}
target {
type = "Value"
value = "100"
}
}
}
}
}
Explanation:
- Before: The Object metric name and measured-object reference are missing.
- After: The measured Ingress and latency metric are specified. Actual collection and a separate scale target are still required.