Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and...

39
Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker

Transcript of Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and...

Page 1: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Orchestration in Docker

Swarm mode, Docker services and declarative application deployment

Mike Goelzer & Victor VieuxDocker

Page 2: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Mike Goelzer / [email protected] / gh: mgoelzer

Orchestration Overview

Page 3: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Orchestration in Docker● Orchestration

○ Swarm Mode○ Docker Services○ Security○ Routing mesh

● Container Healthcheck

Page 4: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Engine

Swarm Mode

$ docker swarm init

Page 5: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Engine

Swarm Mode

$ docker swarm init

$ docker swarm join <IP of manager>:2377

Engine

Page 6: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Engine

Engine

Engine

EngineEngine Engine

Swarm Mode

$ docker swarm init

$ docker swarm join <IP of manager>:2377

Page 7: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Engine

Engine

Engine

EngineEngine Engine

Services

$ docker service create --replicas 3 --name frontend --network mynet

--publish 80:80/tcp frontend_image:latest

mynet

Page 8: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Engine

Engine

Engine

EngineEngine Engine

Services

$ docker service create --replicas 3 --name frontend --network mynet

--publish 80:80/tcp frontend_image:latest

$ docker service create --name redis --network mynet redis:latest

mynet

Page 9: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Engine

Engine

Engine

EngineEngine Engine

Node Failure

$ docker service create --replicas 3 --name frontend --network mynet

--publish 80:80/tcp frontend_image:latest

$ docker service create --name redis --network mynet redis:latest

mynet

Page 10: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Engine

Engine

Engine

EngineEngine Engine

Node Failure

$ docker service create --replicas 3 --name frontend --network mynet

--publish 80:80/tcp frontend_image:latest

$ docker service create --name redis --network mynet redis:latest

mynet

Page 11: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Engine

Engine

Engine

EngineEngine

Desired State ≠ Actual State

$ docker service create --replicas 3 --name frontend --network mynet

--publish 80:80/tcp frontend_image:latest

$ docker service create --name redis --network mynet redis:latest

mynet

Page 12: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Engine

Engine

Engine

EngineEngine

Converge Back to Desired State

$ docker service create --replicas 3 --name frontend --network mynet

--publish 80:80/tcp frontend_image:latest

$ docker service create --name redis --network mynet redis:latest

mynet

Page 13: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Engine

Engine

Engine

EngineEngine

Scaling

$ docker service scale frontend=6

mynet

Page 14: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Engine

Engine

Engine

EngineEngine

Scaling

$ docker service scale frontend=10

mynet

Page 15: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Engine

Engine

Engine

EngineEngine

Global Services

$ docker service create --mode=global --name prometheus prom/prometheus

mynet

Page 16: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Engine

Engine

Engine

EngineEngine

Constraints

Engine

docker daemon --label com.example.storage="ssd"

docker daemon --label com.example.storage="ssd"

Page 17: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Engine

Engine

Engine

EngineEngine

Constraints

$ docker service create --replicas 3 --name frontend --network mynet

--publish 80:80/tcp --constraint engline.labels.com.example.storage==ssd frontend_image:latest

Engine

docker daemon --label com.example.storage="ssd"

docker daemon --label com.example.storage="ssd"

Page 18: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Engine

Engine

Engine

EngineEngine

Constraints

$ docker service create --replicas 3 --name frontend --network mynet

--publish 80:80/tcp --constraint engline.labels.com.example.storage==ssd frontend_image:latest$ docker service scale frontend=10

Engine

docker daemon --label com.example.storage="ssd"

docker daemon --label com.example.storage="ssd"

Page 19: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Services

Page 20: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Services are grouped into stacks

Page 21: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Swarm mode orchestration is optional● You don’t have to use it● 1.12 is fully backwards compatible● Will not break existing deployments and scripts

Page 22: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Routing Mesh• Operator reserves a

swarm-wide ingress port (8080) for myapp

