-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
63 lines (50 loc) · 2.13 KB
/
Makefile
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
NAMESPACE ?= r7-dev-env
MYSQLVOLUMEHOSTPATH ?= $(shell pwd)/_data/mysql
REDISVOLUMEHOSTPATH ?= $(shell pwd)/_data/redis
TIMESTAMP ?= $(shell date +"%Y%m%dT%H%M%S")
MYSQLSNAPSHOT ?= $(shell ls -t _data/_snapshot | grep -m 1 mysql)
.PHONY: help
help:
@echo "===================================================================="
@echo " install install or upgrade the helmchart"
@echo " uninstall uninstall the helmchart"
@echo " snapshot create a snapshot mysql"
@echo " restore restore most recent mysql snapshot"
@echo " update restart all databases to pull new images"
@echo " status check the health of the deployment"
@echo "--------------------------------------------------------------------"
.PHONY: install
install:
helm upgrade --install ${NAMESPACE} ./ \
--namespace ${NAMESPACE} --create-namespace \
--set-string db.mysql.persistentVolumeHostPath=${MYSQLVOLUMEHOSTPATH} \
--set-string db.redis.persistentVolumeHostPath=${REDISVOLUMEHOSTPATH}
.PHONY: uninstall
uninstall:
helm uninstall ${NAMESPACE} --namespace ${NAMESPACE}
.PHONY: status
status:
kubectl get all -n ${NAMESPACE}
.PHONY: snapshot
snapshot: create-snapshot-dir
tar czf _data/_snapshot/mysql-${TIMESTAMP}.tar.gz _data/mysql
create-snapshot-dir:
mkdir -p _data/_snapshot
.PHONY: restore
restore: scale-down-mysql replace scale-up-mysql
@echo "------------------------------------------------------------"
@echo " Snapshot restored from ${MYSQLSNAPSHOT}"
@echo "------------------------------------------------------------"
replace:
rm -rf _data/mysql
tar xzf _data/_snapshot/${MYSQLSNAPSHOT}
scale-down-mysql:
kubectl scale statefulset -n ${NAMESPACE} --replicas=0 ${NAMESPACE}-mysql-stateful-set
scale-up-mysql:
kubectl scale statefulset -n ${NAMESPACE} --replicas=1 ${NAMESPACE}-mysql-stateful-set
.PHONY: update
update: install update-mysql update-redis
update-mysql:
kubectl rollout restart statefulset -n ${NAMESPACE} ${NAMESPACE}-mysql-stateful-set
update-redis:
kubectl rollout restart statefulset -n ${NAMESPACE} ${NAMESPACE}-redis-stateful-set