swarm, kubernetes or mesos? - cloudbees.com

59
SCALING JENKINS WITH DOCKER SWARM, KUBERNETES OR MESOS? / / Carlos Sanchez csanchez.org @csanchez Watch online at carlossg.github.io/presentations

Upload: duongdung

Post on 03-Jan-2017

235 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: SWARM, KUBERNETES OR MESOS? - cloudbees.com

SCALING JENKINS WITH DOCKER

SWARM, KUBERNETES OR MESOS? / / Carlos Sanchez csanchez.org @csanchez

Watch online at carlossg.github.io/presentations

Page 2: SWARM, KUBERNETES OR MESOS? - cloudbees.com

ABOUT MEEngineer @ CloudBees, Private SaaS Edition Team

Contributor to

Jenkins Mesos plugin

Jenkins and Maven official Docker images

Author of Jenkins Kubernetes plugin

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

Page 3: SWARM, KUBERNETES OR MESOS? - cloudbees.com

DOCKER DOCKERDOCKER

Page 4: SWARM, KUBERNETES OR MESOS? - cloudbees.com
Page 5: SWARM, KUBERNETES OR MESOS? - cloudbees.com

BUT IT IS NOT TRIVIAL

Page 6: SWARM, KUBERNETES OR MESOS? - cloudbees.com

CLUSTER SCHEDULINGRunning in public cloud, private cloud, VMs or bare metalHA and fault tolerantWith Docker support of course

Page 7: SWARM, KUBERNETES OR MESOS? - cloudbees.com
Page 8: SWARM, KUBERNETES OR MESOS? - cloudbees.com

A distributed systems kernel

Page 9: SWARM, KUBERNETES OR MESOS? - cloudbees.com

APACHE MESOSStarted before 2011Runs tasks, any binary or Docker, rkt, appc imagesFrameworks run on top of Mesos

Mesosphere Marathon: long running servicesApache Aurora: long running servicesChronos: distributed cron-like system

Used in Twitter, Airbnb, eBay, Apple, Verizon, Yelp,...

Page 10: SWARM, KUBERNETES OR MESOS? - cloudbees.com

DOCKER SWARM

Page 11: SWARM, KUBERNETES OR MESOS? - cloudbees.com

DOCKER SWARMBy Docker Inc.Uses the same Docker APINo need to modify existing tooling

Page 12: SWARM, KUBERNETES OR MESOS? - cloudbees.com

DOCKER ENGINE SWARM MODENew in Docker 1.12No need to install extra so�ware, each daemon can run asa Swarm memberNew service object to describe distributed containers

Existing tooling needs to be updated

Swarm mode

Page 13: SWARM, KUBERNETES OR MESOS? - cloudbees.com
Page 14: SWARM, KUBERNETES OR MESOS? - cloudbees.com

KUBERNETESBased on Google BorgRun in local machine, virtual, cloudGoogle provides Google Container Engine (GKE)Other services run by stackpoint.io, CoreOS Tectonic,Azure,...Minikube for local testing

Page 15: SWARM, KUBERNETES OR MESOS? - cloudbees.com

SCALING JENKINSTwo options:

More build agents per masterMore masters

Page 16: SWARM, KUBERNETES OR MESOS? - cloudbees.com

SCALING JENKINS: MORE BUILDAGENTS

Pros

Multiple plugins to add more agents, even dynamically

Cons

The master is still a SPOFHandling multiple configurations, plugin versions,...There is a limit on how many build agents can beattached

Page 17: SWARM, KUBERNETES OR MESOS? - cloudbees.com

SCALING JENKINS: MORE MASTERSPros

Different sub-organizations can self service and operateindependently

Cons

Single Sign-OnCentralized configuration and operation

Covered by CloudBees Jenkins Operations Center andCloudBees Jenkins Platform Private SaaS Edition

Page 18: SWARM, KUBERNETES OR MESOS? - cloudbees.com
Page 19: SWARM, KUBERNETES OR MESOS? - cloudbees.com

If you haven't automatically destroyedsomething by mistake, you are not

automating enough

Page 20: SWARM, KUBERNETES OR MESOS? - cloudbees.com

RUNNING IN DOCKER

Page 21: SWARM, KUBERNETES OR MESOS? - cloudbees.com
Page 22: SWARM, KUBERNETES OR MESOS? - cloudbees.com

