Description
An HPA using a type: Object metric needs valid describedObject, metric and target information. The measured object has a different role from scaleTargetRef, which identifies the workload whose replica count changes. Incomplete references or a metric adapter that does not provide the value can prevent autoscaling from working as intended.
Potential impact
- Replicas may not increase when rising load requires them.
- An unsuitable target value can cause excessive scaling or inadequate response to load.
Remediation
- Match the Object metric’s describedObject name, kind and API version, metric name, and target type and value to actual resources. Specify the workload’s scaleTargetRef separately and accurately.
- Check the metric adapter, units and minimum/maximum replicas, then verify HPA conditions, events and actual scaling under load.
Examples
The referenced Deployment, Ingress and an adapter providing requests-per-second must exist separately. The 10k target and 1–10 replicas are illustrative; adjust them to actual load.
Before
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: php-apache
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: php-apache
minReplicas: 1
maxReplicas: 10
metrics:
- type: Object
object:
metric:
name: requests-per-second
target:
type: Value
value: 10k
describedObject:
apiVersion: networking.k8s.io/v1
kind: Ingress
The measured Ingress lacks a name, leaving the reference incomplete.
After
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: php-apache
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: php-apache
minReplicas: 1
maxReplicas: 10
metrics:
- type: Object
object:
metric:
name: requests-per-second
describedObject:
apiVersion: networking.k8s.io/v1
kind: Ingress
name: main-route
target:
type: Value
value: 10k
main-route is the measured object. The workload being scaled is the separate php-apache Deployment in scaleTargetRef.