skip to content
Alvin Lucillo

Associating ScaledObject and deployment

/ 1 min read

By default, if you don’t specify a kind (scaledobject.spec.scaleTargetRef.kind) in scaleTargetRef, it will assume a deployment kind. In the example below, the ScaledObject references ai-worker, an existing deployment. These two objects need to be in the same namespace.

apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  name: ai-worker
  namespace: keda-demo
spec:
  advanced:
    horizontalPodAutoscalerConfig:
      behavior:
        scaleDown:
          stabilizationWindowSeconds: 15
    scalingModifiers: {}
  maxReplicaCount: 10
  minReplicaCount: 1
  scaleTargetRef:
    name: ai-worker
  triggers:
  - authenticationRef:
      name: rabbitmq
    metadata:
      mode: QueueLength
      protocol: http
      queueName: ai-jobs
      value: "5"
    type: rabbitmq
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/instance: keda-demo
    app.kubernetes.io/name: ai-worker
    app.kubernetes.io/part-of: keda-demo
  name: ai-worker
  namespace: keda-demo
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app.kubernetes.io/instance: keda-demo
      app.kubernetes.io/name: ai-worker
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app.kubernetes.io/instance: keda-demo
        app.kubernetes.io/name: ai-worker
    spec:
      containers:
      - args:
        - worker
        env:
        - name: RABBITMQ_URL
          valueFrom:
            secretKeyRef:
              key: amqp-uri
              name: rabbitmq
        - name: QUEUE_NAME
          value: ai-jobs
        - name: WORKER_TYPE
          value: ai
        - name: PROCESSING_SECONDS
          value: "5"
        image: keda-demo:local
        imagePullPolicy: Never
        name: worker
        ports:
        - containerPort: 8080
          name: metrics
          protocol: TCP
        resources:
          limits:
            memory: 96Mi
          requests:
            cpu: 10m
            memory: 32Mi
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 15