Skip to content

Instantly share code, notes, and snippets.

@akarca
Last active September 11, 2024 06:43
Show Gist options
  • Save akarca/1737303c8ae775376dec6b16165e2596 to your computer and use it in GitHub Desktop.
Save akarca/1737303c8ae775376dec6b16165e2596 to your computer and use it in GitHub Desktop.
Automatic VPA generator for all deployments in namespace
#!/bin/bash
#
# Usage: ./generate_vpa.sh namespace
#
# Generates yaml files for vpa and applies.
#
mkdir -p "yaml/"$1"/"
kubectl get deploy -n $1 | grep -v NAME | awk -v namespace=$1 '{print $1" "namespace}' | awk '{ system("sed -e \"s/\{namespace}/"$2"/\" -e \"s/\{name}/"$1"/\" vpa.tpl > yaml/"$2"/"$1".yaml") }'
find "yaml/"$1 -name "*.yaml" -exec kubectl apply -f {} \;
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
namespace: {namespace}
name: {name}
spec:
targetRef:
apiVersion: "apps/v1"
kind: Deployment
name: {name}
updatePolicy:
updateMode: "Off"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment