microservices - jug saxony day · microservices chaos kontrolle mit kubernetes robert kubis -...

49
Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

Upload: others

Post on 06-Jun-2020

10 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

MicroservicesChaos Kontrolle mit Kubernetes

Robert Kubis - Developer Advocate, Google@hostirosti

Page 2: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

2@hostirosti #kubernetesio #googlecloud #jsd2015

Robert KubisDeveloper AdvocateGoogle Cloud PlatformLondon, UK

hostirosti github.com/hostirosti

About me

Page 3: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

Agenda

Motivation (Microservices)

Container Overview

Cluster Management & Kubernetes

Demo

1

2

3

4

Page 4: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

Google Cloud Platform 4

Microservices

Page 5: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

5@hostirosti #kubernetesio #googlecloud #jsd2015

A B

C D

Decomposing Monolithic apps

Page 6: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

6@hostirosti #kubernetesio #googlecloud #jsd2015

A B

CD

Decomposing Monolithic apps

Page 7: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

7@hostirosti #kubernetesio #googlecloud #jsd2015

A B

CD

Decomposing Monolithic apps

Page 8: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

8@hostirosti #kubernetesio #googlecloud #jsd2015

Curated runtimes Rich services Auto-everything … just add code

Platform

Basic atom Run anything Self-managed

VM

More agility

More Flexibility

build and deploy appsbuild and deploy vm images

Where should I run my microservices?

Page 9: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

9@hostirosti #kubernetesio #googlecloud #jsd2015

Curated runtimes Rich services Auto-everything … just add code

● Managed collections● Declarative + Dynamic

PlatformCluster

Basic atom Run anything Self managed

VM

More agility

More Flexibility

build and deploy containers build and deploy appsbuild and deploy vm images

Where should I run my microservices?

Page 10: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

Google Cloud Platform 10

What is a container?

Containers Overview

Page 11: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

11@hostirosti #kubernetesio #googlecloud #jsd2015

No isolation

No namespacing

Common libs

Highly coupled apps and OS

Old Way: Shared Machines

kernel

libs

app

app app

app

Page 12: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

12@hostirosti #kubernetesio #googlecloud #jsd2015

Some isolation

Inefficient

Still highly coupled to the guest OS

Hard to manage

Old Way: Virtual Machines

app

libskernel

libs

app app

kernel

app

libs

libskernel

kernel

Page 13: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

13@hostirosti #kubernetesio #googlecloud #jsd2015

New Way: Containers

libs

app

kernel

libs

app

libs

app

libs

app

Page 14: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

14@hostirosti #kubernetesio #googlecloud #jsd2015

Concrete Docker Example - Images● An image is a stack of Read-Only file

system layers.

● Usual process:○ build○ push to repository○ pull to execution host○ start container from image

Debian

App

JRE

Libs

Page 15: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

15@hostirosti #kubernetesio #googlecloud #jsd2015

Concrete Docker Example - Images

Read / Write Read / Write

Debian

App

JRE

Libs

Read / Write● A container is a process

○ started with kernel restrictions○ a stack of shared Read-Only file

system layers○ plus a process specific Read-

Write layer● Every new container gets a new

Read-Write later. All containers from the same image start from exactly the same state!

Page 16: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

16@hostirosti #kubernetesio #googlecloud #jsd2015

Debian

App

PHP & Apache

Libs

Read / Write

host dir

● It's possible to mount host directories into a container's filesystem.

● These are mutable and do outlive the container.

● They're only available on that host.

Mounting Host Directories

Page 17: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

17@hostirosti #kubernetesio #googlecloud #jsd2015

Concrete Docker Example

Server

Debian

Docker Engine

Service BService A

libs

libs

libslibs

App

PHP & Apache

Page 18: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

19@hostirosti #kubernetesio #jsd2015

Why containers?

Performance

Images by Connie Zhou

Page 19: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

20@hostirosti #kubernetesio #jsd2015

Why containers?

Performance

Repeatability

Images by Connie Zhou

Page 20: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

21@hostirosti #kubernetesio #jsd2015

Why containers?

Performance

Repeatability

Quality of service

