KEDA (Kubernetes Event-Driven Autoscaling) Cheatsheet¶
Instalación¶
| Platform/Method | Command |
|---|---|
| Helm (Recommended) | INLINE_CODE_12 |
| YAML Manifest | INLINE_CODE_13 |
| Specific Version | INLINE_CODE_14 |
| macOS (Prerequisites) | INLINE_CODE_15 |
| Windows (Prerequisites) | INLINE_CODE_16 |
| OpenShift OperatorHub | Navigate to: Operators → OperatorHub → Search "KEDA" |
| Upgrade Existing | INLINE_CODE_17 |
| Uninstall | INLINE_CODE_18 |
Comandos de verificación¶
| Command | Description |
|---|---|
| INLINE_CODE_19 | Check KEDA components are running |
| INLINE_CODE_20 | Verify KEDA CRDs are installed |
| INLINE_CODE_21 | Check KEDA operator deployment |
| INLINE_CODE_22 | Verify metrics API service |
Comandos básicos¶
Scaled Gestión de objetos¶
| Command | Description |
|---|---|
| INLINE_CODE_23 | List all ScaledObjects in current namespace |
| INLINE_CODE_24 | List ScaledObjects (short form) |
| INLINE_CODE_25 | List ScaledObjects across all namespaces |
| INLINE_CODE_26 | List ScaledObjects in specific namespace |
| INLINE_CODE_27 | Show detailed information about a ScaledObject |
| INLINE_CODE_28 | View ScaledObject YAML configuration |
| INLINE_CODE_29 | Watch ScaledObject status changes in real-time |
| INLINE_CODE_30 | Delete a ScaledObject |
| INLINE_CODE_31 | Edit ScaledObject configuration |
| INLINE_CODE_32 | Create/update ScaledObject from file |
Scaled Gestión de empleo¶
| Command | Description |
|---|---|
| INLINE_CODE_33 | List all ScaledJobs in current namespace |
| INLINE_CODE_34 | List ScaledJobs (short form) |
| INLINE_CODE_35 | List ScaledJobs across all namespaces |
| INLINE_CODE_36 | Show detailed information about a ScaledJob |
| INLINE_CODE_37 | View ScaledJob YAML configuration |
| INLINE_CODE_38 | Delete a ScaledJob |
| INLINE_CODE_39 | View Jobs created by ScaledJob |
| INLINE_CODE_40 | View logs from ScaledJob-created Job |
Authentication Management¶
| Command | Description |
|---|---|
| INLINE_CODE_41 | List TriggerAuthentications |
| INLINE_CODE_42 | List TriggerAuthentications (short form) |
| INLINE_CODE_43 | Show TriggerAuthentication details |
| INLINE_CODE_44 | List ClusterTriggerAuthentications |
| INLINE_CODE_45 | List ClusterTriggerAuthentications (short form) |
| INLINE_CODE_46 | Delete a TriggerAuthentication |
| INLINE_CODE_47 | Create secret for TriggerAuthentication |
Monitoring and Status¶
__TABLE_113_
Advanced Usage¶
Advanced Scaled Operaciones de objetos¶
__TABLE_114_
KEDA Operator Management¶
| Command | Description |
|---|---|
| INLINE_CODE_62 | Scale KEDA operator for HA |
| INLINE_CODE_63 | Restart KEDA operator |
| INLINE_CODE_64 | Check operator rollout status |
| INLINE_CODE_65 | View KEDA component details |
| INLINE_CODE_66 | View available Helm configuration options |
| INLINE_CODE_67 | View current Helm installation values |
| INLINE_CODE_68 | Update KEDA configuration |
Metrics and Debugging¶
| Command | Description |
|---|---|
| INLINE_CODE_69 | Query external metrics API |
| INLINE_CODE_70 | Query specific external metric |
| INLINE_CODE_71 | Check metrics API service status |
| INLINE_CODE_72 | View recent operator logs |
| INLINE_CODE_73 | View recent metrics server logs |
| INLINE_CODE_74 | View KEDA namespace events |
| INLINE_CODE_75 | View all KEDA-managed HPAs |
Multi-Trigger and Complex Scenarios¶
| Command | Description |
|---|---|
| INLINE_CODE_76 | List all trigger types for a ScaledObject |
| INLINE_CODE_77 | Check health status of triggers |
| INLINE_CODE_78 | View last active time |
| INLINE_CODE_79 | View current replica count |
| INLINE_CODE_80 | View desired replica count |
Configuración¶
Escalada básica Configuración de objetos¶
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: my-scaledobject
namespace: default
spec:
scaleTargetRef:
name: my-deployment # Target deployment name
minReplicaCount: 0 # Minimum replicas (0 for scale-to-zero)
maxReplicaCount: 10 # Maximum replicas
pollingInterval: 30 # Seconds between metric checks
cooldownPeriod: 300 # Seconds to wait after last trigger
triggers:
- type: prometheus # Scaler type
metadata:
serverAddress: http://prometheus:9090
metricName: http_requests_total
threshold: '100'
query: sum(rate(http_requests_total[2m]))
Scaled Objeto con múltiples desencadenantes¶
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: multi-trigger-scaler
spec:
scaleTargetRef:
name: api-deployment
minReplicaCount: 1
maxReplicaCount: 50
triggers:
- type: prometheus
metadata:
serverAddress: http://prometheus:9090
threshold: '100'
query: sum(rate(http_requests_total[2m]))
- type: cpu
metricType: Utilization
metadata:
value: "70"
- type: memory
metricType: Utilization
metadata:
value: "80"
Scaled Objeto con comportamiento avanzado HPA¶
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: advanced-scaling
spec:
scaleTargetRef:
name: worker-deployment
minReplicaCount: 2
maxReplicaCount: 100
advanced:
restoreToOriginalReplicaCount: true
horizontalPodAutoscalerConfig:
behavior:
scaleDown:
stabilizationWindowSeconds: 300
policies:
- type: Percent
value: 50 # Scale down max 50% at a time
periodSeconds: 60
scaleUp:
stabilizationWindowSeconds: 0
policies:
- type: Percent
value: 100 # Scale up max 100% at a time
periodSeconds: 15
- type: Pods
value: 5 # Or add max 5 pods at a time
periodSeconds: 15
selectPolicy: Max # Use the policy that scales faster
triggers:
- type: kafka
metadata:
bootstrapServers: kafka:9092
consumerGroup: my-group
topic: events
lagThreshold: '10'
Scaled Configuración de empleo¶
apiVersion: keda.sh/v1alpha1
kind: ScaledJob
metadata:
name: batch-processor
spec:
jobTargetRef:
parallelism: 1
completions: 1
backoffLimit: 3
template:
spec:
containers:
- name: processor
image: myapp:latest
command: ["./process"]
restartPolicy: Never
pollingInterval: 30
maxReplicaCount: 10
successfulJobsHistoryLimit: 5
failedJobsHistoryLimit: 5
scalingStrategy:
strategy: "default" # or "custom", "accurate"
triggers:
- type: rabbitmq
metadata:
queueName: jobs
host: amqp://guest:guest@rabbitmq:5672
queueLength: '5'
TriggerAuthentication with Secret¶
apiVersion: v1
kind: Secret
metadata:
name: rabbitmq-secret
type: Opaque
stringData:
connection-string: "amqp://user:password@rabbitmq:5672"
---
apiVersion: keda.sh/v1alpha1
kind: TriggerAuthentication
metadata:
name: rabbitmq-auth
spec:
secretTargetRef:
- parameter: host
name: rabbitmq-secret
key: connection-string
ClusterTriggerAuthentication with Pod Identity¶
apiVersion: keda.sh/v1alpha1
kind: ClusterTriggerAuthentication
metadata:
name: aws-credentials
spec:
podIdentity:
provider: aws-eks # or aws-kiam, azure, gcp
identityId: arn:aws:iam::123456789012:role/keda-role
Helm installation Valores¶
# values.yaml for Helm installation
operator:
replicaCount: 2 # HA setup
metricsServer:
replicaCount: 2 # HA setup
serviceAccount:
annotations:
eks.amazonaws.com/role-arn: arn:aws:iam::123456789012:role/keda-role
resources:
operator:
limits:
cpu: 1000m
memory: 1000Mi
requests:
cpu: 100m
memory: 100Mi
metricServer:
limits:
cpu: 1000m
memory: 1000Mi
requests:
cpu: 100m
memory: 100Mi
prometheus:
operator:
enabled: true
podMonitor:
enabled: true
metricServer:
enabled: true
podMonitor:
enabled: true
Common Use Cases¶
Use Case 1: RabbitMQ Escalada basada en la cola¶
Escalar un despliegue de trabajadores basado en Rabbit MQ profundidad de cola:
# Create secret with RabbitMQ credentials
kubectl create secret generic rabbitmq-secret \
--from-literal=host='amqp://user:password@rabbitmq.default.svc.cluster.local:5672'
# Create TriggerAuthentication
kubectl apply -f - <<EOF
apiVersion: keda.sh/v1alpha1
kind: TriggerAuthentication
metadata:
name: rabbitmq-auth
spec:
secretTargetRef:
- parameter: host
name: rabbitmq-secret
key: host
EOF
# Create ScaledObject
kubectl apply -f - <<EOF
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: rabbitmq-scaler
spec:
scaleTargetRef:
name: worker-deployment
minReplicaCount: 0
maxReplicaCount: 30
triggers:
- type: rabbitmq
metadata:
protocol: amqp
queueName: tasks
mode: QueueLength
value: '5'
authenticationRef:
name: rabbitmq-auth
EOF
# Monitor scaling
kubectl get scaledobject rabbitmq-scaler -w
kubectl get hpa
kubectl get deployment worker-deployment
Use Case 2: Kafka Consumer Group Lag Scaling¶
Scale Kafka consumidores basados en grupo de consumidores:
# Create ScaledObject for Kafka
kubectl apply -f - <<EOF
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: kafka-consumer-scaler
spec:
scaleTargetRef:
name: kafka-consumer
minReplicaCount: 1
maxReplicaCount: 50
triggers:
- type: kafka
metadata:
bootstrapServers: kafka.default.svc.cluster.local:9092
consumerGroup: my-consumer-group
topic: events
lagThreshold: '10'
offsetResetPolicy: latest
EOF
# Check scaling status
kubectl describe scaledobject kafka-consumer-scaler
kubectl get hpa keda-hpa-kafka-consumer-scaler
# View external metrics
kubectl get --raw "/apis/external.metrics.k8s.io/v1beta1/namespaces/default/s0-kafka-my-consumer-group" | jq
Use Case 3: Prometheus Metrics-Based Scaling¶
Escala basada en la costumbre Prometheus metrics:
# Create ScaledObject with Prometheus trigger
kubectl apply -f - <<EOF
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: prometheus-scaler
spec:
scaleTargetRef:
name: api-server
minReplicaCount: 2
maxReplicaCount: 20
triggers:
- type: prometheus
metadata:
serverAddress: http://prometheus.monitoring.svc.cluster.local:9090
metricName: http_requests_per_second
threshold: '100'
query: |
sum(rate(http_requests_total{job="api-server"}[2m]))
EOF
# Verify Prometheus connectivity
kubectl logs -n keda deployment/keda-operator | grep prometheus
# Test scaling
kubectl get scaledobject prometheus-scaler -o jsonpath='{.status}'
Use Case 4: Cron-Based Scheduled Scaling¶
Capacidades de escala basadas en horarios:
# Create ScaledObject with cron trigger for business hours
kubectl apply -f - <<EOF
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: scheduled-scaler
spec:
scaleTargetRef:
name: business-app
minReplicaCount: 1
maxReplicaCount: 1
triggers:
- type: cron
metadata:
timezone: America/New_York
start: 0 8 * * 1-5 # 8 AM Mon-Fri
end: 0 18 * * 1-5 # 6 PM Mon-Fri
desiredReplicas: "10"
- type: cron
metadata:
timezone: America/New_York
start: 0 18 * * 1-5 # 6 PM Mon-Fri
end: 0 8 * * 1-5 # 8 AM Mon-Fri
desiredReplicas: "2"
EOF
# Monitor scheduled scaling
kubectl get scaledobject scheduled-scaler -w
kubectl get events --field-selector involvedObject.name=scheduled-scaler
Use Case 5: AWS SQS Procesamiento de las colas con¶
Procesamiento mensajes SQS de AWS usando trabajos por lotes:
# Create ClusterTriggerAuthentication with AWS IAM
kubectl apply -f - <<EOF
apiVersion: keda.sh/v1alpha1
kind: ClusterTriggerAuthentication
metadata:
name: aws-credentials
spec:
podIdentity:
provider: aws-eks
EOF
# Create ScaledJob for SQS processing
kubectl apply -f - <<EOF
apiVersion: keda.sh/v1alpha1
kind: ScaledJob
metadata:
name: sqs-processor
spec:
jobTargetRef:
template:
spec:
containers:
- name: processor
image: my-sqs-processor:latest
env:
- name: QUEUE_URL
value: https://sqs.us-east-1.amazonaws.com/123456789012/my-queue
restartPolicy: Never
pollingInterval: 30
maxReplicaCount: 10
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 3
triggers:
- type: aws-sqs-queue
authenticationRef:
name: aws-credentials
kind: ClusterTriggerAuthentication
metadata:
queueURL: https://sqs.us-east-1.amazonaws.com/123456789012/my-queue
queueLength: '5'
awsRegion: us-east-1
EOF
# Monitor job creation
kubectl get scaledjob sqs-processor
kubectl get jobs -l scaledjob.keda.sh/name=sqs-processor
kubectl logs job/<job-name>
Buenas prácticas¶
- Comienza con Límites Conservadores: Comience con
minReplicaCount: 1y valores moderadosmaxReplicaCount_. Test scale-to-zero (minReplicaCount: 0) sólo después de validar las manijas de la aplicación el frío comienza con gracia.
Configure Appropriate Polling and Cooldown: Set pollingInterval (default 30s) basado en la frecuencia de actualización de su fuente métrica. Usar más tiempo cooldownPeriod (por defecto 300s) para cargas de trabajo con tráfico variable para evitar el deslizamiento.
- Use TriggerAuthentication for Secrets: Nunca las credenciales de código duro en las especificaciones de objetos escalados. Utilizar siempre
TriggerAuthenticationoClusterTriggerAuthenticationcon secretos de Kubernetes o proveedores de identidad de pod (AWS IAM, Azure AD, GCP Workload Identity).
Aplicar las políticas de comportamiento de HPA: Para las cargas de trabajo de producción, configure advanced.horizontalPodAutoscalerConfig.behavior para controlar las tasas de escala/descarga. Evitar el escalado agresivo con ventanas de estabilización y políticas basadas en porcentajes.
Monitor KEDA Componentes**: Deploy KEDA operador y servidor de métricas con al menos 2 réplicas para alta disponibilidad. Permite monitorear Prometheus y establecer alertas para los fallos del componente de KEDA en salud y escalado.
-
Stablecer límites de recursos: definir siempre las solicitudes de recursos y los límites de los componentes de KEDA y las cargas de trabajo escaladas. Esto evita la contención de recursos y asegura un comportamiento de escalado predecible.
-
Configuración de Fallback: Configure __INLINE_CODE_89_ y
fallback.failureThresholdpara mantener la disponibilidad de servicios cuando no se disponga de fuentes métricas externas. Esto evita escalar a cero durante las salidas de fuentes métricas. -
Comportamiento de escalado de búsqueda: Antes de la implementación de la producción, prueba el escalado bajo carga usando la anotación de pausa (__INLINE_CODE_91_) para validar los umbrales de activación y observar patrones de escalada sin afectar el tráfico en vivo.
-
Isolación espacial**: Use espacios de nombres separados para diferentes entornos (dev, estadificación, prod) y aplique políticas RBAC apropiadas. Usar
ClusterTriggerAuthenticationpara credenciales compartidas en los espacios de nombres. -
Control de Versión Objetos: Almacene todos los recursos de KEDA en Git junto con los manifiestos de aplicación. Utilice las herramientas GitOps (ArgoCD, Flux) para gestionar las configuraciones de KEDA y asegurar la consistencia en entornos.
Troubleshooting¶
| Issue | Solution |
|---|---|
| ScaledObject not creating HPA | Check KEDA operator logs: INLINE_CODE_93. Verify scaleTargetRef points to existing deployment/statefulset. Ensure deployment has valid selector labels. |
| Pods not scaling to zero | Verify INLINE_CODE_94 is set. Check if HPA exists: INLINE_CODE_95. Ensure no other HPAs target the same deployment. Review trigger conditions: INLINE_CODE_96. |
| Metrics not available | Check metrics server: INLINE_CODE_97. View metrics server logs: INLINE_CODE_98. Verify trigger authentication is configured correctly. |
| Authentication failures | Verify secret exists: INLINE_CODE_99. Check TriggerAuthentication references correct secret and keys. For pod identity, ensure service account has proper IAM/Azure AD annotations. Test credentials manually. |
Scaling too aggression/slow Silencio Adjust pollingInterval (cuántas veces se revisan las métricas). Configure H |