Top Banner
Orchestrating Linux Containers Flavio Castelli Engineering Manager [email protected]
41

Orchestrating Linux Containers

Jan 25, 2017

Download

Software

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Orchestrating Linux Containers

Orchestrating

Linux Containers

Flavio CastelliEngineering [email protected]

Page 2: Orchestrating Linux Containers

New development challenges

● Release early, release often

● Be flexible: react to changes quickly

● Adoption of micro services architectures

● Different cloud providers

● Higher complexity of cloud environments

● Hybrid cloud deployments

● Application super portability

2

Page 3: Orchestrating Linux Containers

Let’s talk aboutapplication containers...

3

Page 4: Orchestrating Linux Containers

Lightweight

4

Host

Page 5: Orchestrating Linux Containers

Composable

5

Host

App X

App Y

App Z

Page 6: Orchestrating Linux Containers

Getting serious...

6

Page 7: Orchestrating Linux Containers

Multi-host deployment

7

host-A host-B host-C

App X

App Y

App Z

eth0 eth0 eth0

Page 8: Orchestrating Linux Containers

Some of the challenges

● Decide where to run each container

● Monitor nodes and containers

● Recover from failures

● Service discovery

● Expose services to external consumers

● Handle secrets (eg: credentials, certificates, keys,…)

● Handle data persistence

8

Page 9: Orchestrating Linux Containers

Container orchestrationengines

9

Page 10: Orchestrating Linux Containers

How can they help us?

● No need to find the right placement for each container

● No manual recovery from failures

● Just declare a “desired state”

10

Page 11: Orchestrating Linux Containers

Desired state reconciliation

11

State description Current state

Compute actionsExecute actions

Page 12: Orchestrating Linux Containers

Manage applications,not machines

12

Page 13: Orchestrating Linux Containers

Which one?

13

Docker Swarm

Page 14: Orchestrating Linux Containers

Kubernetes

● Created by Google, now part of CNCF

● Solid design

● Big and active community

● Opinionated solution, has an answer to most questions

14

Page 15: Orchestrating Linux Containers

Architecture

15

Scheduler

API server

Controller mgr

MasterMaster

etcdetcd

podpod

container

container

docker

kubelet kubeproxy

WorkerWorker

Page 16: Orchestrating Linux Containers

A concrete example

16

Page 17: Orchestrating Linux Containers

A simple web application

● Guestbook application

● Mongodb as database

● Both running inside of dedicated containers

17

Page 18: Orchestrating Linux Containers

Self-healing

18

Page 19: Orchestrating Linux Containers

Challenge #1: self-healing

19

host-A host-B

mongo-01

eth0 eth0

Automatic recovery from failures,

enforce desired state

host-A host-B

eth0 eth0

mongo-01

Page 20: Orchestrating Linux Containers

Replica Set

● Ensure that a specific number of “replicas” are running at any one time

● Recovery from failures

● Automatic scaling

20

Page 21: Orchestrating Linux Containers

Service discovery

21

Page 22: Orchestrating Linux Containers

Challenge #2: service discovery

22

host-A host-B

gbook-01 mongo-01

eth0 eth0

Where is mongo?

host-A host-B

gbook-01 mongo-01

eth0 eth0

● “mongo” container: producer

● “gbook” container: consumer

Page 23: Orchestrating Linux Containers

Use DNS

● Not a good solution:

– Containers can die/be moved somewhere more often

– Return DNS responses with a short TTL → more load on the server

– Some clients ignore TTL → old entries are cached

Note well:

● Docker < 1.11: updates /etc/hosts dynamically

● Docker >= 1.11: integrates a DNS server

23

Page 24: Orchestrating Linux Containers

Key-value store

● Rely on a key-value store (etcd, consul, zookeeper)

● Producer register itself: IP, port #

● Orchestration engine handles this data to the consumer

● At run time either:

– Change your application to read data straight from the k/v

– Rely on some helper that exposes the values via environment file or configuration file

24

Page 25: Orchestrating Linux Containers

Handing changes &multiple choices

25

Page 26: Orchestrating Linux Containers

Challenge #3: react to changes

26

host-A host-B

gbook-01 mongo-01

eth0 eth0

host-C

eth0

“gbook” is already connected to “mongo”

Page 27: Orchestrating Linux Containers

Challenge #3: react to changes

27

host-A host-B

gbook-01 mongo-01

eth0 eth0

host-C

mongo-01

eth0

“gbook” points to to the old location → it’s broken

“mongo” is moved to another host → different IP

Page 28: Orchestrating Linux Containers

Challenge #3: react to changes

28

The link has to be reestablished

host-A host-B

gbook-01

eth0 eth0

host-C

mongo-01

eth0

Containers can be moved at any time:● The producer can be moved to a different host● The consumer should keep working

Page 29: Orchestrating Linux Containers

Challenge #4: multiple choices

29

Multiple instances of the “mongo” image

host-A host-B

gbook-01 mongo-01

eth0 eth0

host-C

mongo-01

eth0

Which mongo?

Workloads can be scaled:● More instances of the same producer● How to choose between all of them?

Page 30: Orchestrating Linux Containers

DIY solution

● Use a load balancer

● Point all the consumers to a load balancer

● Expose the producer(s) using the load balancer

● Configure the load balancer to react to changes

→ More moving parts

30

Page 31: Orchestrating Linux Containers

Kubernetes services

31

host-B

mongo-01

eth0

host-C

mongo-01

eth0

host-A

gbook-01

eth0

mongoservice

VIP

● Service gets a unique and stable Virtual IP Address● VIP always points to one of the service containers● Consumers are pointed to the VIP● Can run in parallel to DNS for legacy applications

Page 32: Orchestrating Linux Containers

Ingress traffic

32

Page 33: Orchestrating Linux Containers

Challenge #5: publish applications

● Your production application is running inside of a container cluster

● How to route customers’ requests to these containers?

● How to react to changes (containers moved, scaling,…)?

33

Page 34: Orchestrating Linux Containers

Kubernetes’ approach

Services can be of three different types:

● ClusterIP: virtual IP reachable only by containers inside of the cluster

● NodePort: “ClusterIP” + the service is exposed on all the nodes of the cluster on a specific port → <NodeIP>:<NodePort>

● LoadBalancer: “NodePort” + k8s allocates a load balancer using the underlying cloud provider. Then it configures it and it keep it up-to-date

34

Page 35: Orchestrating Linux Containers

Ingress traffic flow

35

Load balancer

http://guestbook.com

host-B

gbook-01

8081

blog-01

8080

host-A

gbook-01

80818080

host-C

8081

blog-01

8080

● Load balancer picks a container host● Traffic is handled by the internal service● Works even when the node chosen by the load balancer is not running the

container

Page 36: Orchestrating Linux Containers

Data persistence

36

Page 37: Orchestrating Linux Containers

Challenge #6: stateful containers

● Not all applications can offload data somewhere else

● Some data should survive container death/relocation

37

Page 38: Orchestrating Linux Containers

Kubernetes Volumes

● Built into kubernetes

● They are like resources → scheduler is aware of them

● Support different backends via dedicated drivers:

– NFS

– Ceph

– Cinder

– ...

38

Page 39: Orchestrating Linux Containers

Demo

39

Page 40: Orchestrating Linux Containers

Questions?

40

Page 41: Orchestrating Linux Containers