-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathk8s.sh
executable file
·59 lines (49 loc) · 1.34 KB
/
k8s.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
#!/bin/bash
[[ -z $STAGE ]] && echo "Missing STAGE" && exit 1
[[ -z $SLUG ]] && echo "Missing SLUG" && exit 1
# Create vars
BASEDIR=$(dirname "$0")
NAME=$(echo "${STAGE}" | tr '[:upper:]' '[:lower:]')
NAMESPACE="${NAME}"
# Update config
aws eks update-kubeconfig --name "$NAME"
secrets () {
# Create secrets
kubectl -n "$NAMESPACE" create secret generic "${SLUG}"-secrets \
--from-env-file=<(aws secretsmanager get-secret-value --secret-id "${SLUG}"-secrets | jq -r .SecretString | jq -r 'to_entries | .[] | .key + "=" + .value') \
--dry-run=client -o yaml |
kubectl apply -f -
}
config () {
# Apply config map
envsubst <"$BASEDIR"/config.yml | kubectl apply -n "$NAMESPACE" -f -
}
deploy () {
# Required to substitute variables in k8s.yml
[[ -z $HOST ]] && echo "Missing HOST" && exit 1
[[ -z $PORT ]] && echo "Missing PORT" && exit 1
[[ -z $MEMORY_LIMIT ]] && echo "Missing MEMORY_LIMIT" && exit 1
[[ -z $MEMORY_REQUESTS ]] && echo "Missing MEMORY_REQUESTS" && exit 1
[[ -z $AWS_ECR_URL ]] && echo "Missing AWS_ECR_URL" && exit 1
envsubst <"$BASEDIR"/k8s.yml | kubectl apply -n "$NAMESPACE" -f -
}
restart () {
kubectl rollout restart deployment -n "$NAMESPACE" "$SLUG"
}
case $1 in
"secrets")
secrets
;;
"config")
config
;;
"deploy")
deploy
;;
"restart")
restart
;;
*)
exit 1;
;;
esac