-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathMakefile
210 lines (177 loc) · 6.91 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
###################
## Customization ##
###################
# Change here or use environment variables, e.g. export AWS_PROFILE=<aws profile name>.
# Default SHELL for make for consistency on different platforms
SHELL := /bin/bash
ROOT_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
# When destroy-all runs, the resources on this list will be destroyed, in this order.
ALL_RESOURCES := node master etcd iam pki vault route53 s3 vpc
export
.PHONY: help
help:
@# adapted from https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
@echo '_________________'
@echo '| Make targets: |'
@echo '-----------------'
@cat $(shell pwd)/Makefile | grep -E '^[a-zA-Z_-]+:.*?## .*$$' | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | sort -k1,1
.PHONY: core master node
cluster: core master node ## Create or update a kubernetes cluster (include core, masters and nodes)
.PHONY: vpc s3 route53 iam pki vault etcd
core: vpc s3 route53 iam pki vault etcd ## Create or update vpc, s3, route 53, iam, pki, vault, and etcd.
.PHONY: master plan-master show-master destory-master
master: etcd ## Create or update masters
cd resources/master; make apply
plan-master: ## plan master resources
cd resources/master; make plan
show-master: ## Show master resources
cd resources/master; make show
destroy-master: ## Destroy masters
cd resources/master; make destroy
.PHONY: etcd plan-etcd show-etcd destroy-etcd
etcd: iam vault vpc ## Create or update etcd cluster
cd resources/etcd; make apply
plan-etcd: ## Generate etcd cluster Terraform plan (dry-run)
cd resources/etcd; make plan
show-etcd: ## Show etcd cluster resources
cd resources/etcd; make show
destroy-etcd: destroy-node ## Destroy node and etcd cluster
cd resources/etcd; make destroy
.PHONY: iam destroy-iam
iam: s3 ## Create or update IAM and S3 buckets
cd resources/iam; make apply
destroy-iam: destroy-etcd ## Destroy IAM and its dependencies
cd resources/iam; make destroy
.PHONY: pki s3
pki: s3 ## Create or update Vault PKI backend
cd resources/pki; make apply
destroy-pki: ## Destroy Vault PKI backend.
cd resources/pki; make destroy
.PHONY: route53 show-route53 destroy-route53
route53: vpc ## Create or update Route53 zone
cd resources/route53; make apply
show-route53: ## Show Route53 resource
cd resources/route53; make show
destroy-route53: ## Destroy Route53 Zone
cd resources/route53; make destroy
.PHONY: s3 destroy-s3
s3: ## Create or update S3 buckets
cd resources/s3; make apply
destroy-s3: ## Destroy S3 buckets
cd resources/s3; make destroy
.PHONY: vault plan-vault show-vault destroy-vault
vault: vpc iam pki route53 ## Create or updat Vault server
cd resources/vault; make apply
plan-vault: ## Generate Vault Terraform plan
cd resources/vault; make plan
show-vault: ## Show Vault resource
cd resources/vault; make show
destroy-vault: ## Destroy Vault
cd resources/vault; make destroy
.PHONY: vpc plan-vpc show-vpc destory-vpc
vpc: ## Create or upate VPC, gateways, routing tables, subnets
cd resources/vpc; make apply
plan-vpc: ## Generate VPC Terraform plan
cd resources/vpc; make plan
show-vpc: ## Show VPC and subnets resources
cd resources/vpc; make show
destroy-vpc: destroy-s3 ## Destroy VPC
cd resources/vpc; make destroy
.PHONY: node show-node plan-node destroy-node
node: etcd ## Create or udpate nodes
cd resources/node; make apply
show-node: ## Show node resource
cd resources/node; make show
plan-node: ## Generate node Terraform plan
cd resources/node; make plan
destroy-node: ## Destroy node
cd resources/node; make destroy
.PHONY: plan-destroy-all
plan-destroy-all: ## Generate destroy plan of all resources
@rm -rf /tmp/destroy.err
@$(foreach resource,$(ALL_RESOURCES),cd $(ROOT_DIR)/resources/$(resource) && $(MAKE) destroy-plan 2> /tmp/destroy.err;)
.PHONY: confirm
confirm:
@echo "CONTINUE? [Y/N]: "; read ANSWER; \
if [ ! "$$ANSWER" = "Y" ]; then \
echo "Exiting." ; exit 1 ; \
fi
.PHONY: teardown
teardown:
@-cd ${ROOT_DIR}/apps/gitlab; ./teardown.sh
@-cd ${ROOT_DIR}/apps/nginx-test; ./teardown.sh
$(MAKE) destroy-add-ons
$(MAKE) destroy-all
.PHONY: destroy-all
destroy-all: plan-destroy-all ## Destroy all resources
@rm -f /tmp/destroy_plan
@$(foreach resource,$(ALL_RESOURCES),cd $(ROOT_DIR)/resources/$(resource) && $(MAKE) show-destroy-plan >> /tmp/destroy_plan;)
@cat /tmp/destroy_plan | grep -v data.terraform | grep -v data.aws
@echo ""
@echo "Will destroy these resources. Please confirm."
@$(MAKE) confirm
@$(foreach resource,$(ALL_RESOURCES),cd $(ROOT_DIR)/resources/$(resource) && $(MAKE) destroy 2> /tmp/destroy.err;)
@$(MAKE) destroy-remote
.PHONY: destroy-remote
destroy-remote: # Destroy Terraform remote state, as final cleanup
@echo "Destroy Terraform remote state?"
@echo "This will destroy remote state for each module, all remote state versions, and delete the bucket"
@$(MAKE) confirm
@cd resources/vpc; $(MAKE) force-destroy-remote
.PHONY: show-all
show-all: ## Show all resources
@$(foreach resource,$(ALL_RESOURCES),cd $(ROOT_DIR)/resources/$(resource) && $(MAKE) show 2> /tmp/destroy.err;)
.PHONY: update-kube
update-kube: ## Update Kubernetes cluster
@cd resources/master; make update
@cd resources/node; make update
.PHONY: update-vault
update-vault: ## Upgrade vault
@cd resources/vault; make update
# Extras
.PHONY: add-ons
add-ons: ## Kubernetes add-ons, e.g. dns, dashboard
cd resources/add-ons; make add-ons
.PHONY: ui
ui: ## Open dashboard UI in browser
cd resources/add-ons; make ui
.PHONY: metrics
metrics: ## Open Granfana UI in browser
cd resources/add-ons; make metrics
.PHONY: kill-ui
kill-ui: ## Close dashboard UI connection
cd resources/add-ons; make kill-ui
.PHONY: kill-metrics
kill-metrics: ## Close Granfana UI connection
cd resources/add-ons; make kill-metrics
.PHONY: get-apiserver-elb
get-apiserver-elb: ## Get API server ELB address
cd resources/master; make get-apiserver-elb
.PHONY: destroy-add-ons
destroy-add-ons: ## Delete all add-ons, ie. kubedns, dashboard, and monitor
cd resources/add-ons; make kube-cleanup
.PHONY: sync-docker-time
# see https://github.com/docker/for-mac/issues/17#issuecomment-236517032
sync-docker-time: ## sync docker vm time with hardware clock
@docker run --rm --privileged alpine hwclock -s
.PHONY: kube-config kube-reconfig
kube-config: ## config kubectl
cd resources/add-ons; make kube-config
kube-reconfig: ## reconfig kubectl
cd resources/add-ons; make kube-reconfig
.PHONY: validate
validate: ## Validate kube servies on master and nodes
@make validate-master
@make validate-node
@kubectl get nodes
.PHONY:
validate-master: ## Valiate kube master daemon status
@echo Vaidating master kube processes
@cd resources/master; \
make remote-cmd "cd /etc/systemd/system; systemctl status kube-* kubelet |grep -B 2 Active"
.PHONY:
validate-node: ## Valiate kube node daemon status
@echo Validating nodes kube processes
@cd resources/node; \
make remote-cmd "cd /etc/systemd/system; systemctl status kube-* kubelet |grep -B 2 Active"