-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Django/Postgres/Redis Container Engine example
- Loading branch information
Bill Prin
committed
Jan 29, 2016
1 parent
b00f1dc
commit 5a89cdb
Showing
33 changed files
with
1,384 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.* | ||
!/.gitignore | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
GCLOUD_PROJECT:=$(shell gcloud config list project --format="value(core.project)") | ||
ZONE=$(shell gcloud config list compute/zone --format="value(compute.zone)") | ||
AUTOSCALE_GROUP=$(shell gcloud container clusters describe $(CLUSTER_NAME) --zone $(ZONE) --format yaml | grep -A 1 instanceGroupUrls | awk -F/ 'FNR ==2 {print $$NF}') | ||
CLUSTER_NAME=guestbook | ||
COOL_DOWN=15 | ||
MIN=2 | ||
MAX=15 | ||
TARGET=50 | ||
RC=frontend | ||
POSTGRES_POD_NAME=$(shell kubectl get pods | grep postgres | awk '{print $$1}') | ||
FRONTEND_POD_NAME=$(shell kubectl get pods | grep frontend -m 1 | awk '{print $$1}' ) | ||
|
||
.PHONY: all | ||
all: deploy | ||
|
||
.PHONY: create-cluster | ||
create-cluster: | ||
gcloud container clusters create guestbook \ | ||
--scope "https://www.googleapis.com/auth/userinfo.email","cloud-platform" \ | ||
--num-nodes=$(MIN) | ||
gcloud container clusters get-credentials guestbook | ||
|
||
.PHONY: create-bucket | ||
create-bucket: | ||
gsutil mb gs://$(GCLOUD_PROJECT) | ||
gsutil defacl set public-read gs://$(GCLOUD_PROJECT) | ||
|
||
.PHONY: template | ||
template: | ||
sed -i ".tmpl" "s/\$$GCLOUD_PROJECT/$(GCLOUD_PROJECT)/g" kubernetes_configs/postgres.yaml | ||
sed -i ".tmpl" "s/\$$GCLOUD_PROJECT/$(GCLOUD_PROJECT)/g" kubernetes_configs/frontend.yaml | ||
sed -i ".tmpl" "s/\$$GCLOUD_PROJECT/$(GCLOUD_PROJECT)/g" kubernetes_configs/load_tester.yaml | ||
|
||
.PHONY: deploy | ||
deploy: push template | ||
kubectl create -f kubernetes_config/frontend.yaml | ||
|
||
.PHONY: update | ||
update: | ||
kubectl rolling-update guestbook --image=gcr.io/${GCLOUD_PROJECT}/guestbook | ||
|
||
.PHONY: disk | ||
disk: | ||
gcloud compute disks create pg-data --size 500GB | ||
|
||
.PHONY: firewall | ||
firewall: | ||
gcloud compute firewall-rules create kubepostgres --allow tcp:30061 | ||
|
||
.PHONY: autoscale-on | ||
autoscale-on: | ||
gcloud compute instance-groups managed set-autoscaling $(AUTOSCALE_GROUP) \ | ||
--cool-down-period $(COOL_DOWN) \ | ||
--max-num-replicas $(MAX) \ | ||
--min-num-replicas $(MIN) \ | ||
--scale-based-on-cpu --target-cpu-utilization $(shell echo "scale=2; $(TARGET)/100" | bc) | ||
kubectl autoscale rc $(RC) --min=$(MIN) --max=$(MAX) --cpu-percent=$(TARGET) | ||
|
||
.PHONY: db-setup | ||
db-setup: | ||
kubectl exec $(POSTGRES_POD_NAME) -- /init_db.sh | ||
|
||
.PHONY: migrations | ||
migrations: | ||
kubectl exec $(FRONTEND_POD_NAME) -- python /app/manage.py migrate | ||
|
||
|
||
.PHONY: delete | ||
delete: | ||
gcloud container clusters delete guestbook | ||
gcloud compute disks delete pg-data |
Oops, something went wrong.