Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances...

64
Running docker in production Roy Bauweraerts & Erwin de Keijzer

Transcript of Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances...

Page 1: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Running docker in production

Roy Bauweraerts & Erwin de Keijzer

Page 2: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Hello!Mijndomein

● Webhosting company founded in 2003● 572.870 Domains● 194.870 Customers

Page 3: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

md3Behold the monolith

● Own iron● 1 release every 4 weeks (+ hotfixes)

○ mostly night releases● (mostly) manual process● Releases by Operations

Page 4: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

µd3behold the distributed monolith

● 3 dedicated aws ec2 instances per microservice

● Multiple releases every week● Releases by Developers● Service discovery with Consul

Page 5: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

ConsulService discovery

Consul

● Service discovery

● Failure detection

● Multi datacenter

● Key/Value storage

Page 6: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

µd3Behold the distributed monolith

● Tightly coupled● Expensive● Complicated to introduce new services

○ write playbooks○ add instances○ add “service” to deploy server○ create healthchecks

● High overhead

Page 7: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

The goalBut why?!

To migrate to a platform that allows us to quickly add, change or remove functionality

with high confidence, without compromising the user experience or availability.

Page 8: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Docker

Page 9: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Docker

Docker containers wrap a piece of software in a complete filesystem that contains everything

needed to run:

code, runtime, system tools, system libraries –

anything that can be installed on a server.

This guarantees that the software will always run the same, regardless of its environment.

Their own words

Page 10: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

ChallengesDo you accept?

● Running docker containers

● Environment consistency & configuration

● Service discovery

● Logging

● Request routing

● Monitoring

● Updates without downtime

Page 11: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge#1 Running docker containers

What is the easiest and most reliable method of managing your containers (CRUD & scale) with minimal effort and without affecting your customers?

Page 12: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge

Kubernetes

#1 Running docker containers

Nomad Docker swarm Amazon ecs

Page 13: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge

Kubernetes

#1 Running docker containers

Nomad Docker swarm Amazon ecs

Page 14: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge

DC/OS

“DC/OS is an enterprise grade datacenter-scale

operating system,

providing a single platform for running containers,

big data, and distributed apps in production.”

#1 Running docker containers

Page 15: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge

Pro:● It keeps the containers

running rather well● Easy bootstrap● CRUD web interface● Logging possibilites● Rolling updates based on

health checks

Con:● Lots of moving parts● Distributed state● No native consul integration● Webui has flaws● No internal name spacing● No way of running services on

all agents

#1 Running docker containersDC/OS

Page 16: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge#1 Running docker containers

Page 17: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

ChallengesDo you accept?

● Running docker containers

● Environment consistency & configuration

● Service discovery

● Logging

● Request routing

● Monitoring

● Updates without downtime

Page 18: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge#2 Environment

How can you guarantee that your code behaves the same?

here

and here

Page 19: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge#2 Environment

● Use the same artifact in all your environments

● Artifact combines all resources needed for running your code:

○ os

○ libraries

○ plugins

○ tooling

● Configuration is injected during runtime

Page 20: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

● Use the same artifact in all your environments

● Artifact combines all resources needed for running your code:

○ os

○ libraries

○ plugins

○ tooling

● Configuration is injected during runtime

Challenge#2 Environment

} docker

Page 21: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

● Use the same artifact in all your environments

● Artifact combines all resources needed for running your code:

○ os

○ libraries

○ plugins

○ tooling

● Configuration is injected during runtime

Challenge#2 Environment

} docker

}consul-template

Page 22: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

environment consistencyChallenge#2 Environment

➭ cat parameters.yml.ctmpl ---{{ tree "config/mijndomein" | explode | toYAML }}

➭ consul-template -consul consul.service.consul:8500 -once -template "parameters.yml.ctmpl:parameters.yml"

➭ cat parameters.yml---example: data

Page 23: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

environment consistencyChallenge#2 Environment

consul-template

parameters.yml

Page 24: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge#2 Environment

Page 25: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

ChallengesDo you accept?

● Running docker containers

● Environment consistency & configuration

● Service discovery

● Logging

● Request routing

● Monitoring

● Updates without downtime

Page 26: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge#3 Service discovery

10.0.0.2 10.0.0.310.0.0.1

A AC DB FE AB

13:00

How do you let your containers discover other containers in continuously changing environment?

Page 27: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge#3 Service discovery

10.0.0.2 10.0.0.310.0.0.1

13:10

D AC DE FB AC

How do you let your containers discover other containers in continuously changing environment?

Page 28: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge#3 Service discovery

10.0.0.2 10.0.0.310.0.0.1

13:20

A BC AE FB DC

13:20

How do you let your containers discover other containers in continuously changing environment?

Page 29: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge#3 Service discovery

Mesos DNSContainers need to communicate with services outside

of DC/OS.

DC/OS service portsOutside services also need to know the IP addresses.

Consul DNSDC/OS cannot communicate with consul.

Page 30: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge#3 Service discovery

Mesos consul

“Mesos to Consul bridge for service discovery.”

Page 31: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge#3 Service discovery

● Watches Mesos

