-
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
Feb 1, 2016
1 parent
b00f1dc
commit 2c4985e
Showing
33 changed files
with
1,385 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 @@ | ||
.env | ||
guestbook/static | ||
|
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)") | ||
CLUSTER_NAME=guestbook | ||
COOL_DOWN=15 | ||
MIN=2 | ||
MAX=15 | ||
TARGET=50 | ||
RC=frontend | ||
|
||
.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: | ||
AUTOSCALE_GROUP=$(shell gcloud container clusters describe $(CLUSTER_NAME) --zone $(ZONE) --format yaml | grep -A 1 instanceGroupUrls | awk -F/ 'FNR ==2 {print $$NF}') | ||
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: | ||
POSTGRES_POD_NAME=$(shell kubectl get pods | grep postgres | awk '{print $$1}') | ||
kubectl exec $(POSTGRES_POD_NAME) -- /init_db.sh | ||
|
||
.PHONY: migrations | ||
migrations: | ||
FRONTEND_POD_NAME=$(shell kubectl get pods | grep frontend -m 1 | awk '{print $$1}' ) | ||
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.