orchestrating linux containers while tolerating failures

44
Orchestrating Linux Containers while Tolerating Failures Container Camp, London September 9, 2016 Nishant Totla, Core Team Software Engineer, Docker Inc. @nishanttotla

Upload: docker-inc

Post on 06-Jan-2017

5.140 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Orchestrating Linux Containers while tolerating failures

Orchestrating Linux Containers while Tolerating FailuresContainer Camp, LondonSeptember 9, 2016

Nishant Totla, Core Team Software Engineer, Docker Inc.@nishanttotla

Page 2: Orchestrating Linux Containers while tolerating failures

What is a Linux Container?• A Linux container is a self-contained execution environment with isolated

resources• The technology has been around for a while - LXC, FreeBSD Jails, Solaris

Zones• The Docker project, open-sourced in 2013 made containers extremely

popular and significantly easier to use

Page 3: Orchestrating Linux Containers while tolerating failures

What is a Linux Container?• A Linux container is a self-contained execution environment with isolated

resources• The technology has been around for a while - LXC, FreeBSD Jails, Solaris

Zones• The Docker project, open-sourced in 2013 made containers extremely

popular and significantly easier to use

Source: Docker blog (August ‘16)

Page 4: Orchestrating Linux Containers while tolerating failures

Real-world Applications• The growth of containers has brought a fresh perspective on deploying

containerized applications, particularly microservices• This brings up interesting problems• Infrastructure• Deployment• Security• Networking• Scaling• Fault-tolerance

• New tools and abstractions needed• Container Orchestration is the key!

Page 5: Orchestrating Linux Containers while tolerating failures

Trends

Docker

Orchestration, etc.

Page 6: Orchestrating Linux Containers while tolerating failures

Orchestration is Hard• Distributed Systems are hard to get right• Failures happen all the time!• Machines go down• Networks can fail or drop packets• Latency can cause unexpected scenarios

Page 7: Orchestrating Linux Containers while tolerating failures

Can we make it easier to orchestrate real-world containerized applications?

Page 8: Orchestrating Linux Containers while tolerating failures

Can we make it easier to orchestrate real-world containerized applications?

à Swarm Mode in Docker 1.12

Page 9: Orchestrating Linux Containers while tolerating failures

Swarm Mode in Docker 1.12• Goals• It should be simple to setup and use a distributed cluster• It should be seamless to move from development to deployment

Page 10: Orchestrating Linux Containers while tolerating failures

Swarm Mode in Docker 1.12• Goals• It should be simple to setup and use a distributed cluster• It should be seamless to move from development to deployment

• Starting with 1.12, Docker now has inbuilt orchestration• The easiest way to orchestrate Docker containers is now Docker• Multiple Docker Engines can be brought together to form a Swarm cluster• Really easy to manage applications on the cluster

Page 11: Orchestrating Linux Containers while tolerating failures

The Docker approach to container orchestration

1. Swarm Topology

2. Managing Cluster State

3. Managing Application State

Demo

Page 12: Orchestrating Linux Containers while tolerating failures

Part 1: Swarm Topology

Page 13: Orchestrating Linux Containers while tolerating failures

Single Node Cluster

$ docker swarm init --advertise-addr 198.211.109.17

Engine

Page 14: Orchestrating Linux Containers while tolerating failures

Adding another Node

$ docker swarm init --advertise-addr 198.211.109.17$ docker swarm join 198.211.109.17:2377

Engine Engine

Page 15: Orchestrating Linux Containers while tolerating failures

More Nodes

$ docker swarm init --advertise-addr 198.211.109.17$ docker swarm join 198.211.109.17:2377

Engine Engine

Engine

Engine

Engine

Page 16: Orchestrating Linux Containers while tolerating failures

Managers and Workers• Swarm nodes can be workers or managers• Worker nodes• Run Tasks (containers)

• Manager nodes • Run Tasks (containers)• Accept specifications from the user• Reconcile desired and and actual cluster state

