Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis -...

Post on 06-Jun-2020

4 views 0 download

Transcript of Microservices - JUG Saxony Day · Microservices Chaos Kontrolle mit Kubernetes Robert Kubis -...

MicroservicesChaos 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

Agenda

Motivation (Microservices)

Container Overview

Cluster Management & Kubernetes

Demo

1

2

3

4

Google Cloud Platform 4

Microservices

5@hostirosti #kubernetesio #googlecloud #jsd2015

A B

C D

Decomposing Monolithic apps

6@hostirosti #kubernetesio #googlecloud #jsd2015

A B

CD

Decomposing Monolithic apps

7@hostirosti #kubernetesio #googlecloud #jsd2015

A B

CD

Decomposing Monolithic apps

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?

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?

Google Cloud Platform 10

What is a container?

Containers Overview

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

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

13@hostirosti #kubernetesio #googlecloud #jsd2015

New Way: Containers

libs

app

kernel

libs

app

libs

app

libs

app

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

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!

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

17@hostirosti #kubernetesio #googlecloud #jsd2015

Concrete Docker Example

Server

Debian

Docker Engine

Service BService A

libs

libs

libslibs

App

PHP & Apache

19@hostirosti #kubernetesio #jsd2015

Why containers?

Performance

Images by Connie Zhou

20@hostirosti #kubernetesio #jsd2015

Why containers?

Performance

Repeatability

Images by Connie Zhou

21@hostirosti #kubernetesio #jsd2015

Why containers?

Performance

Repeatability

Quality of service

Images by Connie Zhou

22@hostirosti #kubernetesio #jsd2015

Why containers?

Performance

Repeatability

Quality of service

Accounting

Images by Connie Zhou

23@hostirosti #kubernetesio #jsd2015

Why containers?

Performance

Repeatability

Quality of service

Accounting

Portability

Images by Connie Zhou

24@hostirosti #kubernetesio #jsd2015

Why containers?

Performance

Repeatability

Quality of service

Accounting

Portability

A fundamentally different way of managing applications

Images by Connie Zhou

25@hostirosti #kubernetesio #googlecloud #jsd2015

containers are awesomelet's use lots of them!

Google Cloud Platform 26

Cluster Management and Kubernetes

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!

28Image by Connie

Zhou

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

30@hostirosti #kubernetesio #googlecloud #jsd2015

Developer View

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?

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

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

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

Google Cloud Platform 37

Desired State

38@hostirosti #kubernetesio #googlecloud #jsd2015

Guestbook App

phpphp

phpNginx

Mongo

Redis

phpSpringJava

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?

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

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

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

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

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

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

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

47@hostirosti #kubernetesio #googlecloud #jsd2015

Map to Kubernetes

phpphp

phpNginx

Mongo

Redis

phpSpringJava

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

Google Cloud Platform 49

Demo - Guestbook

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

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

Google Cloud Platform 52

@hostirosti #kubernetesio #googlecloud#jsd2015

Vielen Dank fuer die Aufmerksamkeit!Fragen?