Home
%3CLINGO-SUB%20id%3D%22lingo-sub-1162632%22%20slang%3D%22en-US%22%3EKEDA%20and%20AKS%20Experiments%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1162632%22%20slang%3D%22en-US%22%3E%3CP%3EKEDA%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fkedacore%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fkedacore%3C%2FA%3E%26nbsp%3Bis%20an%20open%20source%20K8s%20controller%20that%20acts%20as%20a%20man%20in%20the%20middle%20between%20a%20data%20or%20event%20store%20such%20as%20Azure%20Event%20Hub%2C%20Storage%20or%20Bus%20queue%20(but%20also%20AWS%2C%20Kafka%2C%20etc.)%20and%20an%20event%20handler%20such%20as%20Azure%20Functions.%20Its%20scalers%20ensure%20that%20the%20appropriate%20number%20of%20handlers%20are%20started%20according%20to%20the%20load%20happening%20at%20the%20level%20of%20the%20source.%20KEDA%20comes%20with%20its%20own%20K8s%20Custom%20Resource%20Definition%20called%20%3CSTRONG%3EScaledObject%3C%2FSTRONG%3E.%20Here%20is%20an%20example%20of%20such%20a%20resource%20deployment%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CDIV%3E%0A%3CDIV%3E%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3EapiVersion%3A%20keda.k8s.io%2Fv1alpha1%0Akind%3A%20ScaledObject%0Ametadata%3A%0A%20%20name%3A%20kedablobautoscaler%0A%20%20namespace%3A%20anamespace%0A%20%20labels%3A%0A%20%20%20%20deploymentName%3A%20kedablob%0Aspec%3A%0A%20%20scaleTargetRef%3A%0A%20%20%20%20deploymentName%3A%20kedablob%0A%23this%20one%20is%20optional.%20KEDA%20scales%20out%20automatically%20but%20we%20can%20still%20limit%20the%20number%20of%20pods%0A%20%20maxReplicaCount%3A%2010%20%0A%20%20triggers%3A%0A%20%20-%20type%3A%20azure-blob%0A%20%20%20%20metadata%3A%0A%20%20%20%20%20%20blobContainerName%3A%20whatever%0A%20%20%20%20%20%20connection%3A%20AzureWebJobsStorage%0A%20%20%20%20%20%20path%3A%20keda%2F%7Bname%7D%0A%20%20%20%20%20%20name%3A%20capturedBlob%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3EIn%20the%20above%20example%2C%20we%20can%20see%20that%20this%20resource%20is%20linked%20to%20a%20deployment%20called%20kedablob%20(not%20present%20here)%20that%20is%20the%20handler.%20The%20source%20is%20in%20this%20case%20an%20Azure%20Blob%20Storage%20and%20the%20connection%20to%20use%20is%20specified%20in%20the%20metadata.%26nbsp%3B%20When%20deploying%20this%2C%20you%20end%20up%20with%20an%20HPA%20(Kubernetes's%20built-in%20Horizontal%20Pod%20Autoscaler)%20being%20created%20for%20you%3A%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22hpa.png%22%20style%3D%22width%3A%20809px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F170001iAC924E7C5DA698AC%2Fimage-dimensions%2F809x342%3Fv%3D1.0%22%20width%3D%22809%22%20height%3D%22342%22%20title%3D%22hpa.png%22%20alt%3D%22hpa.png%22%20%2F%3E%3C%2FSPAN%3E%0A%3CP%3E%E2%80%83%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3E%E2%80%83where%20the%20important%20part%20is%20highlighted%20in%20red.%20It%20takes%20the%20number%20of%20blobs%20present%20in%20the%20Blob%20Storage%20into%20account%20to%20scale%20out%20the%20related%20deployment%20accordingly.%20Note%20that%20if%20the%20handler%20does%20not%20delete%20the%20incoming%20blob%2C%20the%20HPA%20will%20never%20scale%20down.%20Also%20important%20to%20notice%20that%20one%20can%20influence%20the%20HPA%20by%20specifying%20the%20target%20metric%20ourselves.%20KEDA%20defaults%20to%205%20for%20various%20event%20stores.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThere%20are%20many%20triggers%20for%20many%20different%20sources%2C%20to%20get%20an%20exhaustive%20list%2C%20the%20easiest%20is%20to%20have%20a%20look%20at%20the%20.go%20source%20code%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fkedacore%2Fkeda%2Fblob%2Fb068c6430c0029457ac82f3e9af2780c38d6eb72%2Fpkg%2Fhandler%2Fscale_handler.go%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fkedacore%2Fkeda%2Fblob%2Fb068c6430c0029457ac82f3e9af2780c38d6eb72%2Fpkg%2Fhandler%2Fscale_handler.go%3C%2FA%3E%26nbsp%3B.%20For%20Azure%2C%20KEDA%20currently%20supports%20Storage%20Queue%2C%20Service%20Bus%20Queue%2C%20Event%20Hub%20and%20Blob%20Storage.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20below%20schema%20shows%20high%20level%20interactions%20and%20components%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22keda.png%22%20style%3D%22width%3A%20801px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F170006i2F48976971F87D18%2Fimage-dimensions%2F801x661%3Fv%3D1.0%22%20width%3D%22801%22%20height%3D%22661%22%20title%3D%22keda.png%22%20alt%3D%22keda.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%E2%80%83%3C%2FP%3E%0A%3CP%3ETo%20test%20it%20out%20with%20some%20realistic%20scenario%2C%20I%20deployed%20a%20QueueWriter%20pod%20that%20writes%205000%20messages%20every%202%20seconds%20to%20a%20Storage%20Queue.%20I%20scaled%20out%20the%20QueueWriter%20to%2015%20instances%2C%20meaning%2037500%20messages%2Fs.%20I%20let%20KEDA%20scale%20out%20automatically%20and%20ended%20up%20with%20~90%20virtual%20kubelets%20(meaning%20~90%20ACIs)%20handling%20the%20load.%20I%20let%20it%20run%20during%20an%20hour%20to%20treat%20about%20135%20million%20messages.%20Whenever%20I%20checked%20the%20queue%2C%20it%20was%20empty%20or%20could%20see%20a%20message%20from%20time%20to%20time%2C%20meaning%20that%20the%20handlers%20had%20no%20problem%20to%20follow%20the%20pace.%20KEDA%20can%20be%20used%20in%20conjunction%20with%20worker%20nodes%20but%20it%20is%20wiser%20to%20use%20it%20together%20with%20Virtual%20Kubelets%20which%20translates%20to%20ACIs%20and%20a%20dedicated%20agent%20pool%20coming%20with%20the%20following%20characteristics%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22capacity.png%22%20style%3D%22width%3A%20336px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F170011iAFD117C085731D6E%2Fimage-dimensions%2F336x293%3Fv%3D1.0%22%20width%3D%22336%22%20height%3D%22293%22%20title%3D%22capacity.png%22%20alt%3D%22capacity.png%22%20%2F%3E%3C%2FSPAN%3E%0A%3CP%20class%3D%22lia-align-left%22%3E%E2%80%83meaning%20a%20serious%20amount%20of%20resources.%20However%2C%20and%20that%20is%20not%20related%20to%20KEDA%2C%20one%20must%20pay%20attention%20to%20multiple%20things.%20Despite%20of%20the%20nice%20figures%20above%2C%20some%20limitations%20such%20as%20the%20total%20number%20of%20concurrent%20ACI%20(quota)%20apply.%20By%20default%2C%20you%20can't%20exceed%20100%20per%20region%20and%20since%20your%20cluster%20is%20bound%20to%20a%20region%2C%20you%20simply%20can't%20exceed%20100.%20This%20means%20that%20letting%20KEDA%20scale%20your%20handlers%20without%20control%20will%20easily%20lead%20to%20hit%20this%20limit.%20You'll%20end%20up%20with%20containers%20in%20ProviderFailed%20state.%20A%20ticker%20to%20MS%20support%20can%20be%20done%20to%20increase%20the%20default%20threshold.%3C%2FP%3E%0A%3CP%20class%3D%22lia-align-left%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-align-left%22%3EAlso%2C%20admittedly%2C%20ACIs%20are%20not%20started%20in%20a%20few%20secs%20only%2C%20meaning%20that%20under%20high%20load%2C%20KEDA%20will%20attempt%20to%20scale%20even%20more.%20In%20messaging%20and%20event-driven%20scenarios%20that%20are%20very%20asynchronous%20by%20nature%2C%20waiting%20a%20bit%20is%20not%20an%20issue%20but%20as%20long%20as%20no%20handler%20is%20ready%20to%20handle%20queue%20messages%2C%20KEDA%20will%20keep%20scaling%2C%20unless%20a%20maxiumReplicaCount%20is%20specified%20for%20the%20ScaledObject.%26nbsp%3B%20Last%20but%20not%20least%2C%20sometimes%20some%20ACIs%20hang%20in%20a%20pending%20state.%20Here%20again%2C%20although%20a%20bit%20scary%20the%20scheduler%20will%20terminate%20them%20once%20the%20HPA%20is%20back%20to%20its%20lower%20targets.%3C%2FP%3E%0A%3CP%20class%3D%22lia-align-left%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-align-left%22%3EOverall%2C%20this%20produced%20rather%20good%20results%20and%20sure%2C%20KEDA%20is%20something%20to%20keep%20an%20eye%20on!%3C%2FP%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1162632%22%20slang%3D%22en-US%22%3E%3CP%3EInterested%20in%20Event-Driven%20applications%20but%20also%20by%20new%20ways%20of%20handling%20messaging%3F%20Read%20some%20results%20from%20my%20experiments%20with%20KEDA%20and%20AKS%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1162632%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAKS%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Eserverless%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E

KEDA https://github.com/kedacore is an open source K8s controller that acts as a man in the middle between a data or event store such as Azure Event Hub, Storage or Bus queue (but also AWS, Kafka, etc.) and an event handler such as Azure Functions. Its scalers ensure that the appropriate number of handlers are started according to the load happening at the level of the source. KEDA comes with its own K8s Custom Resource Definition called ScaledObject. Here is an example of such a resource deployment:

 

apiVersion: keda.k8s.io/v1alpha1
kind: ScaledObject
metadata:
  name: kedablobautoscaler
  namespace: anamespace
  labels:
    deploymentName: kedablob
spec:
  scaleTargetRef:
    deploymentName: kedablob
#this one is optional. KEDA scales out automatically but we can still limit the number of pods
  maxReplicaCount: 10 
  triggers:
  - type: azure-blob
    metadata:
      blobContainerName: whatever
      connection: AzureWebJobsStorage
      path: keda/{name}
      name: capturedBlob
 
In the above example, we can see that this resource is linked to a deployment called kedablob (not present here) that is the handler. The source is in this case an Azure Blob Storage and the connection to use is specified in the metadata.  When deploying this, you end up with an HPA (Kubernetes's built-in Horizontal Pod Autoscaler) being created for you:
 
hpa.png


 where the important part is highlighted in red. It takes the number of blobs present in the Blob Storage into account to scale out the related deployment accordingly. Note that if the handler does not delete the incoming blob, the HPA will never scale down. Also important to notice that one can influence the HPA by specifying the target metric ourselves. KEDA defaults to 5 for various event stores.

 

There are many triggers for many different sources, to get an exhaustive list, the easiest is to have a look at the .go source code https://github.com/kedacore/keda/blob/b068c6430c0029457ac82f3e9af2780c38d6eb72/pkg/handler/scale_han... . For Azure, KEDA currently supports Storage Queue, Service Bus Queue, Event Hub and Blob Storage.  

 

The below schema shows high level interactions and components:

 

keda.png

To test it out with some realistic scenario, I deployed a QueueWriter pod that writes 5000 messages every 2 seconds to a Storage Queue. I scaled out the QueueWriter to 15 instances, meaning 37500 messages/s. I let KEDA scale out automatically and ended up with ~90 virtual kubelets (meaning ~90 ACIs) handling the load. I let it run during an hour to treat about 135 million messages. Whenever I checked the queue, it was empty or could see a message from time to time, meaning that the handlers had no problem to follow the pace. KEDA can be used in conjunction with worker nodes but it is wiser to use it together with Virtual Kubelets which translates to ACIs and a dedicated agent pool coming with the following characteristics:

 

capacity.png

 meaning a serious amount of resources. However, and that is not related to KEDA, one must pay attention to multiple things. Despite of the nice figures above, some limitations such as the total number of concurrent ACI (quota) apply. By default, you can't exceed 100 per region and since your cluster is bound to a region, you simply can't exceed 100. This means that letting KEDA scale your handlers without control will easily lead to hit this limit. You'll end up with containers in ProviderFailed state. A ticker to MS support can be done to increase the default threshold.

 

Also, admittedly, ACIs are not started in a few secs only, meaning that under high load, KEDA will attempt to scale even more. In messaging and event-driven scenarios that are very asynchronous by nature, waiting a bit is not an issue but as long as no handler is ready to handle queue messages, KEDA will keep scaling, unless a maxiumReplicaCount is specified for the ScaledObject.  Last but not least, sometimes some ACIs hang in a pending state. Here again, although a bit scary the scheduler will terminate them once the HPA is back to its lower targets.

 

Overall, this produced rather good results and sure, KEDA is something to keep an eye on!