• Workers can be promoted to managers• Managers can be demoted to workers

Engine

Engine

Page 17: Orchestrating Linux Containers while tolerating failures

Secure by Default with end to end Encryption• Cryptographic node

identity• Automatic encryption and

mutual auth (TLS)• Automatic certificate

rotation• External CA integration• Encrypted communication

Manager[TLS][CA]

Manager[TLS][CA]

Manager[TLS][CA]

Agent[TLS]

Agent[TLS]

Agent[TLS]

Page 18: Orchestrating Linux Containers while tolerating failures

Part 2: Managing Cluster State

Page 19: Orchestrating Linux Containers while tolerating failures

The Raft Algorithm• Raft is a popular distributed consensus algorithm• Features• Single leader performs all updates• Leader election – elect a leader• Log replication – replicate the log of cluster operations

• Consensus is maintained as long as a majority of nodes are working

Page 20: Orchestrating Linux Containers while tolerating failures

Raft Consensus Layer

Manager

Internal Distributed State Store

Manager Manager

Raft consensus group

• Built on top of the etcd Raft library• Strongly consistent - holds desired state• Fast (in-memory reads, domain-specific indexing, batched operations)• Secure

Page 21: Orchestrating Linux Containers while tolerating failures

Raft Consensus Layer• Swarm managers are crucial• Manager nodes form a Raft consensus group• No need to set up an external KV store• As long as a majority of managers are running, the cluster will function

normally (should start with an odd number)• All managers can accept API requests (HA, no single point of failure)

Page 22: Orchestrating Linux Containers while tolerating failures

Worker to Worker Gossip

Engine Engine Engine EngineEngine

Gossip Network

• Different from Raft to keep Raft concise• High volume, p2p network between workers• Eventually consistent – networking, load balancing rules, etc.• Secure: symmetric encryption with key rotation in Raft

Page 23: Orchestrating Linux Containers while tolerating failures

Putting it All Together

Page 24: Orchestrating Linux Containers while tolerating failures

Full Architecture

Engine Engine Engine EngineEngine

Gossip Network

Manager

Internal Distributed State Store

Manager Manager

Raft consensus group

gRPC

Page 25: Orchestrating Linux Containers while tolerating failures

Part 3: Managing Application State

Page 26: Orchestrating Linux Containers while tolerating failures

A Higher Level of Abstraction• From containers to services

$ docker run $ docker service create

• Docker services• Allow declarative specification• Work seamlessly on any number of nodes• Perform desired state reconciliation• Can be scaled or updated easily

Page 27: Orchestrating Linux Containers while tolerating failures

Services

$ docker service create \--replicas 3 \--name frontend \--network mynet \--publish 8080:80 \frontend_image:1.0

Engine Engine

Engine

Engine

Engine

mynet

Page 28: Orchestrating Linux Containers while tolerating failures

Swarm Routing Mesh• All nodes expose port

8080 for myapp

• Routing mesh ensures traffic is routed transparently to a running container of the service

Manager

Agent 1 Agent 2 Agent 3

$ docker service create \--replicas 3 \--name frontend \--network mynet \--publish 8080:80 \frontend_image:1.0

:8080 :8080 :8080

:8080

access myapp.com:8080

Page 29: Orchestrating Linux Containers while tolerating failures

Swarm Routing Mesh• Every service gets

assigned a virtual IP (VIP)

• Built-in DNS-based service discovery: service name resolves to service VIP• VIP round-robins between

container IPs using Linux IPVS

Manager

Agent 1 Agent 2 Agent 3

$ docker service create \--replicas 3 \--name frontend \--network mynet \--publish 8080:80 \frontend_image:1.0

:8080 :8080 :8080

:8080

access myapp.com:8080

Page 30: Orchestrating Linux Containers while tolerating failures

Node Failure

