Skip to content

Instantly share code, notes, and snippets.

@hagzag
Created July 14, 2024 06:30
Show Gist options
  • Save hagzag/6f66c357e8c511c22b84365df68fff11 to your computer and use it in GitHub Desktop.
Save hagzag/6f66c357e8c511c22b84365df68fff11 to your computer and use it in GitHub Desktop.
keda-redis-demo
version: '3'
vars:
DEMO_NAME: "keda"
tasks:
cluster-create:
desc: Start the k3d cluster
cmds:
- k3d cluster create {{.DEMO_NAME}}-demo
install-keda:
desc: Install keda via helm
cmds:
- helm repo add kedacore https://kedacore.github.io/charts
- helm upgrade --install keda kedacore/keda --namespace keda --create-namespace --kube-context k3d-{{.DEMO_NAME}}-demo
install-redis:
desc: Install redis via helm
cmds:
- helm repo add bitnami https://charts.bitnami.com/bitnami
- helm upgrade --install redis bitnami/redis --set auth.enabled=false --set architecture=standalone --namespace keda-demo --create-namespace --kube-context k3d-{{.DEMO_NAME}}-demo
demo-web-app:
desc: create a demo web app deploymwnt we can scale
cmds:
- |
cat <<EOF | kubectl -n keda-demo apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-app
spec:
replicas: 1
selector:
matchLabels:
app: web-app
template:
metadata:
labels:
app: web-app
spec:
containers:
- name: web-container
image: nginx:latest
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"
EOF
redis-scaler-deployment:
desc: create a redis scaler
cmds:
- |
cat <<EOF | kubectl apply -f -
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: redis-scaler
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: web-app
pollingInterval: 15
cooldownPeriod: 30
minReplicaCount: 1
maxReplicaCount: 10
triggers:
- type: redis
metadata:
# based on the svc name:
# "redis-master" . "keda-demo" (namespace) . "svc.cluster.local" (cluster-suffix)
address: redis-master.keda-demo.svc.cluster.local:6379
listName: my-queue
listLength: "10"
password: ""
databaseIndex: "0"
key: "hits"
type: string
operator: GT
threshold: "2"
EOF
populate-redis-queue:
desc: populate the redis queue
cmds:
- |
cat <<EOF | kubectl apply -f -
apiVersion: batch/v1
kind: Job
metadata:
name: populate-redis-queue
spec:
template:
spec:
containers:
- name: redis-cli
image: redis:latest
command: ["sh", "-c", "redis-cli -h redis-master.keda-demo.svc.cluster.local -p 6379 lpush my-queue item1 item2 item3 item4 item5 item6 item7 item8 item9"]
restartPolicy: Never
EOF
help:
desc: Show help
cmds:
- task --list
setup:
desc: run the initial setup
cmds:
- task: cluster-create
- task: install-keda
- task: install-redis
- task: demo-web-app
- task: redis-scaler-deployment
demonstrate-scale:
desc: run the initial setup
cmds:
- task: populate-redis-queue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment