Created
April 19, 2017 21:54
-
-
Save tpryan/b912f9865693703ef44a57abcbc6687d to your computer and use it in GitHub Desktop.
Kubernetes Makefile
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
apiVersion: extensions/v1beta1 | |
kind: Deployment | |
metadata: | |
name: api-deployment | |
spec: | |
replicas: 3 | |
strategy: | |
type: RollingUpdate | |
template: | |
metadata: | |
labels: | |
layer: api | |
spec: | |
containers: | |
- name: "api" | |
image: "gcr.io/[your projectid]/locations-api" | |
ports: | |
- name: "http" | |
containerPort: 80 | |
protocol: TCP |
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
apiVersion: v1 | |
kind: Service | |
metadata: | |
labels: | |
name: api | |
name: api | |
spec: | |
type: LoadBalancer | |
ports: | |
# The port that this service should serve on. | |
- port: 80 | |
targetPort: 80 | |
protocol: TCP | |
# Label keys and values that must match in order to receive traffic for this service. | |
selector: | |
layer: api |
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
apiVersion: v1 | |
kind: Service | |
metadata: | |
labels: | |
name: mysql | |
name: mysql | |
spec: | |
ports: | |
# The port that this service should serve on. | |
- port: 3306 | |
# Label keys and values that must match in order to receive traffic for this service. | |
selector: | |
layer: db |
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
apiVersion: apps/v1beta1 | |
kind: StatefulSet | |
metadata: | |
name: db-set | |
spec: | |
serviceName: "mysql" | |
replicas: 1 | |
template: | |
metadata: | |
labels: | |
layer: db | |
spec: | |
terminationGracePeriodSeconds: 0 | |
containers: | |
- name: db | |
image: "gcr.io/[your projectid]/locations-db" | |
env: | |
- name: MYSQL_ALLOW_EMPTY_PASSWORD | |
value: "yes" | |
ports: | |
- containerPort: 3306 | |
name: mysql | |
volumeMounts: | |
- name: mysql-pvc | |
mountPath: /var/lib/mysql | |
volumeClaimTemplates: | |
- metadata: | |
name: mysql-pvc | |
annotations: | |
volume.alpha.kubernetes.io/storage-class: anything | |
spec: | |
accessModes: [ "ReadWriteOnce" ] | |
resources: | |
requests: | |
storage: 1Gi |
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
apiVersion: extensions/v1beta1 | |
kind: Deployment | |
metadata: | |
name: frontend-deployment | |
spec: | |
replicas: 4 | |
strategy: | |
type: RollingUpdate | |
template: | |
metadata: | |
labels: | |
layer: ui | |
spec: | |
containers: | |
- name: "frontend" | |
image: "gcr.io/[your projectid]/locations-frontend" | |
ports: | |
- name: "http" | |
containerPort: 80 | |
protocol: TCP |
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
apiVersion: v1 | |
kind: Service | |
metadata: | |
labels: | |
name: frontend | |
name: frontend | |
spec: | |
type: LoadBalancer | |
ports: | |
# The port that this service should serve on. | |
- port: 80 | |
targetPort: 80 | |
protocol: TCP | |
# Label keys and values that must match in order to receive traffic for this service. | |
selector: | |
layer: ui |
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
BASEDIR = $(shell pwd) | |
RULELIST = $(shell gcloud compute forwarding-rules list --format='value[terminator=" "](name)') | |
include Makefile.properties | |
all: cluster app | |
app: db api frontend | |
# Requests a GKE cluster | |
cluster: | |
-gcloud container clusters create $(CLUSTER) --num-nodes $(NODECOUNT) \ | |
--disk-size=$(NODEDISKSIZE) --machine-type=$(NODETYPE) | |
cluster.clean: | |
-gcloud container clusters delete $(CLUSTER) -q | |
pvc.clean: | |
-kubectl delete pvc mysql-pvc-db-set-0 | |
update: api.reset frontend.reset | |
deploy: app.only | |
# Completely obliterates everything. | |
clean: | |
-kubectl delete -f frontend-service.yaml | |
-kubectl delete -f api-service.yaml | |
-kubectl delete -f db-statefulset.yaml | |
-kubectl delete pvc mysql-pvc-db-set-0 | |
-kubectl delete -f db-service.yaml | |
-kubectl delete -f api-deployment.yaml | |
-kubectl delete -f frontend-deployment.yaml | |
sleep 10 | |
-gcloud container clusters delete $(CLUSTER) -q | |
# only gets rid of the container pieces | |
teardown: frontend.teardown api.teardown db.teardown rules.teardown | |
rules.teardown: | |
-gcloud compute forwarding-rules delete $(RULELIST) --region $(REGION) -q | |
app.only: db.service api.service frontend.service db.set api.deployment frontend.deployment | |
app.clean: db.clean api.clean frontend.clean | |
api.teardown: | |
-kubectl delete -f api-deployment.yaml | |
-kubectl delete -f api-service.yaml | |
api.delete.deployment: | |
-kubectl delete -f api-deployment.yaml | |
api.service: | |
kubectl create -f api-service.yaml | |
api.deployment: | |
-kubectl create -f api-deployment.yaml | |
api: api.image api.deployment api.service | |
api.image: api.image.stage api.image.build api.image.unstage | |
api.clean: api.image.unstage | |
api.reset: api.delete.deployment api.image api.deployment | |
api.image.build: | |
docker build -t gcr.io/$(PROJECT)/locations-api "$(BASEDIR)/../containers/api/." | |
gcloud docker push gcr.io/$(PROJECT)/locations-api | |
api.image.stage: | |
cp -R "$(BASEDIR)/../../../code/app" "$(BASEDIR)/../containers/api" | |
rm -rf "$(BASEDIR)/../containers/api/app/ui" | |
rm -rf "$(BASEDIR)/../containers/api/app/static" | |
api.image.unstage: | |
rm -rf "$(BASEDIR)/../containers/api/app" | |
db.teardown: | |
-kubectl delete -f db-statefulset.yaml | |
-kubectl delete -f db-service.yaml | |
db: db.image db.set db.service | |
db.service: | |
kubectl create -f db-service.yaml | |
db.set: | |
kubectl create -f db-statefulset.yaml | |
db.image: db.image.stage db.image.build db.image.unstage | |
db.clean: db.image.unstage | |
db.reset: db.teardown pvc.clean db | |
db.image.build: | |
docker build -t gcr.io/$(PROJECT)/locations-db "$(BASEDIR)/../containers/db/." | |
gcloud docker push gcr.io/$(PROJECT)/locations-db | |
db.image.stage: | |
cp -R "$(BASEDIR)/../../../code/sql" "$(BASEDIR)/../containers/db" | |
cat "$(BASEDIR)/../containers/db/sql/base_schema.sql" > "$(BASEDIR)/../containers/db/sql/load.sql" | |
cat "$(BASEDIR)/../containers/db/sql/starting_data.sql" >> "$(BASEDIR)/../containers/db/sql/load.sql" | |
cat "$(BASEDIR)/../containers/db/sql/creds.sql" >> "$(BASEDIR)/../containers/db/sql/load.sql" | |
db.image.unstage: | |
rm -rf "$(BASEDIR)/../containers/db/sql" | |
frontend: frontend.image frontend.deployment frontend.service | |
frontend.teardown: | |
-kubectl delete -f frontend-deployment.yaml | |
-kubectl delete -f frontend-service.yaml | |
frontend.reset: frontend.delete.deployment frontend.image frontend.deployment | |
frontend.delete.deployment: | |
-kubectl delete -f frontend-deployment.yaml | |
frontend.service: | |
kubectl create -f frontend-service.yaml | |
frontend.deployment: | |
kubectl create -f frontend-deployment.yaml | |
frontend.image: frontend.image.stage frontend.image.build frontend.image.unstage | |
frontend.clean: frontend.image.unstage | |
frontend.image.build: | |
docker build -t gcr.io/$(PROJECT)/locations-frontend "$(BASEDIR)/../containers/frontend/." | |
gcloud docker push gcr.io/$(PROJECT)/locations-frontend | |
frontend.image.stage: | |
cp -R "$(BASEDIR)/../../../code/app/ui" "$(BASEDIR)/../containers/frontend" | |
cp -R "$(BASEDIR)/../../../code/app/static" "$(BASEDIR)/../containers/frontend" | |
frontend.image.unstage: | |
rm -rf "$(BASEDIR)/../containers/frontend/ui" | |
rm -rf "$(BASEDIR)/../containers/frontend/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
PROJECT=[your project id] | |
REGION=us-central1 | |
ZONE=us-central1-c | |
MYSQL_ROOTPASS=[password] | |
MYSQL_ROOTHASH=[hash of what is above] | |
MYSQL_HOSTNAME=locations-lamp | |
NODEDISKSIZE="200" | |
NODECOUNT="2" | |
NODETYPE=g1-small | |
CLUSTER=location-cluster | |
GCS_DOMAIN=[a domain for your bucket] | |
env: | |
gcloud config set project $(PROJECT) | |
gcloud config set compute/zone $(ZONE) | |
creds: | |
gcloud container clusters get-credentials $(CLUSTER) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment