This repository contains an example application demonstrating the use of OpenTelemetry with KEDA for Kubernetes-based autoscaling.
This repository makes use of Nix and direnv to manage the development environment and dependencies. Follow these steps to set them up:
- Install Nix by following the instructions here.
- Install direnv by following the instructions here.
- Navigate to the project directory and allow direnv to load the environment:
direnv allowhelm repo add grafana https://grafana.github.io/helm-charts
helm repo add kedacore https://kedacore.github.io/charts
helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts
helm repo updatekind create cluster --config=kind.yaml --name otel-keda-examplehelm upgrade grafana grafana/grafana --namespace grafana --create-namespace --install --values grafana-values.yaml
helm upgrade mimir grafana/mimir-distributed --namespace mimir --create-namespace --install --values mimir-values.yaml
helm upgrade keda kedacore/keda --namespace keda --create-namespace --install --values keda-values.yaml
helm upgrade opentelemetry-collector-daemonset open-telemetry/opentelemetry-collector --namespace opentelemetry-collector --create-namespace --install --values opentelemetry-collector-daemonset-values.yaml
helm upgrade opentelemetry-collector-deployment open-telemetry/opentelemetry-collector --namespace opentelemetry-collector --create-namespace --install --values opentelemetry-collector-deployment-values.yamlFrom local repository
helm upgrade sample-app sample-app/helm --namespace sample-app --create-namespace --install --values sample-app-values.yamlFrom GHCR
helm upgrade sample-app oci://ghcr.io/joaoestrela/otel-keda-example/helm-charts/sample-app --version 0.1.1 --namespace sample-app --create-namespace --install --values sample-app-values.yamlkubectl apply -f sampleAppScaledObject.yamlkubectl get secret --namespace grafana grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echokubectl --namespace grafana port-forward svc/grafana 3000:9090POD_N=0
kubectl --namespace sample-app get pods -o jsonpath="{.items[$POD_N].metadata.name}" | xargs -I {} kubectl --namespace sample-app port-forward {} $((8080 + POD_N)):8080To trigger an autoscaling above 1 pod, make sure the counter average is above what is set in sampleAppScaledObject.yaml. If you have not changed anything, it should be 10.
POD_N=0
grpcurl -plaintext -d '{"value": 5}' localhost:$((8080 + POD_N)) counter.CounterService/IncreaseCounter
grpcurl -plaintext -d '{"value": 3}' localhost:$((8080 + POD_N)) counter.CounterService/DecreaseCounterAfterwards you can check the pod count
kubectl get pods --namespace sample-app --no-headers | wc -lNote
For simplicity's sake, the configured metric is just a basic average at a point in time. It can be changed to any valid Prometheus query.
grafana-values.yaml: Configuration for Grafana.keda-values.yaml: Configuration for KEDA.mimir-values.yaml: Configuration for Mimir.opentelemetry-collector-daemonset-values.yaml: Configuration for OpenTelemetry Collector DaemonSet.opentelemetry-collector-deployment-values.yaml: Configuration for OpenTelemetry Collector Deployment.sample-app/: Sample application.sample-app/helm/: Helm chart for deploying the sample application.sample-app-values.yaml: Configuration for the sample application.