Created
December 15, 2021 19:46
-
-
Save rothgar/4304a79f0b1161e5c38ad53d47a0d4a8 to your computer and use it in GitHub Desktop.
Create random Kubernetes deployments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -o pipefail | |
# total amount of pods to create | |
TOTAL=${1:-500} | |
# deploy size | |
export BATCH=${2:-100} | |
export NAMESPACE=${KUBE_NAMESPACE:-default} | |
CPU_OPTIONS=(250m 500m 750m 1 2) | |
#MEM_OPTIONS=(128M 256M 512M 1G 2G) | |
MEM_OPTIONS=(512M 750M 1G 1500M 2G) | |
CPU_OPTIONS_LENG=${#CPU_OPTIONS[@]} | |
MEM_OPTIONS_LENG=${#MEM_OPTIONS[@]} | |
COUNT=0 | |
while (test $COUNT -lt $TOTAL); do | |
RAND=$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 5 | head -n 1) | |
export CPU=${CPU_OPTIONS[$[$RANDOM % $CPU_OPTIONS_LENG]]} | |
export MEM=${MEM_OPTIONS[$[$RANDOM % $MEM_OPTIONS_LENG]]} | |
export NAME="batch-${CPU,,}-${MEM,,}-${RAND}" | |
echo "Creating ${NAME} with ${BATCH} replicas" | |
cat deployment-template.yaml \ | |
| envsubst \ | |
| kubectl apply -n ${NAMESPACE} -f - | |
COUNT=$((COUNT+$BATCH)) | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eo pipefail | |
kubectl get deploy \ | |
| grep batch \ | |
| awk '{print $1}' \ | |
| xargs kubectl delete deploy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
name: "${NAME}" | |
spec: | |
replicas: ${BATCH} | |
selector: | |
matchLabels: | |
app: "${NAME}" | |
template: | |
metadata: | |
labels: | |
app: "${NAME}" | |
spec: | |
containers: | |
- image: public.ecr.aws/jg/curlit:latest | |
name: "${NAME}" | |
resources: | |
requests: | |
cpu: "${CPU}" | |
memory: "${MEM}" | |
tolerations: | |
- key: karpenter | |
operator: Exists | |
nodeSelector: | |
kubernetes.io/arch: amd64 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment