SlideShare a Scribd company logo
USING CONTAINERS FOR
CONTINUOUS INTEGRATION
AND
CONTINUOUS DELIVERY
Carlos Sanchez
/csanchez.org @csanchez
Watch online at carlossg.github.io/presentations
ABOUT ME
Engineer @ CloudBees, Scaling Jenkins
Author of Jenkins Kubernetes plugin
Contributor to Jenkins Mesos plugin & Jenkins and Maven
official Docker images
Long time OSS contributor at Apache Maven, Eclipse,
Puppet,…
DOCKER DOCKER
DOCKER
Using containers for continuous integration and continuous delivery - Carlos Sanchez
USING CONTAINERS IS NOT TRIVIAL
Using containers for continuous integration and continuous delivery - Carlos Sanchez
SCALING JENKINS
Two options:
More build agents per master
More masters
SCALING JENKINS: MORE BUILD
AGENTS
Pros
Multiple plugins to add more agents, even dynamically
Cons
The master is still a SPOF
Handling multiple configurations, plugin versions,...
There is a limit on how many build agents can be
attached
SCALING JENKINS: MORE MASTERS
Pros
Different sub-organizations can self service and operate
independently
Cons
Single Sign-On
Centralized configuration and operation
Covered by CloudBees Jenkins Enterprise
DOCKER AND JENKINS
RUNNING IN DOCKER
Using containers for continuous integration and continuous delivery - Carlos Sanchez
Using containers for continuous integration and continuous delivery - Carlos Sanchez
JENKINS DOCKER PLUGINS
Dynamic Jenkins agents with Docker plugin or Yet Another
Docker Plugin
No support yet for Docker Swarm mode
Isolated build agents and jobs
Agent image needs to include Java, downloads slave jar
from Jenkins master
JENKINS DOCKER PLUGINS
Multiple plugins for different tasks
Docker build and publish
Docker build step plugin
CloudBees Docker Hub/Registry Notification
CloudBees Docker Traceability
Great pipeline support
Using containers for continuous integration and continuous delivery - Carlos Sanchez
Using containers for continuous integration and continuous delivery - Carlos Sanchez
JENKINS DOCKER PIPELINE
def 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}", 'app')
pcImg.push();
}
}
WHEN ONE MACHINE IS NO LONGER
ENOUGH
Running Docker across multiple hosts
In public cloud, private cloud, VMs or bare metal
HA and fault tolerant
Using containers for continuous integration and continuous delivery - Carlos Sanchez
If you haven't automatically destroyed
something by mistake, you are not
automating enough
Using containers for continuous integration and continuous delivery - Carlos Sanchez
Using containers for continuous integration and continuous delivery - Carlos Sanchez
KUBERNETES
Based on Google Borg
Run in local machine, virtual, cloud
Google provides Google Container Engine (GKE)
Other services run by stackpoint.io, CoreOS Tectonic,
Azure,...
Minikube for local testing
GROUPING CONTAINERS (PODS)
Example:
Jenkins agent
Maven build
Selenium Hub with
Firefox
Chrome
5 containers
STORAGE
Jenkins masters need persistent storage, agents (maybe)
Persistent volumes
GCE disks
GlusterFS
NFS
EBS
etc
PERMISSIONS
Containers should not run as root
Container user id != host user id
i.e. jenkins user in container is always 1000 but matches
ubuntu user in host
PERMISSIONS
containers: [...]
securityContext:
fsGroup: 1000
volumes: [...]
Volumes which support ownership
management are modified to be owned
and writable by the GID specified in fsGroup
NETWORKING
Jenkins masters open several ports
HTTP
JNLP Build agent
SSH server (Jenkins CLI type operations)
Jenkins agents connect to master:
inbound (SSH)
outbound (JNLP)
Multiple :networking options
GCE, Flannel, Weave, Calico,...
One IP per Pod
Containers can find other containers in the same Pod using
localhost
MEMORY LIMITS
Scheduler needs to account for container memory
requirements and host available memory
Prevent containers for using more memory than allowed
Memory constraints translate to Docker --memory
https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/#how-
pods-with-resource-limits-are-run
WHAT DO YOU THINK HAPPENS WHEN?
Your container goes over memory quota?
Using containers for continuous integration and continuous delivery - Carlos Sanchez
NEW JVM SUPPORT FOR CONTAINERS
JDK 8u131+ and JDK 9
$ docker run -m 1GB openjdk:8u131 java 
-XX:+UnlockExperimentalVMOptions 
-XX:+UseCGroupMemoryLimitForHeap 
-XshowSettings:vm -version
VM settings:
Max. Heap Size (Estimated): 228.00M
Ergonomics Machine Class: server
Using VM: OpenJDK 64-Bit Server VM
Running a JVM in a Container Without Getting Killed
https://blog.csanchez.org/2017/05/31/running-a-jvm-in-a-container-without-getting-killed
NEW JVM SUPPORT FOR CONTAINERS
$ docker run -m 1GB openjdk:8u131 java 
-XX:+UnlockExperimentalVMOptions 
-XX:+UseCGroupMemoryLimitForHeap 
-XX:MaxRAMFraction=1 -XshowSettings:vm -version
VM settings:
Max. Heap Size (Estimated): 910.50M
Ergonomics Machine Class: server
Using VM: OpenJDK 64-Bit Server VM
Running a JVM in a Container Without Getting Killed
https://blog.csanchez.org/2017/05/31/running-a-jvm-in-a-container-without-getting-killed
CPU LIMITS
Scheduler needs to account for container CPU requirements
and host available CPUs
CPU requests translates into Docker --cpu-shares
CPU limits translates into Docker --cpu-quota
https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/#how-
pods-with-resource-limits-are-run
WHAT DO YOU THINK HAPPENS WHEN?
Your container tries to access more than one CPU
Your container goes over CPU limits
Totally different from memory
JENKINS KUBERNETES PLUGIN
Dynamic Jenkins agents, running as Pods
Multiple container support
One jnlp image, others custom
Pipeline support for both agent Pod definition and
execution
Persistent workspace
JENKINS KUBERNETES PIPELINE
podTemplate(label: 'maven', containers: [
containerTemplate(name: 'maven', image: 'maven:3.3.9-jdk-8-alpine'
ttyEnabled: true, command: 'cat') ]) {
node('maven') {
stage('Get a Maven project') {
git 'https://github.com/jenkinsci/kubernetes-plugin.git'
container('maven') {
stage('Build a Maven project') {
sh 'mvn -B clean package'
}
}
}
}
}
Multi-language Pipeline
podTemplate(label: 'maven-golang', containers: [
containerTemplate(name: 'maven', image: 'maven:3.3.9-jdk-8-alpine',
ttyEnabled: true, command: 'cat'),
containerTemplate(name: 'golang', image: 'golang:1.8.0',
ttyEnabled: true, command: 'cat')]) {
node('maven-golang') {
stage('Build a Maven project') {
git 'https://github.com/jenkinsci/kubernetes-plugin.git'
container('maven') {
sh 'mvn -B clean package'
}
}
stage('Build a Golang project') {
git url: 'https://github.com/hashicorp/terraform.git'
container('golang') {
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
"""
}
}
}
JENKINS PLUGINS CAVEATS
Using the Cloud API
Not ideal for containerized workload
Agents take > 1 min to start provision and are kept
around
Agents can provide more than one executor
JENKINS PLUGINS CAVEATS
One Shot Executor
Improved API to handle one off agents
Optimized for containerized agents
Plugins need to support it
MERCI
csanchez.org
csanchez
carlossg

More Related Content

PDF
Production FS: Adapt or die - Claudia Beresford & Tiago Scolar
PDF
Security in a containerized world - Jessie Frazelle
PDF
There is no container - Ori Pekelman
PDF
[DockerCon 2019] Hardening Docker daemon with Rootless mode
PDF
時代在變 Docker 要會:台北 Docker 一日入門篇
PDF
Docker 導入:障礙與對策
PDF
手把手帶你學 Docker 入門篇
PPTX
Deploying windows containers with kubernetes
Production FS: Adapt or die - Claudia Beresford & Tiago Scolar
Security in a containerized world - Jessie Frazelle
There is no container - Ori Pekelman
[DockerCon 2019] Hardening Docker daemon with Rootless mode
時代在變 Docker 要會:台北 Docker 一日入門篇
Docker 導入:障礙與對策
手把手帶你學 Docker 入門篇
Deploying windows containers with kubernetes

What's hot (20)

PDF
桃園市教育局Docker技術入門與實作
PPTX
Containers without docker
PDF
Automatically Renew Certificated In Your Kubernetes Cluster
PDF
Docker 101 @KACST Saudi HPC 2016
PDF
Docker Security: Are Your Containers Tightly Secured to the Ship?
PDF
Kubernetes上で動作する機械学習モジュールの配信&管理基盤Rekcurd について
ODP
Docker engine - Indroduc
PPTX
Monitoring, Logging and Tracing on Kubernetes
PDF
Docker 初探,實驗室中的運貨鯨
PDF
Paris container day june17
PDF
How to easy deploy app into any cloud
PPTX
The state of containerd
PDF
Docker研習營
PPTX
HP Advanced Technology Group: Docker and Ansible
PDF
猿でもわかる Helm
PDF
Docker 進階實務班
PPTX
Hide your development environment and application in a container
PPTX
Intro to Docker and clustering with Rancher from scratch
PDF
Leveraging the Power of containerd Events - Evan Hazlett
桃園市教育局Docker技術入門與實作
Containers without docker
Automatically Renew Certificated In Your Kubernetes Cluster
Docker 101 @KACST Saudi HPC 2016
Docker Security: Are Your Containers Tightly Secured to the Ship?
Kubernetes上で動作する機械学習モジュールの配信&管理基盤Rekcurd について
Docker engine - Indroduc
Monitoring, Logging and Tracing on Kubernetes
Docker 初探,實驗室中的運貨鯨
Paris container day june17
How to easy deploy app into any cloud
The state of containerd
Docker研習營
HP Advanced Technology Group: Docker and Ansible
猿でもわかる Helm
Docker 進階實務班
Hide your development environment and application in a container
Intro to Docker and clustering with Rancher from scratch
Leveraging the Power of containerd Events - Evan Hazlett
Ad

Similar to Using containers for continuous integration and continuous delivery - Carlos Sanchez (20)

PDF
Using Kubernetes for Continuous Integration and Continuous Delivery
PDF
Using Kubernetes for Continuous Integration and Continuous Delivery. Java2days
PDF
Using Containers for Building and Testing: Docker, Kubernetes and Mesos. FOSD...
PDF
Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?
PDF
Testing Distributed Micro Services. Agile Testing Days 2017
PDF
CI and CD at Scale: Scaling Jenkins with Docker and Apache Mesos
PDF
From Monolith to Docker Distributed Applications
PDF
Using Containers for Continuous Integration and Continuous Delivery. KubeCon ...
PDF
CI and CD at Scale: Scaling Jenkins with Docker and Apache Mesos
PDF
Containerising bootiful microservices javaeeconf
PDF
Dockerized maven
PDF
Docker + jenkins in the enterprise (3)
PDF
From Monolith to Docker Distributed Applications. JavaOne
PDF
Achieving CI/CD with Kubernetes
PDF
Get you Java application ready for Kubernetes !
PDF
Fabric8: Better Software Faster with Docker, Kubernetes, Jenkins
PDF
DCSF19 Docker Containers & Java: What I Wish I Had Been Told
PDF
Cloud read java with kubernetes
PDF
Microservices with Kubernetes, Docker, and Jenkins
PDF
Microservices with Docker, Kubernetes, and Jenkins
Using Kubernetes for Continuous Integration and Continuous Delivery
Using Kubernetes for Continuous Integration and Continuous Delivery. Java2days
Using Containers for Building and Testing: Docker, Kubernetes and Mesos. FOSD...
Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?
Testing Distributed Micro Services. Agile Testing Days 2017
CI and CD at Scale: Scaling Jenkins with Docker and Apache Mesos
From Monolith to Docker Distributed Applications
Using Containers for Continuous Integration and Continuous Delivery. KubeCon ...
CI and CD at Scale: Scaling Jenkins with Docker and Apache Mesos
Containerising bootiful microservices javaeeconf
Dockerized maven
Docker + jenkins in the enterprise (3)
From Monolith to Docker Distributed Applications. JavaOne
Achieving CI/CD with Kubernetes
Get you Java application ready for Kubernetes !
Fabric8: Better Software Faster with Docker, Kubernetes, Jenkins
DCSF19 Docker Containers & Java: What I Wish I Had Been Told
Cloud read java with kubernetes
Microservices with Kubernetes, Docker, and Jenkins
Microservices with Docker, Kubernetes, and Jenkins
Ad

More from Paris Container Day (6)

PDF
Living the Nomadic life - Nic Jackson
PDF
Advanced Task Scheduling with Amazon ECS - Julien Simon
PDF
Monitoring de conteneurs en production - Jonathan Raffre & Jean-Pascal Thiery
PDF
End to-end monitoring with the prometheus operator - Max Inden
PDF
Nomad, l'orchestration made in Hashicorp - Bastien Cadiot
PDF
OpenShift en production - Akram Ben Assi & Eloïse Faure
Living the Nomadic life - Nic Jackson
Advanced Task Scheduling with Amazon ECS - Julien Simon
Monitoring de conteneurs en production - Jonathan Raffre & Jean-Pascal Thiery
End to-end monitoring with the prometheus operator - Max Inden
Nomad, l'orchestration made in Hashicorp - Bastien Cadiot
OpenShift en production - Akram Ben Assi & Eloïse Faure

Recently uploaded (20)

PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Encapsulation theory and applications.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
A comparative analysis of optical character recognition models for extracting...
PPTX
Big Data Technologies - Introduction.pptx
PDF
Electronic commerce courselecture one. Pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Machine learning based COVID-19 study performance prediction
Unlocking AI with Model Context Protocol (MCP)
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Encapsulation theory and applications.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Assigned Numbers - 2025 - Bluetooth® Document
MIND Revenue Release Quarter 2 2025 Press Release
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
MYSQL Presentation for SQL database connectivity
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Reach Out and Touch Someone: Haptics and Empathic Computing
Review of recent advances in non-invasive hemoglobin estimation
A comparative analysis of optical character recognition models for extracting...
Big Data Technologies - Introduction.pptx
Electronic commerce courselecture one. Pdf
20250228 LYD VKU AI Blended-Learning.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Spectral efficient network and resource selection model in 5G networks
Machine learning based COVID-19 study performance prediction

Using containers for continuous integration and continuous delivery - Carlos Sanchez

  • 1. USING CONTAINERS FOR CONTINUOUS INTEGRATION AND CONTINUOUS DELIVERY Carlos Sanchez /csanchez.org @csanchez Watch online at carlossg.github.io/presentations
  • 2. ABOUT ME Engineer @ CloudBees, Scaling Jenkins Author of Jenkins Kubernetes plugin Contributor to Jenkins Mesos plugin & Jenkins and Maven official Docker images Long time OSS contributor at Apache Maven, Eclipse, Puppet,…
  • 5. USING CONTAINERS IS NOT TRIVIAL
  • 7. SCALING JENKINS Two options: More build agents per master More masters
  • 8. SCALING JENKINS: MORE BUILD AGENTS Pros Multiple plugins to add more agents, even dynamically Cons The master is still a SPOF Handling multiple configurations, plugin versions,... There is a limit on how many build agents can be attached
  • 9. SCALING JENKINS: MORE MASTERS Pros Different sub-organizations can self service and operate independently Cons Single Sign-On Centralized configuration and operation Covered by CloudBees Jenkins Enterprise
  • 14. JENKINS DOCKER PLUGINS Dynamic Jenkins agents with Docker plugin or Yet Another Docker Plugin No support yet for Docker Swarm mode Isolated build agents and jobs Agent image needs to include Java, downloads slave jar from Jenkins master
  • 15. JENKINS DOCKER PLUGINS Multiple plugins for different tasks Docker build and publish Docker build step plugin CloudBees Docker Hub/Registry Notification CloudBees Docker Traceability Great pipeline support
  • 18. JENKINS DOCKER PIPELINE def 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}", 'app') pcImg.push(); } }
  • 19. WHEN ONE MACHINE IS NO LONGER ENOUGH Running Docker across multiple hosts In public cloud, private cloud, VMs or bare metal HA and fault tolerant
  • 21. If you haven't automatically destroyed something by mistake, you are not automating enough
  • 24. KUBERNETES Based on Google Borg Run in local machine, virtual, cloud Google provides Google Container Engine (GKE) Other services run by stackpoint.io, CoreOS Tectonic, Azure,... Minikube for local testing
  • 25. GROUPING CONTAINERS (PODS) Example: Jenkins agent Maven build Selenium Hub with Firefox Chrome 5 containers
  • 26. STORAGE Jenkins masters need persistent storage, agents (maybe) Persistent volumes GCE disks GlusterFS NFS EBS etc
  • 27. PERMISSIONS Containers should not run as root Container user id != host user id i.e. jenkins user in container is always 1000 but matches ubuntu user in host
  • 28. PERMISSIONS containers: [...] securityContext: fsGroup: 1000 volumes: [...] Volumes which support ownership management are modified to be owned and writable by the GID specified in fsGroup
  • 29. NETWORKING Jenkins masters open several ports HTTP JNLP Build agent SSH server (Jenkins CLI type operations) Jenkins agents connect to master: inbound (SSH) outbound (JNLP)
  • 30. Multiple :networking options GCE, Flannel, Weave, Calico,... One IP per Pod Containers can find other containers in the same Pod using localhost
  • 31. MEMORY LIMITS Scheduler needs to account for container memory requirements and host available memory Prevent containers for using more memory than allowed Memory constraints translate to Docker --memory https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/#how- pods-with-resource-limits-are-run
  • 32. WHAT DO YOU THINK HAPPENS WHEN? Your container goes over memory quota?
  • 34. NEW JVM SUPPORT FOR CONTAINERS JDK 8u131+ and JDK 9 $ docker run -m 1GB openjdk:8u131 java -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XshowSettings:vm -version VM settings: Max. Heap Size (Estimated): 228.00M Ergonomics Machine Class: server Using VM: OpenJDK 64-Bit Server VM Running a JVM in a Container Without Getting Killed https://blog.csanchez.org/2017/05/31/running-a-jvm-in-a-container-without-getting-killed
  • 35. NEW JVM SUPPORT FOR CONTAINERS $ docker run -m 1GB openjdk:8u131 java -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:MaxRAMFraction=1 -XshowSettings:vm -version VM settings: Max. Heap Size (Estimated): 910.50M Ergonomics Machine Class: server Using VM: OpenJDK 64-Bit Server VM Running a JVM in a Container Without Getting Killed https://blog.csanchez.org/2017/05/31/running-a-jvm-in-a-container-without-getting-killed
  • 36. CPU LIMITS Scheduler needs to account for container CPU requirements and host available CPUs CPU requests translates into Docker --cpu-shares CPU limits translates into Docker --cpu-quota https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/#how- pods-with-resource-limits-are-run
  • 37. WHAT DO YOU THINK HAPPENS WHEN? Your container tries to access more than one CPU Your container goes over CPU limits
  • 39. JENKINS KUBERNETES PLUGIN Dynamic Jenkins agents, running as Pods Multiple container support One jnlp image, others custom Pipeline support for both agent Pod definition and execution Persistent workspace
  • 40. JENKINS KUBERNETES PIPELINE podTemplate(label: 'maven', containers: [ containerTemplate(name: 'maven', image: 'maven:3.3.9-jdk-8-alpine' ttyEnabled: true, command: 'cat') ]) { node('maven') { stage('Get a Maven project') { git 'https://github.com/jenkinsci/kubernetes-plugin.git' container('maven') { stage('Build a Maven project') { sh 'mvn -B clean package' } } } } }
  • 41. Multi-language Pipeline podTemplate(label: 'maven-golang', containers: [ containerTemplate(name: 'maven', image: 'maven:3.3.9-jdk-8-alpine', ttyEnabled: true, command: 'cat'), containerTemplate(name: 'golang', image: 'golang:1.8.0', ttyEnabled: true, command: 'cat')]) { node('maven-golang') { stage('Build a Maven project') { git 'https://github.com/jenkinsci/kubernetes-plugin.git' container('maven') { sh 'mvn -B clean package' } } stage('Build a Golang project') { git url: 'https://github.com/hashicorp/terraform.git' container('golang') { 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 """ } } }
  • 42. JENKINS PLUGINS CAVEATS Using the Cloud API Not ideal for containerized workload Agents take > 1 min to start provision and are kept around Agents can provide more than one executor
  • 43. JENKINS PLUGINS CAVEATS One Shot Executor Improved API to handle one off agents Optimized for containerized agents Plugins need to support it