Warning
You are currently viewing v2.20 of the documentation and it is not the latest. For the most recent documentation, kindly click here.
Kubernetes Resource
Scale applications based on values in Kubernetes ConfigMaps or Secrets
This specification describes the kubernetes-resource trigger that scales based on a value found in a Kubernetes ConfigMap or Secret.
This scaler allows users to scale workloads by extracting values from Kubernetes resources, supporting number, JSON, and YAML formats.
Here is an example of trigger configuration using kubernetes-resource scaler:
triggers:
- type: kubernetes-resource
metadata:
resourceKind: "Secret"
resourceName: "my-secret"
key: "data"
format: "json"
valueLocation: "count"
valueType: "float64"
targetValue: "10"
activationTargetValue: "5"
Parameter list:
resourceKind - Type of Kubernetes resource to read from. Supported values: ConfigMap, Secret (Required)resourceName - Name of the resource to read. (Required)key - Key in the ConfigMap’s data field or Secret’s data field to read from. The value at this key is retrieved as a string. (Required)format - Format of the string value retrieved from key. Supported values: number, json, yaml. (Default: number, Optional)
number - The string value is parsed directly as a numberjson - The string value is a JSON document, and valueLocation extracts a field from ityaml - The string value is a YAML document, and valueLocation extracts a field from itvalueLocation - Path to extract the metric value from the JSON or YAML content retrieved from key. Required for json and yaml formats. Not used for number format. For json, use GJSON path notation. For yaml, use dot-separated path (e.g., foo.bar.count). (Optional)valueType - Type of value to extract. Supported values: float64, int64, quantity. (Default: float64, Optional)
float64 - Floating point number. For JSON format, accepts both numbers and quantity strings.int64 - Integer number. For JSON format, only accepts integer numbers (decimal values are truncated). For number format, the string must be parseable as an integer.quantity - Kubernetes quantity (e.g., “100m”, “1Gi”). For JSON/YAML formats, parses string values as quantities. For JSON format, also accepts raw numbers.targetValue - Target value to scale on. When the extracted value is equal or higher, KEDA will scale out. (Required)activationTargetValue - Value for activating the scaler. Learn more about activation here. (Default: 0, Optional)No authentication parameters are required. The scaler uses the permissions of the KEDA operator to access resources in the same namespace.
Here is a full example of scaled object definition using Kubernetes Resource trigger:
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: k8s-resource-scaledobject
namespace: keda
spec:
maxReplicaCount: 10
scaleTargetRef:
name: dummy
triggers:
- type: kubernetes-resource
metadata:
resourceKind: "ConfigMap"
resourceName: "my-configmap"
key: "metrics"
format: "yaml"
valueLocation: "count"
valueType: "int64"
targetValue: "10"
Assuming the ConfigMap contains:
apiVersion: v1
kind: ConfigMap
metadata:
name: my-configmap
namespace: keda
data:
metrics: |
count: 12
other: value
The scaler will extract the value at count from the YAML data in the metrics key and use it for scaling decisions.
💡 NOTE:
- The
valueTypeparameter controls how values are parsed. Forint64, decimal values in JSON are truncated to integers.- For
jsonformat, use GJSON path syntax. Foryamlformat, use dot-separated path. Fornumberformat, the value at the key is used directly.- For YAML format, the
valueTypedetermines how the extracted value is converted, regardless of whether the value is a string or a native YAML number. For example, ifvalueTypeis set toint64, the value will be converted to an integer; if set toquantity, it will be parsed as a Kubernetes quantity. By default, numeric YAML values are converted to float64 unless a differentvalueTypeis specified.
apiVersion: v1
kind: ConfigMap
metadata:
name: task-count
namespace: keda
data:
count: "42"
---
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: task-scaler
namespace: keda
spec:
scaleTargetRef:
name: worker-deployment
triggers:
- type: kubernetes-resource
metadata:
resourceKind: "ConfigMap"
resourceName: "task-count"
key: "count"
format: "number"
valueType: "float64"
targetValue: "50"
activationTargetValue: "10"
In this example, the value 42 from the count key is used directly.
apiVersion: v1
kind: Secret
metadata:
name: metrics-data
namespace: keda
stringData:
metrics: |
{
"queue": {
"pending": 25,
"processing": 5
}
}
---
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: queue-scaler
namespace: keda
spec:
scaleTargetRef:
name: processor-deployment
triggers:
- type: kubernetes-resource
metadata:
resourceKind: "Secret"
resourceName: "metrics-data"
key: "metrics"
format: "json"
valueLocation: "queue.pending"
valueType: "int64"
targetValue: "20"
In this example, the GJSON path queue.pending extracts the value 25 from the JSON data.
apiVersion: v1
kind: ConfigMap
metadata:
name: app-metrics
namespace: keda
data:
stats: |
application:
workers:
active: 15
idle: 3
---
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: worker-scaler
namespace: keda
spec:
scaleTargetRef:
name: worker-deployment
triggers:
- type: kubernetes-resource
metadata:
resourceKind: "ConfigMap"
resourceName: "app-metrics"
key: "stats"
format: "yaml"
valueLocation: "application.workers.active"
valueType: "int64"
targetValue: "10"
In this example, the dot-separated path application.workers.active extracts the value 15 from the YAML data.
apiVersion: v1
kind: ConfigMap
metadata:
name: resource-limits
namespace: keda
data:
memory: |
{
"available": "2Gi",
"used": "512Mi"
}
---
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: memory-scaler
namespace: keda
spec:
scaleTargetRef:
name: worker-deployment
triggers:
- type: kubernetes-resource
metadata:
resourceKind: "ConfigMap"
resourceName: "resource-limits"
key: "memory"
format: "json"
valueLocation: "used"
valueType: "quantity"
targetValue: "1024000000" # 1Gi in bytes
In this example, the quantity string "512Mi" is parsed and converted to its float64 representation for scaling decisions.
⚠️ Important: When using
valueType: "int64"with JSON format, decimal values will be truncated. For example, if the JSON contains{"count": 25.7}, it will be treated as25.
The scaler works in two steps:
ConfigMap.data[key] or Secret.data[key]format:
valueLocation is needed.
key="count" and ConfigMap.data.count = "42", the metric value is 42valueLocation (using GJSON syntax) extracts the metric value.
key="metrics" and ConfigMap.data.metrics = '{"tasks": 10}', with valueLocation="tasks", the metric value is 10valueLocation (using dot-separated path) extracts the metric value.
key="stats" and ConfigMap.data.stats = 'count: 15', with valueLocation="count", the metric value is 15