What you will learn :
- How to deploy Keda
- How to configure a ScaledObject using the metric API scaler
- How to observe Keda
This repository showcase the usage of the Keda by using GKE with :
- the HipsterShop
- Dynatrace
- Nginx ingress controller
The following tools need to be install on your machine :
- jq
- kubectl
- git
- gcloud ( if you are using GKE)
- Helm
- Dynatrace tenant.
If you don't have any dynatrace tenant , then let's start a trial on Dynatrace
You will first need a Kubernetes cluster with 2 Nodes. You can either deploy on Minikube or K3s or follow the instructions to create GKE cluster:
PROJECT_ID="<your-project-id>"
gcloud services enable container.googleapis.com --project ${PROJECT_ID}
gcloud services enable monitoring.googleapis.com \
cloudtrace.googleapis.com \
clouddebugger.googleapis.com \
cloudprofiler.googleapis.com \
--project ${PROJECT_ID}
ZONE=us-central1-b
gcloud container clusters create onlineboutique \
--project=${PROJECT_ID} --zone=${ZONE} \
--machine-type=e2-standard-2 --num-nodes=4
git clone https://github.com/isItObservable/Keda
cd Keda
helm upgrade --install ingress-nginx ingress-nginx \
--repo https://kubernetes.github.io/ingress-nginx \
--namespace ingress-nginx --create-namespace
--set controller.enableLatencyMetrics=true --set prometheus.create=true
Since we are using Ingress controller to route the traffic , we will need to get the public ip adress of our ingress. With the public ip , we would be able to update the deployment of the ingress for :
- hipstershop
IP=$(kubectl get svc ingress-nginx-controller -n ingress-nginx -ojson | jq -j '.status.loadBalancer.ingress[].ip')
update the following files to update the ingress definitions :
sed -i "s,IP_TO_REPLACE,$IP," kubernetes-manifests/k8s-manifest.yaml
sed -i "s,IP_TO_REPLACE,$IP," K6/load.yaml
In order to configure the ScaledObject based on Dynatrace metrics, we will need to deploy the Dynatrace Operator to be able to observe our cluster in Dynatrace. To deploy it from the Dynatrace UI , you will need to click on the left menu "Deploy Dynatrace". Then click on the "Start installation" and select the type of deployment : Kubernetes and follow the instructions.
Or you can also Follow the steps describe in the documnetation to deploy the dynatrace operator
To be able to observe Keda and the autoscalling process, we will need to run a small K6 load test. To be able to use the k6 integration, we will need to create an API Token with the following scope:
- ingest metrics API v2
- Read metrics API V2 To create token, click on the left menu on Access Tokens , and create token.
Copy the value of your token and fill :
TOKEN= YOU TOKEN
DYNATRACE_HOST=YOU DYNATRACE HOST ( with https)
sed -i "s,URL_TO_REPLACE,$DYNATRACE_HOST," kubernetes-manifests/k6dynatrace.yaml
sed -i "s,URL_TO_REPLACE,$DYNATRACE_HOST," keda/keda.yaml
sed -i "s,TOKEN_TO_REPLACE,$TOKEN," kubernetes-manifests/k6dynatrace.yaml
To let dynatrace collect the prometheus metrics generated by the ingress controller, we need to add the following annation on the nginx deployment :
metrics.dynatrace.com/path: /metrics
metrics.dynatrace.com/port: "10254"
metrics.dynatrace.com/scrape: "true"
to edit the deployment :
kubectl edit deployment ingress-nginx-controller -n ingress-nginx
Add the annotation in the template section of the deployment.
kubectl create ns hipster-shop
kubectl apply -n hipster-shop -f kubernetes-manifests/k6dynatrace.yaml
kubectl apply -n hipster-shop -f kubernetes-manifests/k8s-manifest.yaml
helm repo add kedacore https://kedacore.github.io/charts
helm repo update
kubectl create namespace keda
helm install keda kedacore/keda --namespace keda
kubectl apply -f keda/keda.yaml -n hipster-shop
let's generate some extra load to reach our threshold
kubectl apply -f K6/load.yaml -n hipster-shop
Let's Open Dynatrace and see the data coming in from Keda.
gcloud container clusters delete onlineboutique \
--project=${PROJECT_ID} --zone=${ZONE}