Images by Connie Zhou

Page 21: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

22@hostirosti #kubernetesio #jsd2015

Why containers?

Performance

Repeatability

Quality of service

Accounting

Images by Connie Zhou

Page 22: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

23@hostirosti #kubernetesio #jsd2015

Why containers?

Performance

Repeatability

Quality of service

Accounting

Portability

Images by Connie Zhou

Page 23: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

24@hostirosti #kubernetesio #jsd2015

Why containers?

Performance

Repeatability

Quality of service

Accounting

Portability

A fundamentally different way of managing applications

Images by Connie Zhou

Page 24: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

25@hostirosti #kubernetesio #googlecloud #jsd2015

containers are awesomelet's use lots of them!

Page 25: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

Google Cloud Platform 26

Cluster Management and Kubernetes

Page 26: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

27@hostirosti #kubernetesio #jsd2015

Everything at Google runs in containers:Gmail, Web Search, Maps, ...

MapReduce, batch, ...

GFS, Colossus, ...

Even Google Compute Engine: VMs in containers!

Page 27: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

28Image by Connie

Zhou

Page 28: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

29@hostirosti #kubernetesio #googlecloud #jsd2015

job hello_world = {

runtime = { cell = 'ic' } // Cell (cluster) to run in

binary = '.../hello_world_webserver' // Program to run

args = { port = '%port%' } // Command line parameters

requirements = { // Resource requirements

ram = 100M

disk = 100M

cpu = 0.1

}

replicas = 5 // Number of tasks

}

10000

Developer View

Page 29: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

30@hostirosti #kubernetesio #googlecloud #jsd2015

Developer View

Page 30: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

31@hostirosti #kubernetesio #googlecloud #jsd2015

web browsers

BorgMaster

link shard

UI shardBorgMaster

link shard

UI shardBorgMaster

link shard

UI shardBorgMaster

link shard

UI shard

Scheduler

borgcfg web browsers

scheduler

Borglet Borglet Borglet Borglet

Config file

BorgMaster

link shard

UI shard

persistent store (Paxos)

Binary

What justhappened?

Page 31: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

32

Hello world!

Hello world!

Hello world!

Hello world!Hello

world! Hello world! Hello

world!

Hello world!

Hello world!

Hello world!

Hello world!

Hello world!

Hello world!

Hello world!

Hello world!

Hello world!

Hello world!Hello world!

Hello world!

Hello world!

Hello world!

Hello world!

Hello world! Hello

world!

Hello world!

Hello world!

Hello world!

Image by Connie Zhou

Hello world!

Hello world!

Hello world! Hello

world!

Hello world! Hello

world!

Hello world!

Hello world!

Hello world!

Hello world!

Hello world! Hello

world!

Hello world! Hello

world!

Hello world!

Hello world!

Hello world!

Hello world!

Hello world! Hello

world!

Hello world! Hello

world!

Hello world!

Hello world!

http://goo.gl/1C4nuo (Borg paper)https://youtu.be/elHbkoJOBNE?t=4426

Page 32: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

33@hostirosti #kubernetesio #googlecloud #jsd2015

Greek for “Helmsman”; also the root of the word “Governor”

Container orchestrator Runs Docker containers Supports different cloud and bare-metal

environments Inspired and informed by Google’s experiences

and internal systems Open source, written in Go

Manage applications, not machines

Enter Kubernetes

Page 33: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

36@hostirosti #kubernetesio #googlecloud #jsd2015

Kubernetes Architecture web browsers

yKubelet Kubelet Kubelet Kubelet

Kubernetes Master

ReplicationController Scheduler

API Server

Kube-UI

ContainerRegistry

kubectl

Proxy

<Your App>

web browsers

Page 34: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

Google Cloud Platform 37

Desired State

Page 35: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

38@hostirosti #kubernetesio #googlecloud #jsd2015

Guestbook App

phpphp

phpNginx

Mongo

Redis

phpSpringJava

Page 36: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

39@hostirosti #kubernetesio #googlecloud #jsd2015

Challenges

Which host machine(s) should each process run on?

How does the Java microservice find the cache process?