● Registers tasks as applicationid.service.consul

○ (marathon labels can be used define your own servicename)

● Registers consul (http) health checks based on marathon labels

● Updates on a predefined interval

○ Not ideal, compromises between consistency and performance

Mesos consul

Page 32: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge#3 Service discovery

Page 33: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

ChallengesDo you accept?

● Running docker containers

● Environment consistency & configuration

● Service discovery

● Logging

● Request routing

● Monitoring

● Updates without downtime

Page 34: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge#4 Logging

How do you determine what is happening

● at the application level● at the domain level

with minimal effort?

Page 35: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge#4 Logging

Application

Stdout & stderr available through web interface for

realtime insights.

Also logged to Elasticsearch with rich metadata for

statistics and historical insights.

Page 36: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge#4 Logging

Page 37: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge#4 Logging

Domain

Events that are sent through RabbitMQ also get

stored in Elasticsearch

Page 38: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

ChallengesDo you accept?

● Running docker containers

● Environment consistency & configuration

● Service discovery

● Logging

● Request routing

● Monitoring

● Updates without downtime

Page 39: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge#5 Request routing

AWSELB / ALB

DCOSAgents

to

How do you make sure your requests reach the correct containers?

from

Page 40: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge#5 Request routing

AWSELB / ALB DCOS

Agents

GET / HTTP/1.1Host: www.mijndomein.nl

10.0.0.1:32001

Page 41: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge#5 Request routing

AWSELB / ALB DCOS

Agents

GET /producten HTTP/1.1Host: www.mijndomein.nl

10.0.0.2:32003

Page 42: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge#5 Request routing

AWSELB / ALB DCOS

Agents

GET /login HTTP/1.1Host: auth.mijndomein.nl

10.0.0.3:32005

Page 43: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge#5 Request routing

Register your containers in the AWS ALB Complex and mistake prone

Static proxy (NGINX, Apache2, HAProxy)Large featureset but a lot of manual labour

Dynamic proxy (Fabio/Traefik)Easy but limited

Page 44: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge#5 Request routing

AWSELB / ALB DC/OS

Agentsnginx proxy

Host: w

ww

.mijndom

ein.nl

GET / HTTP/1.1

GET /producten HTTP/1.1

Host: auth.mijndomein.nl

Page 45: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge#5 Request routing

Page 46: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

ChallengesDo you accept?

● Running docker containers

● Environment consistency & configuration

● Service discovery

● Logging

● Request routing

● Monitoring

● Updates without downtime

Page 47: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge#6 Monitoring

How do you automatically check (and fix) the health of your containers?

● Marathon checks● Consul health checks● Alerting with Datadog

Page 48: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge#6 Monitoring

Marathon

Page 49: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge#6 Monitoring

Page 50: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge#6 Monitoring

Datadog

● Visualisation of all tracked metrics

● Alerting on predefined limits

○ hard thresholds (request rate == 0)

○ dynamic thresholds (disk usage suddenly grows

faster than before)

Page 51: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

ChallengesDo you accept?

● Running docker containers

● Environment consistency & configuration

● Service discovery

● Logging

● Request routing

● Monitoring

● Updates without downtime

Page 52: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge#7 Rolling updates

How do you update applications and servers without affecting your customers?

Page 53: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge#7 Rolling updates

Applications

Page 54: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge#7 Rolling updates

Page 55: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Challenge#7 Rolling updates

Servers

Page 56: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

environment consistencyChallenge#7 Rolling updatesDC/OS Agents

1a

1b

1c

Page 57: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

environment consistencyChallenge#7 Rolling updatesDC/OS Agents

1a

1b

1c

Page 58: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

environment consistencyChallenge#7 Rolling updatesDC/OS Agents

1a

1b

1c

Page 59: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

ChallengesDo you accept?

● Running docker containers

● Environment consistency & configuration

● Service discovery

● Logging

● Request routing

● Monitoring

● Updates without downtime

Page 60: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

AfterthoughtsWould we do it again?

○ Entire environment has become more complex

then before.

○ DC/OS schedules single containers, which made us

create multi-process containers.

○ Lack of namespacing forces us to separate accept

and production environments and also allows more

internal communication than necessary.

○ Secrets and ACL are not part of the Free DC/OS.

Page 61: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

AfterthoughtsWould we do it again?

○ Since setting up DC/OS we have had a 200%

increase in microservices.

○ Because Dev, Accept and Prod are so similar, we

have had nearly no bugs introduced by the

environment.

○ Introducing new microservices to production can

now be achieved in a few hours.

○ We now run over 40 unique microservices (about 75

containers) on 12 instances.

Page 62: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

AfterthoughtsWould we do it again?

Page 63: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Components

DC/OSMasters

DC/OSAgents

AWSELB / ALB

MySQL

Redis

RabbitMQ

Elasticsearch

mesosconsul

Consul

Page 64: Roy Bauweraerts & Erwin de Keijzer · behold the distributed monolith 3 dedicated aws ec2 instances per ... Docker Docker containers wrap a piece of software in a ... Applications.

Bye bye!That’s all folks

https://github.com/mijndomein/docker-in-production-talk