Skip to main content
Version: v1.0

KEDA as Autoscaling Trait

Before continue, make sure you have learned about the concepts of Definition Objects and Defining Traits with CUE section.

In the following tutorial, you will learn to add KEDA as a new autoscaling trait to your KubeVela based platform.

KEDA is a Kubernetes-based Event Driven Autoscaler. With KEDA, you can drive the scaling of any container based on resource metrics or the number of events needing to be processed.

Step 1: Install KEDA controller#

Install the KEDA controller into your K8s system.

Step 2: Create Trait Definition#

To register KEDA as a new capability (i.e. trait) in KubeVela, the only thing needed is to create an TraitDefinition object for it.

A full example can be found in this keda.yaml. Several highlights are list below.

1. Describe The Trait#

name: keda-scaler
annotations: "keda supports multiple event to elastically scale applications, this scaler only applies to deployment as example"

We use label to add one line description for this trait. It will be shown in helper commands such as $ vela traits.

2. Register API Resource#


This is how you claim and register KEDA ScaledObject's API resource ( as a trait definition.

3. Define appliesToWorkloads#

A trait can be attached to specified workload types or all (i.e. "*" means your trait can work with any workload type).

For the case of KEAD, we will only allow user to attach it to Kubernetes workload type. So we claim it as below:

- "deployments.apps" # claim KEDA based autoscaling trait can only attach to Kubernetes Deployment workload type.

4. Define Schematic#

In this step, we will define the schematic of KEDA based autoscaling trait, i.e. we will create abstraction for KEDA ScaledObject with simplified primitives, so end users of this platform don't really need to know what is KEDA at all.

template: |-
outputs: kedaScaler: {
apiVersion: ""
kind: "ScaledObject"
metadata: {
spec: {
scaleTargetRef: {
triggers: [{
type: parameter.triggerType
metadata: {
type: "Utilization"
value: parameter.value
parameter: {
// +usage=Types of triggering application elastic scaling, Optional: cpu, memory
triggerType: string
// +usage=Value to trigger scaling actions, represented as a percentage of the requested value of the resource for the pods. like: "60"(60%)
value: string

This is a CUE based template which only exposes type and value as trait properties for user to set.

Please check the Defining Trait with CUE section for more details regarding to CUE templating.

Step 2: Register New Trait to KubeVela#

As long as the definition file is ready, you just need to apply it to Kubernetes.

$ kubectl apply -f

And the new trait will immediately become available for end users to use in Application resource.

Last updated on by Jianbo Sun