Load-test rig: k6 swarm script + in-cluster target drone
This commit is contained in:
47
scripts/loadtest.sh
Executable file
47
scripts/loadtest.sh
Executable file
@@ -0,0 +1,47 @@
|
||||
#!/bin/bash
|
||||
# Spawn a k6 load swarm against a target.
|
||||
# Usage: ./scripts/loadtest.sh <target-url> [pods] [vus-per-pod] [duration]
|
||||
# Example: ./scripts/loadtest.sh https://staging.example.com 20 50 5m
|
||||
# -> 20 pods x 50 virtual users = 1000 concurrent requests, 5 minutes
|
||||
set -euo pipefail
|
||||
|
||||
TARGET=${1:?usage: loadtest.sh <target-url> [pods] [vus-per-pod] [duration]}
|
||||
PODS=${2:-20}
|
||||
VUS=${3:-20}
|
||||
DURATION=${4:-60s}
|
||||
NAME="loadtest-$(date +%s)"
|
||||
|
||||
kubectl -n loadtest apply -f - <<EOF
|
||||
apiVersion: batch/v1
|
||||
kind: Job
|
||||
metadata:
|
||||
name: $NAME
|
||||
spec:
|
||||
parallelism: $PODS
|
||||
completions: $PODS
|
||||
ttlSecondsAfterFinished: 300
|
||||
template:
|
||||
spec:
|
||||
restartPolicy: Never
|
||||
containers:
|
||||
- name: k6
|
||||
image: grafana/k6:1.4.0
|
||||
command: ["k6", "run", "/scripts/test.js"]
|
||||
env:
|
||||
- {name: TARGET_URL, value: "$TARGET"}
|
||||
- {name: VUS, value: "$VUS"}
|
||||
- {name: DURATION, value: "$DURATION"}
|
||||
resources:
|
||||
requests: {cpu: 100m, memory: 128Mi}
|
||||
limits: {memory: 256Mi}
|
||||
volumeMounts:
|
||||
- {name: scripts, mountPath: /scripts}
|
||||
volumes:
|
||||
- name: scripts
|
||||
configMap: {name: k6-script}
|
||||
EOF
|
||||
|
||||
echo "Swarm '$NAME' launched: $PODS pods x $VUS vus for $DURATION against $TARGET"
|
||||
echo "Watch: kubectl -n loadtest get pods -w"
|
||||
echo "Logs: kubectl -n loadtest logs -f job/$NAME --all-pods=true --tail=5"
|
||||
echo "Stop: kubectl -n loadtest delete job $NAME"
|
||||
Reference in New Issue
Block a user