from monolith to docker distributed applications · from monolith to docker distributed...

52
FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez @csanchez Watch online at carlossg.github.io/presentations

Upload: vohanh

Post on 27-May-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

FROM MONOLITH TO DOCKERDISTRIBUTED APPLICATIONS

Carlos Sanchez

@csanchezWatch online at carlossg.github.io/presentations

Page 2: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

ABOUT MESenior So�ware Engineer @ CloudBees

Author of Jenkins Kubernetes plugin

Long time OSS contributor at Apache Maven, Eclipse,Puppet,…

Page 3: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

DOCKER DOCKER DOCKER

Page 4: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks
Page 5: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

OUR USE CASE

Scaling JenkinsYour mileage may vary

Page 6: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks
Page 7: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks
Page 8: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks
Page 9: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks
Page 10: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

A 2000 JENKINS MASTERS CLUSTER3 Mesos masters (m3.xlarge: 4 vCPU, 15GB, 2x40 SSD)317 Mesos slaves (c3.2xlarge, m3.xlarge, m4.4xlarge)7 Mesos slaves dedicated to ElasticSearch: (c3.8xlarge: 32vCPU, 60GB)

12.5 TB - 3748 CPU

Running 2000 masters and ~8000 concurrent jobs

Page 11: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

ARCHITECTURE

Page 12: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks
Page 13: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

Isolated Jenkins masters

Isolated build agents and jobs

Memory and CPU limits

Page 14: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks
Page 15: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks
Page 16: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

CLUSTER SCHEDULINGDistribute tasks across a cluster of hosts

Running in public cloud, private cloud, VMs or bare metal

HA and fault tolerant

With Docker support of course

Page 17: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

APACHE MESOS

A distributed systems kernel

Page 18: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

ALTERNATIVES

Docker Swarm / Kubernetes

Page 19: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

MESOSPHERE MARATHON

Page 20: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

TERRAFORM

Page 21: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

TERRAFORMresource "aws_instance" "worker" { count = 1 instance_type = "m3.large" ami = "ami-xxxxxx" key_name = "tiger-csanchez" security_groups = ["sg-61bc8c18"] subnet_id = "subnet-xxxxxx" associate_public_ip_address = true tags { Name = "tiger-csanchez-worker-1" "cloudbees:pse:cluster" = "tiger-csanchez" "cloudbees:pse:type" = "worker" } root_block_device { volume_size = 50 }}

Page 22: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

TERRAFORMState is managedRuns are idempotentterraform apply

Sometimes it is too automaticChanging image id will restart all instances

Page 23: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks
Page 24: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

IF YOU HAVEN'T AUTOMATICALLYDESTROYED SOMETHING BY

MISTAKE,YOU ARE NOT AUTOMATING ENOUGH

Page 26: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks
Page 27: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks
Page 28: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

STORAGEHandling distributed storage

Servers can start in any host of the cluster

And they can move when they are restarted

Page 29: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

DOCKER VOLUME PLUGINSFlockerGlusterFSNFSEBS

Page 30: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

KUBERNETESGCE disksFlockerGlusterFSNFSEBS

Page 31: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

SIDEKICK CONTAINERA privileged container that manages mounting for other

containers

Can execute commands in the host and other containers

Page 32: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

A lot of magic happening with nsenter

Page 33: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

IN OUR CASESidekick container

Jenkins masters need persistent storage, build agents(typically) don't

Supporting EBS (AWS) and external NFS

Page 34: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

PERMISSIONSContainers should not run as root

Container user id != host user id

i.e. jenkins user in container is always 1000 but matchesubuntu user in host

Page 35: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

MEMORYScheduler needs to account for container memory

requirements and host available memory

Prevent containers for using more memory than allowed

Memory constrains translate to Docker --memory

Page 36: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

WHAT DO YOU THINK HAPPENSWHEN?

Your container goes over memory quota?

Page 37: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks
Page 38: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

WHAT ABOUT THE JVM?WHAT ABOUT THE CHILD

PROCESSES?

Page 39: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

CPUScheduler needs to account for container CPU requirements

and host available CPUs

Page 40: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

WHAT DO YOU THINK HAPPENSWHEN?

Your container tries to access more than one CPU

Your container goes over CPU limits

Page 41: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

Totally different from memory

Mesos/Kubernetes CPU translates into Docker --cpu-shares

Page 42: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

NETWORKINGMultiple services running in the same ports

Must redirect from random ports in the host

Services running in one host need to access services in otherhosts

Page 43: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

NETWORKING: SERVICE DISCOVERYDNS is not great, caching can happen at multiple levels

marathon-lb uses haproxy and Marathon API

A typical nginx reverse proxy is also easy to setup

Page 44: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

NETWORKING: SOFTWARE DEFINEDNETWORKS

Create new custom networks on top of physical networks

Allow grouping containers in subnets

Page 45: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

NETWORKING: SOFTWARE DEFINEDNETWORKS

Battlefield: Calico, Flannel, Weave and Docker OverlayNetwork

http://chunqi.li/2015/11/15/Battlefield-Calico-Flannel-Weave-and-Docker-Overlay-Network/

Page 46: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

SCALINGNew and interesting problems

Page 47: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

LOGGINGRunning ElasticSearch as a cluster service, and the ELK stack

Docker configured to log to syslog

Logstash redirecting syslog to ElasticSearch

Embedded Kibana dashboard in CloudBees JenkinsOperations Center

Page 48: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

AWSResource limits: VPCs, S3 snapshots, some instance sizes

Rate limits: affect the whole account

Retrying is your friend, but with exponential backoff

Page 49: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

EMBRACE FAILURE!

Page 50: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

OPENSTACKCustom flavors

Custom images

Different CLI commands

There are not two OpenStack installations that are the same

Page 51: FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS · FROM MONOLITH TO DOCKER DISTRIBUTED APPLICATIONS Carlos Sanchez ... HA and fault tolerant ... NFS EBS. KUBERNETES GCE disks

UPGRADES /MAINTENANCE

Moving containers from hosts

Draining hosts

Rolling updates

Blue/Green deployment

Immutable infrastructure