kedacore/keda

Scale based on k8s native events

Open

#4,876 opened on Aug 13, 2023

 (18 comments) (1 reaction) (0 assignees)Go (1,457 forks)auto 404
featurehelp wantedscalerstale-bot-ignore

Repository metrics

Stars
 (10,372 stars)
PR merge metrics
 (PR metrics pending)

Description

Proposal

the idea of this scaler is to scale workloads based on k8s native event.

Usecase

a sample use case for this scaler is with DeprovisioningBlocked event . this event is thrown when k8s isn't able to drain a node, there are multiple reasons for this one of them is due to PDB (Pod disruption budges) .

here is a sample event content that can be taken from kubectl get events -o json:

{
            "apiVersion": "v1",
            "count": 1,
            "eventTime": null,
            "firstTimestamp": "2023-08-13T08:47:00Z",
            "involvedObject": {
                "apiVersion": "karpenter.sh/v1alpha5",
                "kind": "Machine",
                "name": "RESOURCE_NAME",
                "resourceVersion": "1069644099",
                "uid": "ad90b678-0693-4ef1-929b-1091fa68e4ea"
            },
            "kind": "Event",
            "lastTimestamp": "2023-08-13T08:47:00Z",
            "message": "Cannot deprovision machine due to pdb {NAMESPACE}/{PDB_BANE} prevents pod evictions",
            "metadata": {
                "creationTimestamp": "2023-08-13T08:47:00Z",
                "name": "RESOURCE_NAME",
                "namespace": "default",
                "resourceVersion": "1070337960",
                "uid": "da73d9a0-7ecb-48f6-a9e0-47d359d9aee4"
            },
            "reason": "DeprovisioningBlocked",
            "reportingComponent": "",
            "reportingInstance": "",
            "source": {
                "component": "karpenter"
            },
            "type": "Normal"
        },

the scaler will be useful to resolve this issue and add new pod when this event is thrown which will allow the node to be drained since there is enough pods to maintain the PDB condition.

Scaler Source

K8s Events API

Scaling Mechanics

we can scale based on the response of k8s Events API .

here is a suggested format for the keda scaled object trigger:

triggers:
- type: kubernetes-events
  metadata:
    eventsFilters:
    - field: reason
      type: exact
      value: 'DeprovisioningBlocked'
    - field: message
      type: regex
      value: '.*due to pdb {NAMESPACE}.*}'
    eventCountThreshold: 3

Authentication Source

KEDA Service account (same as Kubernetes Workload scaler)

Anything else?

I'm willing to work on this scaler and create the PR for it if you don't have any notes on this.

Contributor guide