From 71d3ac6de4f9bc0aec3203588510202f4838a702 Mon Sep 17 00:00:00 2001 From: Yaron Schneider Date: Tue, 15 Oct 2019 14:52:27 -0700 Subject: [PATCH] add KEDA (#123) --- howto/autoscale-with-keda/README.md | 85 +++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 howto/autoscale-with-keda/README.md diff --git a/howto/autoscale-with-keda/README.md b/howto/autoscale-with-keda/README.md new file mode 100644 index 000000000..b533c38a8 --- /dev/null +++ b/howto/autoscale-with-keda/README.md @@ -0,0 +1,85 @@ +# Autoscaling a Dapr app with KEDA + +Dapr is a programming model that's being installed and operated using a sidecar, and thus leaves autoscaling to the hosting layer, for example Kubernetes. +Many of Dapr's [bindings](../../concepts/bindings#supported-bindings-and-specs) overlap with those of [KEDA](https://github.com/kedacore/keda), an Event Driven Autoscaler for Kubernetes. + +For apps that use these bindings, its easy to configure a KEDA autoscaler. + +## Install KEDA + +To install KEDA, follow [these instructions](https://github.com/dapr/docs/tree/master/concepts/bindings#supported-bindings-and-specs) on the KEDA Github page. + +## Create KEDA enabled Dapr binding + +For this example, we'll be using Kafka.
+You can install Kafka in your cluster by using Helm: + +``` +# helm repo add incubator http://storage.googleapis.com/kubernetes-charts-incubator +$ helm install --name my-kafka incubator/kafka +``` + +Next, we'll create the Dapr Kafka binding for Kubernetes.
+Paste the following in a file named kafka.yaml: + +```yaml +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: kafkaevent +spec: + type: bindings.kafka + metadata: + - name: brokers + value: "my-kafka:9092" + - name: topics + value: "myTopic" + - name: consumerGroup + value: "group1" +``` + +The following YAML defines a Kafka component that listens for the topic `myTopic`, with consumer group `group1` and that connects to a broker at `my-kafka:9092`. + +Deploy the binding to the cluster: + +``` +$ kubectl apply -f kafka.yaml +``` + +## Create the KEDA autoscaler for Kafka + +Paste the following to a file named kafka_scaler.yaml, and put the name of your Deployment in the required places: + +```yaml +apiVersion: keda.k8s.io/v1alpha1 +kind: ScaledObject +metadata: + name: kafka-scaler + namespace: default + labels: + deploymentName: +spec: + scaleTargetRef: + deploymentName: + triggers: + - type: kafka + metadata: + type: kafkaTrigger + direction: in + name: event + topic: myTopic + brokers: my-kafka:9092 + consumerGroup: group2 + dataType: binary + lagThreshold: '5' +``` + +Deploy the KEDA scaler to Kubernetes: + +``` +$ kubectl apply -f kafka_scaler.yaml +``` + +All done! + +You can now start publishing messages to your Kafka topic `myTopic` and watch the pods autoscale when the lag threshold is bigger than `5`, as defined in the KEDA scaler manifest. \ No newline at end of file