-
Notifications
You must be signed in to change notification settings - Fork 1
/
scale.sh
executable file
·60 lines (48 loc) · 1.29 KB
/
scale.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
#!/bin/sh -
set -o errexit
if [ $# -ne 1 ]; then
echo "Illegal number of parameters, usage : "
echo " "
echo " $0 <replicas>"
echo " "
echo " examples: "
echo " - $0 5"
echo " - $0 0"
exit 2
fi
KUBECMD="kubectl"
if [ -x "$(command -v microk8s.kubectl)" ]; then
KUBECMD="microk8s.kubectl"
fi
DEPLOYMENT_NAME="movies-spring-web"
WANTED_REPLICAS="$1"
REPLICAS="0"
PREVIOUS_REPLICAS="-1"
replicas() {
REPLICAS=$($KUBECMD get "deployment/$DEPLOYMENT_NAME" -o jsonpath='{.status.readyReplicas}')
if test -z "$REPLICAS"; then
REPLICAS="0"
fi
}
echo "checking deployment: $DEPLOYMENT_NAME"
replicas
if [ "$REPLICAS" -eq "$WANTED_REPLICAS" ]; then
echo "we dont need to scale allready got $REPLICAS replicas ready"
exit 0
fi
echo "scaling deployment: $DEPLOYMENT_NAME to $WANTED_REPLICAS replicas"
$KUBECMD scale "deployment/$DEPLOYMENT_NAME" --replicas "$WANTED_REPLICAS"
START=$(date +%s.%N)
while true; do
if [ "$REPLICAS" != "$PREVIOUS_REPLICAS" ]; then
echo "waiting for scaling: got $REPLICAS replicas, want $WANTED_REPLICAS"
PREVIOUS_REPLICAS="$REPLICAS"
fi
if [ "$REPLICAS" -eq "$WANTED_REPLICAS" ]; then
END=$(date +%s.%N)
DIFF=$(echo "$END - $START" | bc)
echo "scaling complete, $REPLICAS ready, in $DIFF seconds"
exit 0
fi
replicas
done