$ docker service create \--replicas 3 \--name frontend \--network mynet \--publish 8080:80 \frontend_image:1.0

Engine Engine

Engine

Engine

Engine

mynet

Page 31: Orchestrating Linux Containers while tolerating failures

Desired State ≠ Actual State

Engine

Engine

Engine

Engine

mynet

$ docker service create \--replicas 3 \--name frontend \--network mynet \--publish 8080:80 \frontend_image:1.0

Page 32: Orchestrating Linux Containers while tolerating failures

Converge back to Desired State

Engine

Engine

Engine

Engine

mynet

$ docker service create \--replicas 3 \--name frontend \--network mynet \--publish 8080:80 \frontend_image:1.0

Page 33: Orchestrating Linux Containers while tolerating failures

Service Scaling

Engine

Engine

Engine

Engine

mynet

$ docker service scale frontend=6

Page 34: Orchestrating Linux Containers while tolerating failures

And more!• Global services• Configurable rolling updates• Constraints• Restart policies• Resource aware scheduling

Page 35: Orchestrating Linux Containers while tolerating failures

Behind the scenes

API

Orchestrator

Allocator

Scheduler

Dispatcher

Worker

Executor

Manager node

Worker node

Accepts command from client and creates service object

Reconciliation loop for service objects and updates tasks

Allocates IP address to tasks

Assigns nodes to tasks

Dispatches tasks and checks in on workers (heartbeat)

Connects to Dispatcher to check on assigned tasks

Executes tasks assigned to worker node

$ docker service create

Page 36: Orchestrating Linux Containers while tolerating failures

Node Failure• Manager failure• Handled by the Raft algorithm, as long as consensus is maintained

• Worker failure• Dispatcher detects a node is down (failed heartbeat)• Orchestrator reconciles tasks• Allocator, Scheduler, and Dispatcher redo the previous steps to set up new tasks

Page 37: Orchestrating Linux Containers while tolerating failures

If Everything Fails

$ docker swarm init \--advertise-addr 198.211.109.17 \--force-new-cluster

• The flag forces an existing node that was part of a lost quorum to restart as a single node Manager without losing its data

Page 38: Orchestrating Linux Containers while tolerating failures

To Conclude

• Swarm mode in Docker 1.12 makes it very easy to create and manage a failure-tolerant cluster• Networking and security are handled out of the box• The service abstraction allows for a declarative specification of how the

application is expected to run• Much more coming up in the next few releases!

Page 39: Orchestrating Linux Containers while tolerating failures

Contributions welcome!• Docker open-source on GitHub• github.com/docker/swarmkit | github.com/docker/docker

Page 40: Orchestrating Linux Containers while tolerating failures

Special thanks to my co-workers for helping out with this talk- Nathan LeClaire, - Alexandre Beslic, - Aaron Lehmann, - Drew Erny, - Jana Radhakrishnan, - Dongluo Chen

Page 41: Orchestrating Linux Containers while tolerating failures

Nishant Totla@nishanttotla

Thank You!

Page 42: Orchestrating Linux Containers while tolerating failures

Constraints

Engine Engine

Engine

Engine

Engine $ docker daemon --label com.example.storage=“ssd”

$ docker daemon --label com.example.storage=“ssd”

Page 43: Orchestrating Linux Containers while tolerating failures

Constraints

$ docker service create \--replicas 5 \--name frontend \--network mynet \--publish 8080:80 \--constraint engine.labels.com.example.storage==ssdfrontend_image:1.0

Engine Engine

Engine

Engine

Engine

mynet

$ docker daemon --label com.example.storage=“ssd”

$ docker daemon --label com.example.storage=“ssd”

Page 44: Orchestrating Linux Containers while tolerating failures

Constraints

Engine Engine

Engine

Engine

Engine

mynet

$ docker daemon --label com.example.storage=“ssd”

$ docker daemon --label com.example.storage=“ssd”

$ docker service scale frontend=10