scaling jenkins with docker: swarm, kubernetes or mesos?

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

Upload: carlos-sanchez

Post on 16-Apr-2017

1.320 views

Category:

Software


10 download

TRANSCRIPT

Page 1: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

SCALING JENKINS WITH DOCKER

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

Watch online at carlossg.github.io/presentations

Page 2: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

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: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

DOCKER DOCKERDOCKER

Page 4: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?
Page 5: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

BUT IT IS NOT TRIVIAL

Page 6: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

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

Page 7: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?
Page 8: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

A distributed systems kernel

Page 9: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

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: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

DOCKER SWARM

Page 11: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

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

Page 12: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

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: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?
Page 14: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

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: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

SCALING JENKINSTwo options:

More build agents per masterMore masters

Page 16: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

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: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

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: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?
Page 19: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

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

automating enough

Page 20: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

RUNNING IN DOCKER

Page 21: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?
Page 22: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

CLUSTER SCHEDULINGIsolated build agents and jobs

Using Docker

Capabilities can be dropped

Page 23: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

GROUPING CONTAINERSExample:

Jenkins agentMaven buildSelenium testing in

FirefoxChromeSafari

5 containers

Page 24: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

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: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

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: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

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

Page 27: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?
Page 28: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

WHAT ABOUT THE JVM?WHAT ABOUT THE CHILD PROCESSES?

Page 29: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

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: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

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

Your container goes over CPU limits

Page 31: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

Totally different from memory

Page 32: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

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: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

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: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

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: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

NETWORKINGJenkins masters open several ports

HTTPJNLP Build agentSSH server (Jenkins CLI type operations)

Jenkins agents connect to master:

inbound (SSH)outbound (JNLP)

Page 36: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

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: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

JENKINS PLUGINS

Page 38: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

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: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?
Page 40: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?
Page 41: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?
Page 42: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?
Page 43: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

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: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

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

Definition in pipeline

Can have side containers

Just released!

Page 45: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?
Page 46: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

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

Page 47: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

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: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?
Page 49: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?
Page 50: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?
Page 51: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?
Page 52: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?
Page 53: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

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: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

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: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

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: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

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: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

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: Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?

JENKINS ONE SHOT EXECUTORImproved API to handle one off agents

Optimized for containerized agents

Plugins need to support it