4. Agenda
The Monolith
What is the Monolith and why is it bad?
Breaking The Monolith into Microservices
Why Microservices is the way to go?
Problems with Microservices
Exchanging one set of problems with another?
Containers and Kubernetes
What are containers and Kubernetes, how do they help?
Kubernetes building blocks
Pods, services, replication controllers/set and more
@meteatamel
7. Confidential & ProprietaryGoogle Cloud Platform 7
Problems with the Monolith
Unnecessary tight coupling among different modules
All at once, or none at all update policy
Hard to scale different parts independently
Ignores different development velocity of different teams completely
Hard to establish ownership of the whole system as it’s huge
Hard to debug and test in general, hard to run on a single development machine
@meteatamel
9. Confidential & ProprietaryGoogle Cloud Platform 9
The Monolith to Microservices
@meteatamel
Microservice1
DB1
Microservice2
DB2
Microservice3
DB3
10. Confidential & ProprietaryGoogle Cloud Platform 10
Problems with Microservices
Need to worry about multiple independent systems instead of one
Can be hard to debug and test across multiple services without proper logging
“But it works on my machine!” problem still applies
Common maintenance problems still apply: Redundancy, resilience, rolling
upgrades, rolling downgrades
@meteatamel
12. Confidential & ProprietaryGoogle Cloud Platform 12
Quick recap of Containers
@meteatamel
Lightweight
Hermetically sealed
Isolated
Easily deployable
Introspectable
Runnable
Linux processes
Improves overall developer experience
Fosters code and component reuse
Simplifies operations for cloud native applications
Docker
13. Confidential & ProprietaryGoogle Cloud Platform 13
Everything at Google runs on containers
Gmail, Web Search, Maps, ...
MapReduce, batch, ...
GFS, Colossus, ...
Google’s Cloud Platform: VMs run in containers!
We launch over 2 billion containers per week
14. Confidential & ProprietaryGoogle Cloud Platform 14
Containers are great but not enough
Containers help to create a lightweight and consistent environment for apps
But it does not solve common app management problems:
● Deploy your a new version of your app reliably
● Create resiliency
● Scale up and down
● Rollback a deployment
● Health checks
● Graceful shutdown
● Etc. etc. etc.
@meteatamel
15. Confidential & ProprietaryGoogle Cloud Platform 15
Kubernetes comes to rescue
http://kubernetes.io
Open source container management platform
Based on years of experience running Borg at Google
Runs everywhere: your laptop, on-prem, different cloud platforms
Helps with reliable deployment of apps, scaling, roll out and roll back of versions,
autoscaling, health checks and more!
@meteatamel
16. Confidential & ProprietaryGoogle Cloud Platform 16
Kubernetes Cluster
@meteatamel
K8s Master
API Server
Dash Board
scheduler
Kubelet Kubelet Kubelet Kubelet
Container
Registry
etcdControllers
web browsers
kubectl
web browsers
Config
file
Image
17. Confidential & ProprietaryGoogle Cloud Platform 17
Kubernetes Cluster
@meteatamel
K8s Master
API Server
Dash Board
scheduler
Kubelet Kubelet Kubelet Kubelet
etcdControllers
web browsers
kubectl
web browsers
Config
file
Image
Container
Registry
20. Confidential & ProprietaryGoogle Cloud Platform 20
Pods
@meteatamel
The atom of scheduling for containers
Represents an application specific logical
host
Hosts containers and volumes
Each has its own routable (no NAT) IP
address
Ephemeral
• Pods are functionally identical and therefore
ephemeral and replaceable
Pod
Web Server
Volume
Consumers
21. Confidential & ProprietaryGoogle Cloud Platform 21
Pods
@meteatamel
Pod
Git
Synchronizer
Node.js App
Container
Volume
Consumersgit Repo
Can be used to group multiple containers &
shared volumes
Containers within a pod are tightly coupled
Shared namespaces
• Containers in a pod share IP, port and IPC
namespaces
• Containers in a pod talk to each other through
localhost
22. Confidential & ProprietaryGoogle Cloud Platform 22
Pods
@meteatamel
Pods have IPs which are routable
Pods can reach each other without NAT
Even across nodes
No Brokering of Port Numbers
These are fundamental requirements
Many solutions
GCE Advanced Routes, AWS Flannel,
Weave, OpenVSwitch, Cloud Provider
10.1.2.0/24
10.1.1.0/24
10.1.1.211 10.1.1.2
10.1.2.106
10.1.3.0/24
10.1.3.4510.1.3.17
10.1.3.0/24
23. Confidential & ProprietaryGoogle Cloud Platform 23
Labels
@meteatamel
Pod
Pod
frontend
Pod
frontend
Pod Pod
type = FE
version = v2
type = FE version = v2
● Metadata with semantic meaning
● Membership identifier
● The only Grouping Mechanism
Behavior Benefits
➔ Allow for intent of many users (e.g. dashboards)
➔ Build higher level systems …
➔ Queryable by Selectors
Dashboard
selector:
type = FE
Dashboard
selector:
version = v2
24. Confidential & ProprietaryGoogle Cloud Platform 24
Label Expressions
@meteatamel
Pod
Pod
frontend
Pod
frontend
Pod Pod
env = qa env = test
● env = prod
● tier != backend
● env = prod, tier !=backend
Expressions
● env in (test,qa)
● release notin (stable,beta)
● tier
● !tier
env = prod
Pod
env = prod
Dashboard
selector:
env = notin(prod)
25. Confidential & ProprietaryGoogle Cloud Platform 25
Services
@meteatamel
Client
Pod
Container
Pod
Container
Pod
Container
A logical grouping of pods that perform the
same function (the Service’s endpoints)
• grouped by label selector
Load balances incoming requests across
constituent pods
Choice of pod is random but supports
session affinity (ClientIP)
Gets a stable virtual IP and port
• also a DNS nametype =
Service
Label selector:
type = FE
VIP
type = FE type = FE type = FE
26. Confidential & ProprietaryGoogle Cloud Platform 26
Replication Controllers/Sets
@meteatamel
Replication
Controller Pod
frontend
Pod
frontend
app = demo app = demo app = demo
ReplicaSet
#pods = 3
app = demo
color in (blue,grey)
show: version = v2
color = blue color = blue color = grey
Behavior Benefits
● Keeps Pods running
● Gives direct control of Pod #s
● Grouped by Label Selector
➔ Recreates Pods, maintains desired state
➔ Fine-grained control for scaling
➔ Standard grouping semantics
Pod Pod Pod
27. Confidential & ProprietaryGoogle Cloud Platform 27
Replication Controllers/Sets
@meteatamel
ReplicaSet
- Name = “backend”
- Selector = {“name”: “backend”}
- Template = { ... }
- NumReplicas = 4
API Server
3
Start 1
more
OK 4
How
many?
How
many?
Canonical example of control loops
Have one job: ensure N copies of a pod
● if too few, start new ones
● if too many, kill some
● group == selector
Replicated pods are fungible
● No implied order or identity
28. Confidential & ProprietaryGoogle Cloud Platform 28
Scaling
@meteatamel
Service
Label selectors:
version = 1.0
type = Frontend
Service
name = frontend
Label selector:
type = BE
Replication
Controller Pod
frontend
Pod
version= v1 version = v1
ReplicaSet
version = v1
#pods = 1
show: version = v2
type = FE type = FE
Pod
frontend
Pod
version = v1
type = FE
ReplicaSet
version = v1
#pods = 2
show: version = v2
Pod Pod
ReplicaSet
version = v1
type = FE
#pods = 4
show: version = v2
version = v1
type = FE
29. Confidential & ProprietaryGoogle Cloud Platform 29
Canary
@meteatamel
Service
Label selectors:
version = 1.0
type = Frontend
Service
name = backend
Label selector:
type = BE
Replication
Controller
Pod
Pod
frontend
Pod
version= v1 version = v1
ReplicaSet
version = v1
type = BE
#pods = 2
show: version = v2
type = BE type = BE
Replication
Controller
ReplicaSet
version = v2
type = BE
#pods = 1
show: version = v2
Pod
frontend
Pod
version = v2
type = BE
30. Confidential & ProprietaryGoogle Cloud Platform 30
Autoscaling
@meteatamel
Replication
Controller Pod
frontend
Pod
name=locust name=locust
ReplicaSet
name=locust
role=worker
#pods = 1
show: version = v2
Pod
frontend
Pod
name=locust
ReplicaSet
name=locust
role=worker
#pods = 2
show: version = v2
Pod Pod
name=locust
Scale
CPU Target% = 50
Heapster
role=worker role=worker role=worker role=worker
ReplicaSet
name=locust
role=worker
#pods = 4
70% CPU
40% CPU
> 50% CPU< 50% CPU
31. Confidential & ProprietaryGoogle Cloud Platform 31
Rollout
@meteatamel
API
DeploymentDeployment
Create frontend-1234567
Deployment
Create frontend-1234567
Scale frontend-1234567 up to 1
Deployment
Create frontend-1234567
Scale frontend-1234567 up to 1
Scale frontend-7654321 down to 0
Pod Pod
frontend
Pod
version = v1
ReplicaSet
frontend-1234567
version = v2
type = BE
#pods = 0
show: version = v2
ReplicaSet
frontend-7654321
version = v1
type = BE
#pods = 2
version: v2
ReplicaSet
frontend-7654321
version: v1
type: BE
#pods = 0
version: v1
ReplicaSet
frontend-1234567
version = v2
type = BE
#pods = 1
show: version = v2
ReplicaSet
frontend-1234567
version: v2
type: BE
#pods = 2
type = BE type = BE
Pod
version: v2
type = BE
Servic
e
be-svc
Deployment
Create frontend-1234567
Scale frontend-1234567 up to 1
Scale frontend-7654321 down to 0
Scale frontend-1234567 up to 2
kubectl edit deployment ...