using kubernetes to deploy django in gcp

28
USING KUBERNETES TO DEPLOY DJANGO IN GCP BY WALTER

Upload: walter-liu

Post on 28-Jan-2018

751 views

Category:

Software


3 download

TRANSCRIPT

Page 1: Using Kubernetes to deploy Django in GCP

USING KUBERNETES TO DEPLOY DJANGO IN GCP

BY WALTER

Page 2: Using Kubernetes to deploy Django in GCP

INTRODUCTION

ME

▸ FB: Walter Liu

▸ /

Page 3: Using Kubernetes to deploy Django in GCP

Based on a true story

No computer was harmed during the process.

Page 4: Using Kubernetes to deploy Django in GCP

GAME GO PRODUCTION TOMORROW. LET’S INCREASE SIZE OF THE CLUSTER

REAL STORY

Page 5: Using Kubernetes to deploy Django in GCP

ASIA-EAST1-C IS FULL.

REAL STORY

Page 6: Using Kubernetes to deploy Django in GCP

WHAT? MY WHOLE CLUSTER IS IN ASIA-EAST1-C !!!

REAL STORY

Page 7: Using Kubernetes to deploy Django in GCP

K8S + GCP COME TO RESCUE

Page 8: Using Kubernetes to deploy Django in GCP

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.

Page 9: Using Kubernetes to deploy Django in GCP

USING KUBERNETES

USED K8S COMPONENTS

▸ POD

▸ Deployment

▸ Statefulset

▸ Secrets/ConfigMap

▸ Endpoints

▸ Service

▸ Ingress

Page 10: Using Kubernetes to deploy Django in GCP

USING KUBERNETES

POD

▸ one POD could contain multiple containers.

▸ Nginx+uwsgi+django

▸ cloudsql-proxy

▸ twemproxy

▸ telegraf

▸ Share

▸ IP

▸ networking space

▸ shared volumes

Page 11: Using Kubernetes to deploy Django in GCP

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

Page 12: Using Kubernetes to deploy Django in GCP

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

Page 13: Using Kubernetes to deploy Django in GCP

USING KUBERNETES

SECRETES/CONFIGMAP

▸ Usage: environment variables for Django settings

▸ No git for secretes

Page 14: Using Kubernetes to deploy Django in GCP

USING KUBERNETES

ENDPOINTS

▸ Usage: IPs of external resources

Page 15: Using Kubernetes to deploy Django in GCP

USING KUBERNETESTEXT

SERVICE

▸ K8S Internal service

▸ External service

▸ TCP Load Balancer

▸ [optional] Firewall

▸ *Global Load Balancer

▸ with Ingress

Page 16: Using Kubernetes to deploy Django in GCP

USING KUBERNETES

INGRESS

▸ Global Load Balancer

▸ No firewall ability

Page 17: Using Kubernetes to deploy Django in GCP

Ingress

Service

Deployment/POD Statefulset/POD GCP Cloud SQL

Service Service/Endpoints

Page 18: Using Kubernetes to deploy Django in GCP

USING KUBERNETES

K8S HAS NO CRONTAB

▸ Use celery

▸ Google App Engine

Page 19: Using Kubernetes to deploy Django in GCP

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

Page 20: Using Kubernetes to deploy Django in GCP

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

Page 21: Using Kubernetes to deploy Django in GCP

NEW CLUSTER CREATED IN 30 MINUTES

REAL STORY

Page 22: Using Kubernetes to deploy Django in GCP

OTHERS

TEMPLATING ▸ I use Python Jinjia to do K8S templating.

▸ Someone had suggested me HELM.

▸ Show Templating example.

Page 23: Using Kubernetes to deploy Django in GCP
Page 24: Using Kubernetes to deploy Django in GCP

WE ARE HIRING

▸ 8

▸ MIS/

▸ PHP

FB GCPUG + Walter Liu

Page 25: Using Kubernetes to deploy Django in GCP

Page 26: Using Kubernetes to deploy Django in GCP

▸ PHP

▸ Docker

▸ Kubernetes

▸ Google Cloud

▸ git

▸ mix of Scrum/Kanban

▸ Trello/Slack

Page 27: Using Kubernetes to deploy Django in GCP

PICAXXXX@GMAIL DOT COM

Walter Liu

Page 28: Using Kubernetes to deploy Django in GCP

Q & A