Created
April 16, 2019 13:50
-
-
Save saumets/f4056e0f298fa02fd078566ab26135df to your computer and use it in GitHub Desktop.
Dynamically update the Horizontal Pod Autoscaler for a given Openshift deployment.
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/sh | |
set -o nounset -o errexit | |
## Dynamically update the Horizontal Pod Autoscaler for a given Openshift deployment. | |
## Usage: ./run-hpa-update.sh 3 5 my-app production | |
MIN_REPLICAS=${1:-1} | |
MAX_REPLICAS=${2:-1} | |
APP=${3:-my-app-name} | |
ENVIRONMENT=${4:-staging} | |
# workaround for https://github.com/kubernetes/kubernetes/issues/34413 | |
if oc get hpa/${APP}-${ENVIRONMENT} > /dev/null 2>&1 | |
then | |
oc delete hpa/${APP}-${ENVIRONMENT} | |
fi | |
HPA='{ | |
"apiVersion": "autoscaling/v1", | |
"kind": "HorizontalPodAutoscaler", | |
"metadata": { | |
"name": "'${APP}'-'${ENVIRONMENT}'", | |
"labels": { | |
"app": "'${APP}'" | |
} | |
}, | |
"spec": { | |
"maxReplicas": '${MAX_REPLICAS}', | |
"minReplicas": '${MIN_REPLICAS}', | |
"scaleTargetRef": { | |
"apiVersion": "v1", | |
"kind": "DeploymentConfig", | |
"name": "'${APP}'-'${ENVIRONMENT}'" | |
}, | |
"targetCPUUtilizationPercentage": 80 | |
} | |
}' | |
echo $HPA | oc create --dry-run -o yaml -f - | oc apply -f - |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment