USING KUBERNETES TO DEPLOY DJANGO IN GCP
BY WALTER
INTRODUCTION
ME
▸ FB: Walter Liu
▸
▸
▸ /
▸
Based on a true story
No computer was harmed during the process.
GAME GO PRODUCTION TOMORROW. LET’S INCREASE SIZE OF THE CLUSTER
REAL STORY
ASIA-EAST1-C IS FULL.
REAL STORY
WHAT? MY WHOLE CLUSTER IS IN ASIA-EAST1-C !!!
REAL STORY
K8S + GCP COME TO RESCUE
USING KUBERNETES
K8S + GCP
▸ Infrastructure as code
▸ Record cluster creation steps
▸ Automation scripts for daily jobs
▸ Note: Puppet/Chef/Ansible/Saltstack is not needed for current application
▸ GCP: easy K8S hosting and cluster is free under 5 VMs.
USING KUBERNETES
USED K8S COMPONENTS
▸ POD
▸ Deployment
▸ Statefulset
▸ Secrets/ConfigMap
▸ Endpoints
▸ Service
▸ Ingress
USING KUBERNETES
POD
▸ one POD could contain multiple containers.
▸ Nginx+uwsgi+django
▸ cloudsql-proxy
▸ twemproxy
▸ telegraf
▸ Share
▸ IP
▸ networking space
▸ shared volumes
USING KUBERNETES
DEPLOYMENT
▸ POD template
▸ Desired state instead of changing property
▸ replicas: number of POD
▸ image: the container image
▸ the version of the application
▸ health check for auto-restart POD
USING KUBERNETES
STATEFULSET
▸ Like deployment with static POD name
▸ prod-nimo-kvs-0
▸ prod-nimo-kvs-1
▸ Usage: Sharded service
▸ redis
▸ memcached
▸ Other usage: static volume
USING KUBERNETES
SECRETES/CONFIGMAP
▸ Usage: environment variables for Django settings
▸ No git for secretes
USING KUBERNETES
ENDPOINTS
▸ Usage: IPs of external resources
USING KUBERNETESTEXT
SERVICE
▸ K8S Internal service
▸ External service
▸ TCP Load Balancer
▸ [optional] Firewall
▸ *Global Load Balancer
▸ with Ingress
USING KUBERNETES
INGRESS
▸ Global Load Balancer
▸ No firewall ability
Ingress
Service
Deployment/POD Statefulset/POD GCP Cloud SQL
Service Service/Endpoints
USING KUBERNETES
K8S HAS NO CRONTAB
▸ Use celery
▸ Google App Engine
USING KUBERNETES
K8S+GCP LOAD BALANCER
▸ GCP Global Load Balancer
▸ GCP TCP Load Balancer
▸ GCP Internal Load Balancer (1.7 beta support)
▸ K8S Internal Load Balancer
USING KUBERNETES
CLUSTER CREATION STEPS
▸ kubectl create -f web_secretes.yaml
▸ kubectl apply -f cache_stateful_set.yaml
▸ ./titan_control deploy prod
▸ Like => kubectl apply -f prod_web_deploy.yaml
▸ kubectl apply -f service.yaml
▸ kubectl apply -f ingress.yaml
▸ gsutil mb -l asia gs://static.example.com
NEW CLUSTER CREATED IN 30 MINUTES
REAL STORY
OTHERS
TEMPLATING ▸ I use Python Jinjia to do K8S templating.
▸ Someone had suggested me HELM.
▸ Show Templating example.
WE ARE HIRING
▸
▸
▸ 8
▸ MIS/
▸ PHP
FB GCPUG + Walter Liu
▸
▸ PHP
▸ Docker
▸ Kubernetes
▸ Google Cloud
▸ git
▸ mix of Scrum/Kanban
▸ Trello/Slack
PICAXXXX@GMAIL DOT COM
Walter Liu
Q & A