Skip to content

Instantly share code, notes, and snippets.

@akarca
Last active April 15, 2021 09:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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