KEDA - kamialie/knowledge_corner GitHub Wiki

Architecture

Performs the following roles:

Role Component Description
Agent keda-operator Allows deployments to scale from and to zero, if there are no events.
Metrics keda-operator-metrics-apiserver Exposes metrics directly to HPA, thus, acting as a metrics server.
Admissions Webhook - Can be used in conjunction with admission controller to automatically detect resource configuration changes, keeping them in stable state. Also preserves a scale target from being scaled by multiple ScaledObjects

Scalers

Scalers respond to external events and triggers adjustments: increasing/decreasing number of replicas, adjusting resource limits, or even pausing the deployment. Scaling strategies offer flexible settings such as thresholds, scaling rules, and time windows for triggering actions.

Examples:

  • Scaling a web server based on HTTP requests
  • Processing a backlog of Kafka jobs
  • Adjusting database resources based on query load

Best practices include:

  • Understand the event source thoroughly - fully understand how available metrics relate to application, and what metrics correlates best
  • Scalability testing - test various loads, and simulate events before rolling out to production
  • Optimize scaling parameters - configure appropriate cooldown periods to avoid too frequent scaling actions, and set reasonable limits to avoid overprovisioning and under-scaling
  • Security considerations - secure access to event sources and regularly audit and monitor those
  • Monitoring and observability - collect metrics for autoscaling events to understand the behavior over time

Custom Resource Definitions

ScaledObjects

Define how KEDA should scale an arbitrary deployment or workload. Main components are scaleTargetRef (target), triggers (event source and trigger parameters), minReplicaCount and maxReplicaCount.

apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  name: my-scaledobject
spec:
  scaleTargetRef:
    name: my-deployment
  triggers:
  - type: azure-queue
    metadata:
      queueName: my-queue
      connection: azure-secret
      queueLength: '5'
  minReplicaCount: 1
  maxReplicaCount: 10

ScaledJobs

Similar to ScaledObjects but for Kubernetes Jobs.

apiVersion: keda.sh/v1alpha1
kind: ScaledJob
metadata:
  name: my-scaledjob
spec:
  scaleTargetRef:
    name: my-job
  triggers:
  - type: job-completion

TriggerAuthentication

Secure communication with event source.

apiVersion: keda.sh/v1alpha1
kind: TriggerAuthentication
metadata:
  name: my-triggerauth
spec:
  secretTargetRef:
    - parameter: apiKey
      name: my-secret
      key: api-key

ClusterTriggerAuthentication

Similar to TriggerAuthentication, but at the cluster scope. Can be used to share authentication details across ScaledObjects.

apiVersion: keda.sh/v1alpha1
kind: ClusterTriggerAuthentication
metadata:
  name: my-cluster-triggerauth
spec:
  secretTargetRef:
    - parameter: apiKey
      name: my-secret
      key: api-key

Installation

Supports Operator Hub, YAML and Helm chart deployment methods.

# Add Helm repository
helm repo add kedacore ht‌tps://kedacore.github.io/charts
# Update the Helm repository
helm repo update
# Install the KEDA Helm chart
helm install -i keda kedacore/keda --namespace keda --create-namespace

Uninstalling:

# Remove any ScaledObjects and ScaledJobs that you have created
kubectl delete $(kubectl get scaledobjects.keda.sh,scaledjobs.keda.sh -A -o jsonpath='{"-n "}{.items[*].metadata.namespace}{" "}{.items[*].kind}{"/"}{.items[*].metadata.name}{"\n"}')
# Uninstall the Helm chart
helm uninstall keda -n keda

Links