CLUSTER SCHEDULINGIsolated build agents and jobs

Using Docker

Capabilities can be dropped

Page 23: SWARM, KUBERNETES OR MESOS? - cloudbees.com

GROUPING CONTAINERSExample:

Jenkins agentMaven buildSelenium testing in

FirefoxChromeSafari

5 containers

Page 24: SWARM, KUBERNETES OR MESOS? - cloudbees.com

GROUPING CONTAINERSMesos In progress

Swarm Supports grouping through DockerComposeCan force execution in the same host

Kubernetes Supports the concept of Pods nativelyAll running in the same host

MESOS-2449

Page 25: SWARM, KUBERNETES OR MESOS? - cloudbees.com

MEMORY LIMITSScheduler needs to account for container memory

requirements and host available memory

Prevent containers for using more memory than allowed

Mesos required

Swarm optional

Kubernetes optional (plus namespaces)

Memory constrains translate to Docker --memory

Page 26: SWARM, KUBERNETES OR MESOS? - cloudbees.com

WHAT DO YOU THINK HAPPENS WHEN?Your container goes over memory quota?

Page 27: SWARM, KUBERNETES OR MESOS? - cloudbees.com
Page 28: SWARM, KUBERNETES OR MESOS? - cloudbees.com

WHAT ABOUT THE JVM?WHAT ABOUT THE CHILD PROCESSES?

Page 29: SWARM, KUBERNETES OR MESOS? - cloudbees.com

CPU LIMITSScheduler needs to account for container CPU requirements

and host available CPUs

Mesos required

Swarm optional

Kubernetes optional (plus namespaces)

CPU translates into Docker --cpu-shares

Page 30: SWARM, KUBERNETES OR MESOS? - cloudbees.com

WHAT DO YOU THINK HAPPENS WHEN?Your container tries to access more than one CPU

Your container goes over CPU limits

Page 31: SWARM, KUBERNETES OR MESOS? - cloudbees.com

Totally different from memory

Page 32: SWARM, KUBERNETES OR MESOS? - cloudbees.com

STORAGEHandling distributed storage

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

Mesos in 1.0+

Swarm Docker volume plugins: RexRay, Convoy,Flocker,...

Kubernetes

Docker volume support

Persistent volumes

Page 33: SWARM, KUBERNETES OR MESOS? - cloudbees.com

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 34: SWARM, KUBERNETES OR MESOS? - cloudbees.com

CAVEATSOnly a limited number of EBS volumes can be mounted

Docs say /dev/sd[f-p], but /dev/sd[q-z] seem towork too

NFS users must be centralized and match in cluster and NFSserver

Page 35: SWARM, KUBERNETES OR MESOS? - cloudbees.com

NETWORKINGJenkins masters open several ports

HTTPJNLP Build agentSSH server (Jenkins CLI type operations)

Jenkins agents connect to master:

inbound (SSH)outbound (JNLP)

Page 36: SWARM, KUBERNETES OR MESOS? - cloudbees.com

Allows getting one IP per container

Mesos : Calico, Weave

Swarm , and others from plugins

Kubernetes Multiple : GCE, Weave,Calico,...

Network Isolator Modules

Docker overlay

networking options

Page 37: SWARM, KUBERNETES OR MESOS? - cloudbees.com

JENKINS PLUGINS

Page 38: SWARM, KUBERNETES OR MESOS? - cloudbees.com

JENKINS DOCKER PLUGINSDynamic Jenkins agents with Docker plugin or Yet AnotherDocker Plugin

No support yet for Docker 1.12 Swarm modeAgent image needs to include Java, downloads slave jarfrom Jenkins masterMultiple plugins for different tasks

Docker build and publishDocker build step pluginCloudBees Docker Hub/Registry NotificationCloudBees Docker Traceability

Great pipeline support

Page 39: SWARM, KUBERNETES OR MESOS? - cloudbees.com
Page 40: SWARM, KUBERNETES OR MESOS? - cloudbees.com
Page 41: SWARM, KUBERNETES OR MESOS? - cloudbees.com
Page 42: SWARM, KUBERNETES OR MESOS? - cloudbees.com
Page 43: SWARM, KUBERNETES OR MESOS? - cloudbees.com

JENKINS DOCKER PIPELINEdef maven = docker.image('maven:3.3.9-jdk-8');

