Skip to content

Commit

Permalink
Add Django/Postgres/Redis Container Engine example
Browse files Browse the repository at this point in the history
  • Loading branch information
Bill Prin committed Jan 29, 2016
1 parent b00f1dc commit a7d95ed
Show file tree
Hide file tree
Showing 33 changed files with 1,380 additions and 0 deletions.
3 changes: 3 additions & 0 deletions container_engine/django_postgres_redis/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.*
!/.gitignore

71 changes: 71 additions & 0 deletions container_engine/django_postgres_redis/Makefile
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
Loading

0 comments on commit a7d95ed

Please sign in to comment.