SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures -...

39
SwarmKit: Docker’s Simple Model for Complex Orchestration Stephen Day Docker, Inc. ContainerCon+LinuxCon EU October 2016 v1

Transcript of SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures -...

Page 1: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

SwarmKit:Docker’s Simple Model for Complex OrchestrationStephen DayDocker, Inc.ContainerCon+LinuxCon EUOctober 2016

v1

Page 2: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

Stephen DayDocker, Inc.github.com/stevvooe@stevvooe

Page 3: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

SwarmKitA new framework by Docker for building orchestration systems.

Page 4: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

What is orchestration?

Page 5: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

5

Orchestration

- Orchestration Systems- Mostly use a service based model- Mostly wraps docker- Challenging to use

- Standalone Swarm, July 2015- Scale containers- Docker API “native”- No higher-level abstraction

A Docker-oriented History

Page 6: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

Why orchestration?

Page 7: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

7

Example$ docker network create -d overlay backend 31ue4lvbj4m301i7ef3x8022t

$ docker service create -p 6379:6379 --network backend redis bhk0gw6f0bgrbhmedwt5lful6

$ docker service scale serene_euler=3 serene_euler scaled to 3

$ docker service ls ID NAME REPLICAS IMAGE COMMANDdj0jh3bnojtm serene_euler 3/3 redis

Page 8: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

Why services?What is wrong with containers?

Page 9: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

9

Nodes- Arbitrary cluster resources- Connected across a common network- Topology control- Cryptographic identity

Node 1 Node 2 Node 3

Page 10: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

10

Services- Express desired state of the cluster- Abstraction to control a set of containers- Enumerates resources, network availability, placement- Leave the details of runtime to container process- Implement these services by distributing processes across a cluster

Node 1 Node 2 Node 3

Page 11: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

11

Networks- Defines broadcast domains- Services can attach to networks- Routing mesh will route connections to active service process

Node 1 Node 2 Node 3

Page 12: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

Simple systems can exhibit complex behavior

Page 13: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

13

OrchestrationA control system for your cluster

ClusterO

-

Δ SnD

D = Desired StateO = OrchestratorC = ClusterSt = State at time tΔ = Operations to converge S to D

https://en.wikipedia.org/wiki/Control_theory

Page 14: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

14

ConvergenceA functional view

D = Desired StateO = OrchestratorC = ClusterSt = State at time t

f(D, Sn-1, C) → Sn | min(S-D)

Page 15: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

15

Observability and ControllabilityThe Problem

Low Observability High Observability

Failure Process State User Input

Page 16: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

16

Data Model Requirements

- Represent difference in cluster state- Maximize Observability- Support Convergence- Do this while being Extensible and Reliable

Page 17: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

Show me your data structures and I’ll show you your orchestration system

Page 18: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

Declarative

Page 19: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

19

Declarative

$ docker network create -d overlay backend 31ue4lvbj4m301i7ef3x8022t

$ docker service create --network backend redis bhk0gw6f0bgrbhmedwt5lful6

Page 20: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

20

ReconciliationSpec → Object

ObjectCurrent State

SpecDesired State

Page 21: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

Orchestrator

21

Task ModelAtomic Scheduling Unit of SwarmKit

ObjectCurrent State

SpecDesired State

Task0 Task1… Taskn Scheduler

Page 22: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

Consistency

Page 23: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

23

Versioned UpdatesConsistency

service := getCurrentService()

spec := service.Spec

spec.Image = "my.serv/myimage:mytag"

update(spec, service.Version)

Page 24: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

24

Field Ownership

Only one component of the system can write to a field

Consistency

Page 25: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

Worker

Pre-Run

Preparing

Manager

Terminal States

Task StateNew Allocated Assigned

Ready Starting

Running

Complete

Shutdown

Failed

Rejected

Page 26: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

Extensible

Page 27: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

Task Model

Prepare: setup resourcesStart: start the taskWait: wait until task exitsShutdown: stop task, cleanlyTerminate: kill the task, forcefullyUpdate: update task metadata, without interruptionRemove: remove resources used by task

Runtime

Page 28: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

Reliable

Page 29: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

SwarmKit doesn’t Quit

Page 30: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

ArchitectureData Structures

Page 31: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

Service Spec

message ServiceSpec {

// Task defines the task template this service will spawn.

TaskSpec task = 2 [(gogoproto.nullable) = false];

// UpdateConfig controls the rate and policy of updates.

UpdateConfig update = 6;

// Service endpoint specifies the user provided configuration

// to properly discover and load balance a service.

EndpointSpec endpoint = 8;

}

Protobuf Example

Page 32: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

Service Object

message Service {

ServiceSpec spec = 3;

// Runtime state of service endpoint. This may be different

// from the spec version because the user may not have entered

// the optional fields like node_port or virtual_ip and it

// could be auto allocated by the system.

Endpoint endpoint = 4;

// UpdateStatus contains the status of an update, if one is in

// progress.

UpdateStatus update_status = 5;

}

Protobuf Example

Page 33: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

Task

// Task specifies the parameters for implementing a Spec. A task is effectively

// immutable and idempotent. Once it is dispatched to a node, it will not be

// dispatched to another node.

message Task {

TaskSpec spec = 3;

string service_id = 4;

uint64 slot = 5;

string node_id = 6;

TaskStatus status = 9;

TaskState desired_state = 10;

repeated NetworkAttachment networks = 11;

Endpoint endpoint = 12;

Driver log_driver = 13;

}

Protobuf Example

Page 34: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

Blue Green Deployments

Sillyproxy- Uses rolling updates to set proxy backends- Desired state is encoded in environment variables- Rolling updates can control traffic between backends

Applied

Page 35: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

Distributed Period Scheduler

From a GitHub comment- Scheduling criteria set via environment variables

- Can leverage something like redis to do this, as well- Leverage restarts to dispatch to available nodes

Applied

Page 36: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

Future

Page 38: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

Booth D38 @ LinuxCon + ContainerConTues Oct 4th

● Build Distributed Systems without Docker, using Docker Plumbing Projects - Patrick Chanezon, David Chung and Captain Phil Estes

● Getting Started with Docker Services - Mike Goelzer● Swarmkit: Docker’s Simplified Model for Complex Orchestration - Stephen Day● User Namespace and Seccomp Support in Docker Engine - Paul Novarese● Build Efficient Parallel Testing Systems with Docker - Docker Captain Laura Frank

Wed Oct 5th● How Secure is your Container? A Docker Engine Security Update - Phil Estes● Docker Orchestration: Beyond the Basics - Aaron Lehmann● When the Going gets Tough, get TUF Going - Riyaz Faizullabhoy and Lily Guo

Thurs Oct 6th● Orchestrating Linux Containers while Tolerating Failures - Drew Erny● Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry● Berlin Docker Meetup

Friday Oct 7th● Tutorial: Comparing Container Orchestration Tools - Neependra Khare● Tutorial: Orchestrate Containers in Production at Scale with Docker Swarm - Jerome Petazzoni

Page 39: SwarmKit: Docker’s Simple Model for · Orchestrating Linux Containers while Tolerating Failures - Drew Erny Unikernels: When you Should and When you Shouldn’t - Amir Chaudhry

THANK YOU