How do we keep all of these processes running?

What happens if a host machine has trouble?

Are the processes healthy?

How do we scale when load changes?

Run this in another environment? QA, dev, another cloud, your servers?

Page 37: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

40@hostirosti #kubernetesio #googlecloud #jsd2015

Kubernetes Concepts

A small group of tightly coupled containers

Example: static site generator & web server

A loop that drives current state towards desired state

Example: replication controller

A set of running pods that work together

Example: load-balanced backends

Arbitrary metadata to organize components

Example: phase=productionrole=frontend

PodReplication Controller Service Labels

Page 38: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

41@hostirosti #kubernetesio #googlecloud #jsd2015

Pods

Pod

Web Server

Volume

ConsumersThe atom of cluster scheduling & placement

Ephemeral can die and be replaced

Application specific “logical host”

Single container pods can be created directly from a container image

Page 39: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

42@hostirosti #kubernetesio #googlecloud #jsd2015

The atom of cluster scheduling & placement

Ephemeral can die and be replaced

Small group of containers & volumes

Tightly coupled

Shared namespace share IP address & localhost

Pods

Pod

Site generator Web Server

Volume

ConsumersContent Manager

Page 40: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

43@hostirosti #kubernetesio #googlecloud #jsd2015

Responsible for maintaining the desired state

Monitor the current state

Similar to a process supervisor

Replication Controller

observe

diff

act

Page 41: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

44@hostirosti #kubernetesio #googlecloud #jsd2015

A group of pods that act as one == ServiceLoad balances across healthy podsGets a stable virtual IP and port

also a DNS name

Hide complexity ideal for non-native apps

Services

stable IP / port

Page 42: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

45@hostirosti #kubernetesio #googlecloud #jsd2015

Arbitrary metadataAttached to any API objectGenerally represent identityQueryable by selectors

think SQL ‘select ... where ...’The only grouping mechanism

pods under a ReplicationController pods in a Service capabilities of a node (constraints)

Example: “phase: canary”

App: GuestbookPhase: Dev

Role: Frontend

App: GuestbookPhase: Dev

Role: Backend

App: GuestbookPhase: Test

Role: Frontend

App: GuestbookPhase: Test

Role: Backend

Labels

Page 43: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

46@hostirosti #kubernetesio #googlecloud #jsd2015

Predicate based currently Pod Selection Node Capacity (based on requested resource limits)

Prioritisation

Nodes that match all predicates are ranked Priority for Node whose already-running pods consume the

least resources

More to come!

Scheduling

Page 44: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

47@hostirosti #kubernetesio #googlecloud #jsd2015

Map to Kubernetes

phpphp

phpNginx

Mongo

Redis

phpSpringJava

Page 45: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

48@hostirosti #kubernetesio #googlecloud #jsd2015

Google Container Engine

Managed Kubernetes (v1)

Manages Kubernetes Uptime

Manages Updates

Logging agents run on cluster instances, recording log entries that can be viewed in Cloud Logging

Use Google Cloud VPN to have cluster IPs coexist with your private network IPs

Page 46: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

Google Cloud Platform 49

Demo - Guestbook

Page 47: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

50@hostirosti #kubernetesio #googlecloud #jsd2015

Frequently Asked Questions

Q. How does Kubernetes handle secrets?docs/secrets.md

Q. How will Kubernetes scale pods?docs/proposals/autoscaling.md(Based on Traffic, predictive analysis or arbitrary data)

Q. How will Kubernetes scale nodes?http://www.slideshare.net/craigbox/autoscaling-kubernetes(Likely based on Utilization and signals from scheduler)

Q. How can we make Kubernetes highly availabledocs/availability.md

Page 48: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

Google Cloud Platform 51

Google Container Enginehttps://cloud.google.com/container-engine

google-containers google group

Kubernetes https://github.com/kubernetes/kubernetes

irc.freenode.net #google-containers

@kubernetesio

Page 49: Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis - Developer Advocate, Google @hostirosti

Google Cloud Platform 52

@hostirosti #kubernetesio #googlecloud#jsd2015

Vielen Dank fuer die Aufmerksamkeit!Fragen?