-
Notifications
You must be signed in to change notification settings - Fork 242
/
Copy pathscale_deployment.sh
74 lines (68 loc) · 2.12 KB
/
scale_deployment.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
set -ex
total_num_of_run=5
scale_up_of_pods=2400
scale_down_pods=1
function help()
{
echo "Scale deployment based on the parameters."
echo "By default script will repeat the process of scale up/down"
echo
echo "Syntax: scale [-h|n|u|s|c|r]"
echo "options:"
echo "h Print this help."
echo "n Number of times the scale down/scale up task should run."
echo "u Number of pods to be scaled up."
echo "s Scale the pods single time. Accepted Values: true, default : false"
echo "c Check deployment status. Accepted Values: true, default : false"
echo
}
function check_deployment() {
available=-1
replicas="$1"
while [ "${available}" -ne "${replicas}" ]; do
sleep 5s
current_available=$(kubectl get deployment container -o "jsonpath={.status.availableReplicas}" )
if [ "$current_available" != '' ]; then
available=$current_available
fi
echo "available replicas: ${available}"
done
echo "deployment complete."
}
function scale_deployment()
{
desired_replicas=$1
kubectl scale deployment container --replicas "$desired_replicas"
echo "Scaled the deployment to $desired_replicas"
}
function repeat_deployment() {
echo "Total num of run $total_num_of_run"
for ((i=1; i <= total_num_of_run; i++))
do
echo "Current Run: $i"
echo "Scaling down pods to : $scale_down_pods"
scale_deployment $scale_down_pods
check_deployment $scale_down_pods
echo "Scaling pods to : $scale_up_of_pods"
scale_deployment "$scale_up_of_pods"
check_deployment "$scale_up_of_pods"
done
}
while getopts ":h:n:u:sc" option; do
case $option in
h) help
exit;;
n) total_num_of_run=$OPTARG;;
u) scale_up_of_pods=$OPTARG;;
s) echo "Scale deployment"
scale_deployment "$scale_up_of_pods";;
c) echo "Check deployment"
check_deployment "$scale_up_of_pods";;
\?) echo "Error: Invalid option"
exit;;
esac
done
if [ "$total_num_of_run" -gt 0 ]; then
repeat_deployment
fi