stage 'Mirror'maven.pull()docker.withRegistry('https://secure-registry/', 'docker-registry-login'

stage 'Build' maven.inside { sh "mvn -B clean package" }

stage 'Bake Docker image' def pcImg = docker.build("examplecorp/spring-petclinic:${env.BUILD_TAG}"

pcImg.push();}

Page 44: SWARM, KUBERNETES OR MESOS? - cloudbees.com

JENKINS DOCKER SLAVES PLUGINUse any Docker image, no need for Java

Definition in pipeline

Can have side containers

Just released!

Page 45: SWARM, KUBERNETES OR MESOS? - cloudbees.com
Page 46: SWARM, KUBERNETES OR MESOS? - cloudbees.com

Building MavendockerNode("maven:3.3.3-jdk-8") { sh "mvn -version"}

Page 47: SWARM, KUBERNETES OR MESOS? - cloudbees.com

JENKINS MESOS PLUGINDynamic Jenkins agents, both Docker and isolatedprocessesAgent image needs to include Java, grabs slave jar fromMesos sandboxCan run Docker commands on the host, outside of Mesos

Page 48: SWARM, KUBERNETES OR MESOS? - cloudbees.com
Page 49: SWARM, KUBERNETES OR MESOS? - cloudbees.com
Page 50: SWARM, KUBERNETES OR MESOS? - cloudbees.com
Page 51: SWARM, KUBERNETES OR MESOS? - cloudbees.com
Page 52: SWARM, KUBERNETES OR MESOS? - cloudbees.com
Page 53: SWARM, KUBERNETES OR MESOS? - cloudbees.com

JENKINS MESOS PLUGINCan use Docker pipelines with some tricks

Need Docker client installedShared docker.sock from hostMount the workspace in the host, visible under same dir

Page 54: SWARM, KUBERNETES OR MESOS? - cloudbees.com

MESOS PLUGIN AND PIPELINEnode('docker') { docker.image('golang:1.6').inside {

stage 'Get sources' git url: 'https://github.com/hashicorp/terraform.git', tag: "v0.6.15"

stage 'Build' sh """#!/bin/bash -e mkdir -p /go/src/github.com/hashicorp ln -s ̀pwd̀ /go/src/github.com/hashicorp/terraform pushd /go/src/github.com/hashicorp/terraform make core-dev plugin-dev PLUGIN=provider-aws popd cp /go/bin/terraform-provider-aws . """

stage 'Archive' archive "terraform-provider-aws" }}

Page 55: SWARM, KUBERNETES OR MESOS? - cloudbees.com

JENKINS KUBERNETES PLUGINDynamic Jenkins agents, running as PodsMultiple container support

One jnlp image, others customPipeline support for both agent Pod definition andexecution will be in next version

Page 56: SWARM, KUBERNETES OR MESOS? - cloudbees.com

JENKINS KUBERNETES PIPELINEpodTemplate(label: 'mypod', containers: [ [name: 'jnlp', image: 'jenkinsci/jnlp-slave:alpine', args: '${computer.jnlpmac} ${computer.name}' [name: 'maven', image: 'maven:3-jdk-8', ttyEnabled: true, command: [name: 'golang', image: 'golang:1.6', ttyEnabled: true, command: ]) {

node ('mypod') { stage 'Get a Maven project' git 'https://github.com/jenkinsci/kubernetes-plugin.git' container('maven') { stage 'Build a Maven project' sh 'mvn clean install' }

stage 'Get a Golang project' git url: 'https://github.com/hashicorp/terraform.git' container('golang') { stage 'Build a Go project' sh """ mkdir -p /go/src/github.com/hashicorp ln -s ̀pwd̀ /go/src/github.com/hashicorp/terraform cd /go/src/github.com/hashicorp/terraform && make core-dev """ } }

Page 57: SWARM, KUBERNETES OR MESOS? - cloudbees.com

JENKINS PLUGINS RECAPDynamic Jenkins agent creationUsing JNLP slave jar

In complex environments need to use the tunneloption to connect internally

Using the Cloud APINot ideal for containerized workloadAgents take > 1 min to start provision and are keptaroundAgents can provide more than one executor

Page 58: SWARM, KUBERNETES OR MESOS? - cloudbees.com

JENKINS ONE SHOT EXECUTORImproved API to handle one off agents

Optimized for containerized agents

Plugins need to support it