• Every node listens on 8080• Container-aware routing mesh

can transparently reroute traffic from Worker3 to a node that is running container

• Built in load balancing into the Engine

• DNS-based service discovery

Worker 1

:8080

Manager

User accesses myapp.com:8080:8080

Worker 2

:8080

Worker 3

:8080

frontend frontend

$ docker service create --replicas 3 --name frontend --network mynet

-p 8080:80 frontend_image:latest

frontend

Page 23: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Routing Mesh: Published Ports• Operator reserves a

swarm-wide ingress port (8080) for myapp

• Every node listens on 8080• Container-aware routing mesh

can transparently reroute traffic from Worker3 to a node that is running container

• Built in load balancing into the Engine

• DNS-based service discovery

Worker 1

:8080

Manager

User accesses myapp.com:8080:8080

Worker 2

:8080

Worker 3

:8080

frontend frontend

$ docker service create --replicas 3 --name frontend --network mynet

-p 8080:80 frontend_image:latest

frontend

Page 24: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Security out of the box Cryptographic Node Identity

○ Workload segregation (think PCI) There is no “insecure mode”:

○ TLS mutual auth○ TLS encryption○ Certificate rotation

Page 25: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

HEALTHCHECK --interval=5m --timeout=3s

--retries 3

CMD curl -f http://localhost/ || exit 1

Checks every 5 minutes that web server can return index page within 3 seconds.

Three consecutive failures puts container in an unhealthy state.

Container Health Check in Dockerfile

Page 26: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Victor Vieux / [email protected] / gh: vieux

Orchestration Deep Dive

+ demo at the end

Page 27: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Node

Node

Node

NodeNode

Node

Swarm Topology

Node

Node

Node

Node

Node

Node

Page 28: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Node

Node

Node

NodeNode

Node

Swarm Topology

Node

Node

Node

Node

Node

Node

Manager

Worker

Page 29: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Node

Node

Node

NodeNode

Node

Swarm Topology

Node

Node

Node

Node

Node

Node

Manager

Worker

● Each Node has a role● Roles are dynamic● Programmable Topology

Page 30: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Manager ManagerManager

Worker WorkerWorkerWorker WorkerWorker Worker

Internal Distributed State Store

Raft consensus group

Docker swarm mode communication internals

Gossip network

gRPC

Page 31: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Manager ManagerManager

Internal Distributed State Store

Raft consensus group

Quorum Layer

● Strongly consistent: Holds desired state● Simple to operate● Blazing fast (in-memory reads, domain specific indexing, ...)● Secure

Page 32: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Worker WorkerWorkerWorker WorkerWorker Worker

Worker-to-Worker Gossip

Gossip network

● Eventually consistent: Routing mesh, load balancing rules, ...● High volume, p2p network between workers● Secure: Symmetric encryption with key rotation in Raft

Page 33: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

API

Allocator

Orchestrator

Scheduler

Dispatcher

RAFT

Manager Node

Worker

ExecutorWorker Node

Accepts command from client and creates service object

Reconciliation loop for service objects and creates tasks

Allocates IP addresses to tasks

Assigns nodes to tasks

Checks in on workers

docker service create

Connects to dispatcher to check on assigned tasks

Node Breakdown

Executes the tasks assigned to worker node

Page 34: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Internal Load Balancer

Page 35: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Ingress Load Balancer

Page 36: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

Secure by default with end-to-end encryption• Cryptographic node

identity• Automatic encryption

and mutual auth (TLS)• Automatic cert rotation• External CA

integration

Manager Node

CertificateAuthority

TLS

Manager Node

CertificateAuthority

TLS

Manager Node

CertificateAuthority

TLS

Worker

TLS

Worker

TLS

Worker

TLS

Page 37: Orchestration in Docker · 2017-12-14 · Orchestration in Docker Swarm mode, Docker services and declarative application deployment Mike Goelzer & Victor Vieux Docker. Mike Goelzer

DEMO