scaling jenkins with docker and kubernetes

37
Scaling Jenkins with Docker and Kubernetes Carlos Sanchez @csanchez

Upload: carlos-sanchez

Post on 17-Jan-2017

31.120 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Scaling Jenkins with Docker and Kubernetes

Scaling Jenkins with Docker and Kubernetes Carlos Sanchez

@csanchez

Page 2: Scaling Jenkins with Docker and Kubernetes

About me

Senior Software Engineer @ CloudBees Author of Jenkins Kubernetes plugin Long time OSS contributor at Apache Maven, Eclipse, Puppet,…

Page 3: Scaling Jenkins with Docker and Kubernetes

Containers & micro services

Page 4: Scaling Jenkins with Docker and Kubernetes

@YourTwitterHandle

Docker

Linux containers Union File System

File System Users

Processes Network

Page 5: Scaling Jenkins with Docker and Kubernetes

But it is not trivial

Page 7: Scaling Jenkins with Docker and Kubernetes
Page 8: Scaling Jenkins with Docker and Kubernetes
Page 9: Scaling Jenkins with Docker and Kubernetes
Page 10: Scaling Jenkins with Docker and Kubernetes

Kubernetes

Page 11: Scaling Jenkins with Docker and Kubernetes

Kubernetes

Container cluster orchestration Docker containers across multiple hosts (nodes or minions)

Higher level API Enforced state Monitoring of endpoints

Page 12: Scaling Jenkins with Docker and Kubernetes
Page 13: Scaling Jenkins with Docker and Kubernetes

Master

Kubernetes API Server scheduling and synchronization

etcd Kubernetes Controller Manager Server

implements replication algorithm watching etcd

Page 14: Scaling Jenkins with Docker and Kubernetes

Node

Docker Kubelet

ensures state of Pods Kubernetes Proxy

simple network proxy etcd SkyDNS ElasticSearch + Kibana

Page 15: Scaling Jenkins with Docker and Kubernetes
Page 16: Scaling Jenkins with Docker and Kubernetes

Providers

GKE Azure Vmware Rackspace oVirt Vagrant CloudStack Ubuntu

Page 17: Scaling Jenkins with Docker and Kubernetes

PodGroup of colocated containers Same network namespace/IP Environment variables Shared volumes

host mounted empty volumes GCE data disks AWS EBS volumes nfs glusterfs secrets

Page 18: Scaling Jenkins with Docker and Kubernetes

@YourTwitterHandle

Pods

Node

client

kubelet

pods

Master

Node

kubelet

pods

Node

kubelet

pods

… … …

Page 19: Scaling Jenkins with Docker and Kubernetes

Pod

kind: "Pod" apiVersion: "v1" metadata: name: "jenkins" labels: name: "jenkins" spec: containers: - name: "jenkins" image: "csanchez/jenkins-swarm:1.625.1-for-volumes" ports: - containerPort: 8080 - containerPort: 50000 volumeMounts: - name: "jenkins-data" mountPath: "/var/jenkins_home" volumes: - name: "jenkins-data" hostPath: path: "/home/docker/jenkins"

Page 20: Scaling Jenkins with Docker and Kubernetes

Replication controller

Ensure a number of pods are running Pod templates Rolling update

podpod

pod

container

container

container

Page 21: Scaling Jenkins with Docker and Kubernetes

@YourTwitterHandle

Replication controllers

Node

client

podA

Master

Node

podA

Node

podB

podA podB

Page 22: Scaling Jenkins with Docker and Kubernetes
Page 23: Scaling Jenkins with Docker and Kubernetes

Replication controller apiVersion: "v1" kind: "ReplicationController" metadata: name: "jenkins" labels: name: "jenkins" spec: replicas: 1 template: metadata: name: "jenkins" labels: name: "jenkins" spec: containers: - name: "jenkins" image: "csanchez/jenkins-swarm:1.625.1-for-volumes" ports: - containerPort: 8080 - containerPort: 50000 volumeMounts: - name: "jenkins-data" mountPath: "/var/jenkins_home" volumes: - name: "jenkins-data" hostPath: path: "/var/jenkins"

Page 24: Scaling Jenkins with Docker and Kubernetes

Services

Pod discovery IP per service Route to pods selected with labels Can create a load balancer in GCE and AWS

Page 25: Scaling Jenkins with Docker and Kubernetes

@YourTwitterHandle

Services

client

pod

Service

pod pod

Page 26: Scaling Jenkins with Docker and Kubernetes

Services

apiVersion: "v1" kind: "Service" metadata: name: "jenkins" spec: type: "LoadBalancer" selector: name: "jenkins" ports: - name: "http" port: 80 targetPort: 8080 protocol: "TCP" - name: "slave" port: 50000 protocol: "TCP"

Page 27: Scaling Jenkins with Docker and Kubernetes

Kubernetes cluster with docker-compose

# Docker Compose definition for a one node Kubernetes cluster# Based on Docker Cookbook example# https://github.com/how2dock/docbook/ch05/dockeretcd: image: kubernetes/etcd:2.0.5.1 net: "host" command: /usr/local/bin/etcd --addr=127.0.0.1:4001 --bind-addr=0.0.0.0:4001 --data-dir=/var/etcd/datamaster: image: gcr.io/google_containers/hyperkube:v1.0.1 net: "host" volumes: - /var/run/docker.sock:/var/run/docker.sock command: /hyperkube kubelet --api_servers=http://localhost:8080 --v=2 --address=0.0.0.0 --enable_server --hostname_override=127.0.0.1 --config=/etc/kubernetes/manifestsproxy: image: gcr.io/google_containers/hyperkube:v1.0.1 net: "host" privileged: true command: /hyperkube proxy --master=http://127.0.0.1:8080 --v=2

Page 28: Scaling Jenkins with Docker and Kubernetes

Kubernetes and Jenkins

Page 29: Scaling Jenkins with Docker and Kubernetes

@YourTwitterHandle

Initial solution

Pod

Jenkins master

Replication Controller Slaves

slave 3

slave 2Google Persistent Disk

slave 1

Page 30: Scaling Jenkins with Docker and Kubernetes

@YourTwitterHandle

slave 2 (on demand pod)

Replication controller

Improved solutionReplication controller

Jenkins master

Google Persistent Disk

slave 1 (on demand pod)

CloudBees Jenkins Operations Center

Google Persistent Disk

Replication controller

Jenkins master

Replication controller

Jenkins master

Replication controller

Jenkins master

Replication controllers

Jenkins master

slave 3 (on demand pod)

Page 31: Scaling Jenkins with Docker and Kubernetes

Kubernetes Jenkins plugin

Page 32: Scaling Jenkins with Docker and Kubernetes

Kubernetes Jenkins plugin

As a plugin on demand slaves

https://github.com/jenkinsci/kubernetes-plugin

Page 33: Scaling Jenkins with Docker and Kubernetes
Page 34: Scaling Jenkins with Docker and Kubernetes
Page 35: Scaling Jenkins with Docker and Kubernetes

Roadmap

Stable API When Kubernetes Java lib is stable

Using new Jenkins Cloud/Containers APIs Use jobs in Kubernetes 1.1

Page 36: Scaling Jenkins with Docker and Kubernetes

Example code and slides

Available at http://slideshare.csanchez.org https://github.com/jenkinsci/kubernetes-plugin https://github.com/carlossg/kubernetes-jenkins http://blog.csanchez.org

Page 37: Scaling Jenkins with Docker and Kubernetes

Gracias!