SlideShare a Scribd company logo
Continuous Deployment
with Kubernetes, Docker
and GitLab CI
@alexander_kiel

Clojure Berlin 2016
Continuous Deployment with Kubernetes, Docker and GitLab CI
Outline
• Continuous Deployment why?
• Docker
• Kubernetes
• Sample Clojure Service
• Deploy with GitLabCI
Continuous Deployment
• What do we want?
• Increase responsiveness
• Decrease time to market
• Gain confidence by deploying often in small amounts
• How to achieve that?
• Automate everything
• Always deploy the master into production
• Use feature toggles when needed
Simple Git Workflow
• Works for in-house apps
• not for libs or shipping apps
• No versions, no tags, just SHA’s
• Latest commit on master is always
deployed to production
• Feature/fix branches are merged
when ready
master
feature/fix
branches
1ebb95d
be61dda
6e4010d
Docker
• Like VM’s but much more light-weight and shippable
• Runs on Linux, executes processes in an isolated environment
(resource limitation, filesystem, network)
• Container principle: Can contain everything, but looks the
same from the outside
• A container platform can run every container
• Developers have max. freedom what to do
• In contrast: PaaS like Heroku - has to support the language
Kubernetes
• Container runtime platform
• Originally designed by Google - now Open Source
• One of the most active projects on GitHub - 20,000
stars, 40,000 commits, 15,000 issues, 200 releases
• Alternatives: Apache Mesos, Docker Swarm (lacks
features)
Kubernetes Architecture
k8s-master-1
k8s-master-2
k8s-master-3
load-balancer-1
load-balancer-2
DNS RR
k8s-worker-1
proxy
app-1
k8s-worker-2
proxy
app-2
k8s-worker-n
proxy
app-k
etcd cluster

quorum
HAProxy
• Runs on VMware ESX
• CoreOS Linux
• Single YAML file as configuration
• Everything in containers
Kubernetes - Pods
• A Pod is a deployable unit in
Kubernetes
• Pods can contain multiple
containers
• Containers inside a Pod share
on port space, can use
localhost and can
communicate via IPC and
shared memory
• Idea: one process per
container - many cooperating
processes in one Pod
apiVersion: v1

kind: Pod

metadata:

name: <pod-name>

labels:

<key>: <value>

spec:

containers:

- name: <container-name>

image: <container-image>

ports:

- containerPort: 80

env:

- name: <key>

value: <value>
Kubernetes - Deployments
• A Deployment ensures that
certain number of Pods are
always running
• It consists of a Pod template
and the number of replicas
• It supports hot-redeployments
by changing parts of the Pod
template
• Horizontal scaling is possible
apiVersion: extensions/v1beta1

kind: Deployment

metadata:

name: <deployment-name>

spec:

replicas: 2

template:

metadata:
labels:
<key>: <value>
spec:
containers:
- name: <container-name>
image: <container-image>
ports:
- containerPort: 80
env:
- name: <key>
value: <value>
Kubernetes - Services
• Kubernetes uses an overlay
network to provide different address
spaces (we use flannel)
• Every Pod has an IP address - but it
changes every time one is created
• Services provide a stable IP
address for groups of Pods
• Service names are resolvable by an
internal DNS
• Service selectors are used to match
Pods according to there labels
apiVersion: v1
kind: Service
metadata:
name: clojure-berlin-2016
labels:
app: lens
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
protocol: TCP
selector:
service: clojure-
berlin-2016
Kubernetes - External Access
• Kubernetes networks are internal
only
• External access through load
balancers necessary
• Certain Platforms like Google
Compute Engine provide load
balancer integration with Kubernetes
• We have our own solution as a
combination of HAProxy and
Kubernetes NodePort
• Kubernetes Services with type
NodePort are exposed on every
worker under a certain port
frontend http
bind 0.0.0.0:80
mode http
option httplog
acl host_clj hdr(host)
clj.<domain>
use_backend clj if host_clj
backend clj
mode http
balance roundrobin
option httplog
server worker-1 <ip>:32599 check
server worker-2 <ip>:32599 check
Deployment Lifecycle
GitLab CI
Source Code
build
test
Kubernetes
Test
Cluster
Kubernetes
Prod
Cluster
automatic deployment
manual
deployment
git
push
Sample Clojure Service
• .gitlab-ci.yml
• Like .travis.yml contains instructions for GitLabCI
how to test, build and deploy
• Dockerfile
• Instructions for Docker how to build the image of
the app
• Artifact of the build is a docker image - not
uberjar
• kube-deployment.yml
• Kubernetes deployment instructions
• kube-svc.yml
• Kubernetes service description
https://github.com/alexanderkiel/clojure-berlin-2016
The Core Namespace
(ns clojure-berlin-2016.core
(:require [aleph.http :as http]
[clojure.core.async :refer [<!! chan]]))
(defn -main [& args]
(-> (fn [_]
{:status 200
:body "Clojure Berlin 2016"})
(http/start-server {:port 8080}))
(<!! (chan)))
• A simple web server returning "Clojure Berlin 2016"
The Leiningen Project File
(defproject clojure-berlin-2016 "<VERSION>"
:dependencies [[aleph "0.4.1"]
[org.clojure/clojure "1.8.0"]
[org.clojure/core.async "0.2.395"]]
:main clojure-berlin-2016.core)
• <VERSION> is replaced at build time by the Git SHA
• :main is for lein run to work
.gitlab-ci.yml - test/build
image: clojure:lein-2.7.1
stages:
- test
- build
- deploy
test:
stage: test
tags:
- docker
script:
- lein test
build:
stage: build
tags:
- docker
script:
- sed -i "s/<VERSION>/$CI_BUILD_REF/" project.clj
- docker build -t clojure-berlin-2016:$CI_BUILD_REF .
- docker push clojure-berlin-2016:$CI_BUILD_REF
.gitlab-ci.yml - deploy branch
deploy-branch:
stage: deploy
environment: test
image: dreg.life.uni-leipzig.local/kubectl:0.4
tags:
- docker
script:
- sed -i "s/<VERSION>/$CI_BUILD_REF/" kube-deployment.yml
- kubectl config use-context gitlab-ci-test
- kubectl apply -f kube-deployment.yml
except:
- master
when: manual
• Used to test a feature/fix branch in a full environment
.gitlab-ci.yml - deploy test
deploy-master:
stage: deploy
environment: test
image: dreg.life.uni-leipzig.local/kubectl:0.4
tags:
- docker
script:
- sed -i "s/<VERSION>/$CI_BUILD_REF/" kube-deployment.yml
- kubectl config use-context gitlab-ci-test
- kubectl apply -f kube-deployment.yml
only:
- master
.gitlab-ci.yml - deploy prod
deploy-prod:
stage: deploy
environment: prod
image: dreg.life.uni-leipzig.local/kubectl:0.4
tags:
- docker
script:
- sed -i "s/<VERSION>/$CI_BUILD_REF/" kube-deployment.yml
- kubectl config use-context gitlab-ci-prod-a
- kubectl apply -f kube-deployment.yml
only:
- master
when: manual
Docker file
FROM clojure:lein-2.7.1
COPY src /app/src
COPY project.clj /app/
WORKDIR /app
RUN lein with-profile production deps
EXPOSE 80
CMD ["lein", "with-profile", "production", "run"]
• Just copy the sources into the container
• Use Leiningen itself to run in production
kube-deployment.yml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: clojure-berlin-2016
spec:
replicas: 2
template:
metadata:
labels:
app: lens
service: clojure-berlin-2016
spec:
containers:
- name: clojure-berlin-2016
image: dreg.life.uni-leipzig.local/clojure-berlin-2016:<VERSION>
ports:
- containerPort: 8080
resources:
requests:
cpu: "125m"
memory: "1Gi"
limits:
cpu: 1
memory: "2Gi"
kube-svc.yml
apiVersion: v1
kind: Service
metadata:
name: clojure-berlin-2016
labels:
app: lens
spec:
type: NodePort
ports:
- port: 80
targetPort: 8080
protocol: TCP
selector:
service: clojure-berlin-2016
Steps to Follow
• Create the Kubernetes Service
• kubectl create -f kube-svc.yml
• Edit HAProxy Config
• add rules and backend for the service
• Push to GitLab
• git push
Pipeline in GitLab CI
Deployment in GitLabCI
Environments in GitLabCI
• Very good visibility of wich commit is deployed in
which environment right now
• Manual deployment to prod possible
Environment History
• Easy to see when what commit was deployed
• Rollback possible
Numbers
• Our team has 4 developers
• We run 2 Kubernetes clusters (test and prod) with
about 96 GB RAM and and 24 vCPU’s each
• We run about 60 pods in production
• We have other services like central log aggregation
running using Fluentd and Elasticsearch/Kibana
Thank You
• Sample Project on Github

https://github.com/alexanderkiel/clojure-berlin-2016
• Twitter

@alexander_kiel
• Mail

alexanderkiel@gmx.net
Ad

Recommended

CI/CD Pipeline mit Gitlab CI und Kubernetes
CI/CD Pipeline mit Gitlab CI und Kubernetes
inovex GmbH
 
Gitlab ci e kubernetes, build test and deploy your projects like a pro
Gitlab ci e kubernetes, build test and deploy your projects like a pro
sparkfabrik
 
Gitlab ci, cncf.sk
Gitlab ci, cncf.sk
Juraj Hantak
 
FOSDEM 2017: GitLab CI
FOSDEM 2017: GitLab CI
OlinData
 
Gitlab ci-cd
Gitlab ci-cd
Dan MAGIER
 
OPENSHIFT CONTAINER PLATFORM CI/CD Build & Deploy
OPENSHIFT CONTAINER PLATFORM CI/CD Build & Deploy
Natale Vinto
 
Jenkins vs GitLab CI
Jenkins vs GitLab CI
CEE-SEC(R)
 
CI/CD with Openshift and Jenkins
CI/CD with Openshift and Jenkins
Ari LiVigni
 
Why you can't ignore GitLab
Why you can't ignore GitLab
Pivorak MeetUp
 
Workflows using Git GitHub | Edureka
Workflows using Git GitHub | Edureka
Edureka!
 
Breaking Bad Habits with GitLab CI
Breaking Bad Habits with GitLab CI
Ivan Nemytchenko
 
4K–Kubernetes with Knative, Kafka and Kamel
4K–Kubernetes with Knative, Kafka and Kamel
Red Hat Developers
 
GitLab - Java User Group
GitLab - Java User Group
PhilippWestphalen
 
Docker based-Pipelines with Codefresh
Docker based-Pipelines with Codefresh
Codefresh
 
Containerd + buildkit breakout
Containerd + buildkit breakout
Docker, Inc.
 
GitLab for CI/CD process
GitLab for CI/CD process
HYS Enterprise
 
CI with Gitlab & Docker
CI with Gitlab & Docker
Joerg Henning
 
Quarkus: From developer joy to Kubernetes nirvana! | DevNation Tech Talk
Quarkus: From developer joy to Kubernetes nirvana! | DevNation Tech Talk
Red Hat Developers
 
Breaking bad habits with GitLab CI
Breaking bad habits with GitLab CI
Ivan Nemytchenko
 
Cloud Native CI/CD with Jenkins X and Knative Pipelines
Cloud Native CI/CD with Jenkins X and Knative Pipelines
C4Media
 
Webinar - Unbox GitLab CI/CD
Webinar - Unbox GitLab CI/CD
Annie Huang
 
The path to a serverless-native era with Kubernetes
The path to a serverless-native era with Kubernetes
sparkfabrik
 
Docker Best Practices Workshop
Docker Best Practices Workshop
Ahmed AbouZaid
 
Introduction to Kubernetes - Docker Global Mentor Week 2016
Introduction to Kubernetes - Docker Global Mentor Week 2016
Opsta
 
Puzzle ITC Talk @Docker CH meetup CI CD_with_Openshift_0.2
Puzzle ITC Talk @Docker CH meetup CI CD_with_Openshift_0.2
Amrita Prasad
 
Setting up CI/CD pipeline with Kubernetes and Kublr step-by-step
Setting up CI/CD pipeline with Kubernetes and Kublr step-by-step
Oleg Chunikhin
 
VM vs Docker-Based Pipelines
VM vs Docker-Based Pipelines
Codefresh
 
Automate CI/CD with Rancher
Automate CI/CD with Rancher
Nick Thomas
 
Setting up CI/CD Pipeline with Kubernetes and Kublr step by-step
Setting up CI/CD Pipeline with Kubernetes and Kublr step by-step
Kublr
 
HOW TO DRONE.IO IN CI/CD WORLD
HOW TO DRONE.IO IN CI/CD WORLD
Aleksandr Maklakov
 

More Related Content

What's hot (20)

Why you can't ignore GitLab
Why you can't ignore GitLab
Pivorak MeetUp
 
Workflows using Git GitHub | Edureka
Workflows using Git GitHub | Edureka
Edureka!
 
Breaking Bad Habits with GitLab CI
Breaking Bad Habits with GitLab CI
Ivan Nemytchenko
 
4K–Kubernetes with Knative, Kafka and Kamel
4K–Kubernetes with Knative, Kafka and Kamel
Red Hat Developers
 
GitLab - Java User Group
GitLab - Java User Group
PhilippWestphalen
 
Docker based-Pipelines with Codefresh
Docker based-Pipelines with Codefresh
Codefresh
 
Containerd + buildkit breakout
Containerd + buildkit breakout
Docker, Inc.
 
GitLab for CI/CD process
GitLab for CI/CD process
HYS Enterprise
 
CI with Gitlab & Docker
CI with Gitlab & Docker
Joerg Henning
 
Quarkus: From developer joy to Kubernetes nirvana! | DevNation Tech Talk
Quarkus: From developer joy to Kubernetes nirvana! | DevNation Tech Talk
Red Hat Developers
 
Breaking bad habits with GitLab CI
Breaking bad habits with GitLab CI
Ivan Nemytchenko
 
Cloud Native CI/CD with Jenkins X and Knative Pipelines
Cloud Native CI/CD with Jenkins X and Knative Pipelines
C4Media
 
Webinar - Unbox GitLab CI/CD
Webinar - Unbox GitLab CI/CD
Annie Huang
 
The path to a serverless-native era with Kubernetes
The path to a serverless-native era with Kubernetes
sparkfabrik
 
Docker Best Practices Workshop
Docker Best Practices Workshop
Ahmed AbouZaid
 
Introduction to Kubernetes - Docker Global Mentor Week 2016
Introduction to Kubernetes - Docker Global Mentor Week 2016
Opsta
 
Puzzle ITC Talk @Docker CH meetup CI CD_with_Openshift_0.2
Puzzle ITC Talk @Docker CH meetup CI CD_with_Openshift_0.2
Amrita Prasad
 
Setting up CI/CD pipeline with Kubernetes and Kublr step-by-step
Setting up CI/CD pipeline with Kubernetes and Kublr step-by-step
Oleg Chunikhin
 
VM vs Docker-Based Pipelines
VM vs Docker-Based Pipelines
Codefresh
 
Automate CI/CD with Rancher
Automate CI/CD with Rancher
Nick Thomas
 
Why you can't ignore GitLab
Why you can't ignore GitLab
Pivorak MeetUp
 
Workflows using Git GitHub | Edureka
Workflows using Git GitHub | Edureka
Edureka!
 
Breaking Bad Habits with GitLab CI
Breaking Bad Habits with GitLab CI
Ivan Nemytchenko
 
4K–Kubernetes with Knative, Kafka and Kamel
4K–Kubernetes with Knative, Kafka and Kamel
Red Hat Developers
 
Docker based-Pipelines with Codefresh
Docker based-Pipelines with Codefresh
Codefresh
 
Containerd + buildkit breakout
Containerd + buildkit breakout
Docker, Inc.
 
GitLab for CI/CD process
GitLab for CI/CD process
HYS Enterprise
 
CI with Gitlab & Docker
CI with Gitlab & Docker
Joerg Henning
 
Quarkus: From developer joy to Kubernetes nirvana! | DevNation Tech Talk
Quarkus: From developer joy to Kubernetes nirvana! | DevNation Tech Talk
Red Hat Developers
 
Breaking bad habits with GitLab CI
Breaking bad habits with GitLab CI
Ivan Nemytchenko
 
Cloud Native CI/CD with Jenkins X and Knative Pipelines
Cloud Native CI/CD with Jenkins X and Knative Pipelines
C4Media
 
Webinar - Unbox GitLab CI/CD
Webinar - Unbox GitLab CI/CD
Annie Huang
 
The path to a serverless-native era with Kubernetes
The path to a serverless-native era with Kubernetes
sparkfabrik
 
Docker Best Practices Workshop
Docker Best Practices Workshop
Ahmed AbouZaid
 
Introduction to Kubernetes - Docker Global Mentor Week 2016
Introduction to Kubernetes - Docker Global Mentor Week 2016
Opsta
 
Puzzle ITC Talk @Docker CH meetup CI CD_with_Openshift_0.2
Puzzle ITC Talk @Docker CH meetup CI CD_with_Openshift_0.2
Amrita Prasad
 
Setting up CI/CD pipeline with Kubernetes and Kublr step-by-step
Setting up CI/CD pipeline with Kubernetes and Kublr step-by-step
Oleg Chunikhin
 
VM vs Docker-Based Pipelines
VM vs Docker-Based Pipelines
Codefresh
 
Automate CI/CD with Rancher
Automate CI/CD with Rancher
Nick Thomas
 

Similar to Continuous Deployment with Kubernetes, Docker and GitLab CI (20)

Setting up CI/CD Pipeline with Kubernetes and Kublr step by-step
Setting up CI/CD Pipeline with Kubernetes and Kublr step by-step
Kublr
 
HOW TO DRONE.IO IN CI/CD WORLD
HOW TO DRONE.IO IN CI/CD WORLD
Aleksandr Maklakov
 
Get you Java application ready for Kubernetes !
Get you Java application ready for Kubernetes !
Anthony Dahanne
 
Getting started with kubernetes
Getting started with kubernetes
Bob Killen
 
Adf with docker
Adf with docker
Eugene Fedorenko
 
01 - VMUGIT - Lecce 2018 - Fabio Rapposelli, VMware
01 - VMUGIT - Lecce 2018 - Fabio Rapposelli, VMware
VMUG IT
 
K8s in 3h - Kubernetes Fundamentals Training
K8s in 3h - Kubernetes Fundamentals Training
Piotr Perzyna
 
Docker and Puppet for Continuous Integration
Docker and Puppet for Continuous Integration
Giacomo Vacca
 
Containers, Serverless and Functions in a nutshell
Containers, Serverless and Functions in a nutshell
Eugene Fedorenko
 
DCEU 18: Building Your Development Pipeline
DCEU 18: Building Your Development Pipeline
Docker, Inc.
 
KubeCI - Cloud Native Continuous Delivery for Kubernetes
KubeCI - Cloud Native Continuous Delivery for Kubernetes
Tobias Schneck
 
CKA_1st.pptx
CKA_1st.pptx
YIJHEHUANG
 
Docker kubernetes fundamental(pod_service)_190307
Docker kubernetes fundamental(pod_service)_190307
Inhye Park
 
Microservices with containers in the cloud
Microservices with containers in the cloud
Eugene Fedorenko
 
An intro to Kubernetes operators
An intro to Kubernetes operators
J On The Beach
 
Knative build for open whisk runtimes phase 1 - 2018-02-20
Knative build for open whisk runtimes phase 1 - 2018-02-20
Matt Rutkowski
 
Introduction to Kubernetes Workshop
Introduction to Kubernetes Workshop
Bob Killen
 
Continuous Delivery the Hard Way with Kubernetes
Continuous Delivery the Hard Way with Kubernetes
Weaveworks
 
Detailed Introduction To Docker
Detailed Introduction To Docker
nklmish
 
Build optimization mechanisms in GitLab and Docker
Build optimization mechanisms in GitLab and Docker
Dmytro Patkovskyi
 
Setting up CI/CD Pipeline with Kubernetes and Kublr step by-step
Setting up CI/CD Pipeline with Kubernetes and Kublr step by-step
Kublr
 
HOW TO DRONE.IO IN CI/CD WORLD
HOW TO DRONE.IO IN CI/CD WORLD
Aleksandr Maklakov
 
Get you Java application ready for Kubernetes !
Get you Java application ready for Kubernetes !
Anthony Dahanne
 
Getting started with kubernetes
Getting started with kubernetes
Bob Killen
 
01 - VMUGIT - Lecce 2018 - Fabio Rapposelli, VMware
01 - VMUGIT - Lecce 2018 - Fabio Rapposelli, VMware
VMUG IT
 
K8s in 3h - Kubernetes Fundamentals Training
K8s in 3h - Kubernetes Fundamentals Training
Piotr Perzyna
 
Docker and Puppet for Continuous Integration
Docker and Puppet for Continuous Integration
Giacomo Vacca
 
Containers, Serverless and Functions in a nutshell
Containers, Serverless and Functions in a nutshell
Eugene Fedorenko
 
DCEU 18: Building Your Development Pipeline
DCEU 18: Building Your Development Pipeline
Docker, Inc.
 
KubeCI - Cloud Native Continuous Delivery for Kubernetes
KubeCI - Cloud Native Continuous Delivery for Kubernetes
Tobias Schneck
 
Docker kubernetes fundamental(pod_service)_190307
Docker kubernetes fundamental(pod_service)_190307
Inhye Park
 
Microservices with containers in the cloud
Microservices with containers in the cloud
Eugene Fedorenko
 
An intro to Kubernetes operators
An intro to Kubernetes operators
J On The Beach
 
Knative build for open whisk runtimes phase 1 - 2018-02-20
Knative build for open whisk runtimes phase 1 - 2018-02-20
Matt Rutkowski
 
Introduction to Kubernetes Workshop
Introduction to Kubernetes Workshop
Bob Killen
 
Continuous Delivery the Hard Way with Kubernetes
Continuous Delivery the Hard Way with Kubernetes
Weaveworks
 
Detailed Introduction To Docker
Detailed Introduction To Docker
nklmish
 
Build optimization mechanisms in GitLab and Docker
Build optimization mechanisms in GitLab and Docker
Dmytro Patkovskyi
 
Ad

Recently uploaded (20)

Best Practice for LLM Serving in the Cloud
Best Practice for LLM Serving in the Cloud
Alluxio, Inc.
 
University Campus Navigation for All - Peak of Data & AI
University Campus Navigation for All - Peak of Data & AI
Safe Software
 
Test Case Design Techniques – Practical Examples & Best Practices in Software...
Test Case Design Techniques – Practical Examples & Best Practices in Software...
Muhammad Fahad Bashir
 
Y - Recursion The Hard Way GopherCon EU 2025
Y - Recursion The Hard Way GopherCon EU 2025
Eleanor McHugh
 
Foundations of Marketo Engage - Programs, Campaigns & Beyond - June 2025
Foundations of Marketo Engage - Programs, Campaigns & Beyond - June 2025
BradBedford3
 
OpenChain Webinar - AboutCode - Practical Compliance in One Stack – Licensing...
OpenChain Webinar - AboutCode - Practical Compliance in One Stack – Licensing...
Shane Coughlan
 
Key Challenges in Troubleshooting Customer On-Premise Applications
Key Challenges in Troubleshooting Customer On-Premise Applications
Tier1 app
 
Canva Pro Crack Free Download 2025-FREE LATEST
Canva Pro Crack Free Download 2025-FREE LATEST
grete1122g
 
HYBRIDIZATION OF ALKANES AND ALKENES ...
HYBRIDIZATION OF ALKANES AND ALKENES ...
karishmaduhijod1
 
Why Every Growing Business Needs a Staff Augmentation Company IN USA.pdf
Why Every Growing Business Needs a Staff Augmentation Company IN USA.pdf
mary rojas
 
How Automation in Claims Handling Streamlined Operations
How Automation in Claims Handling Streamlined Operations
Insurance Tech Services
 
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
IDM Crack with Internet Download Manager 6.42 Build 41 [Latest 2025]
IDM Crack with Internet Download Manager 6.42 Build 41 [Latest 2025]
pcprocore
 
Sysinfo OST to PST Converter Infographic
Sysinfo OST to PST Converter Infographic
SysInfo Tools
 
Microsoft-365-Administrator-s-Guide1.pdf
Microsoft-365-Administrator-s-Guide1.pdf
mazharatknl
 
arctitecture application system design os dsa
arctitecture application system design os dsa
za241967
 
IObit Driver Booster Pro 12 Crack Latest Version Download
IObit Driver Booster Pro 12 Crack Latest Version Download
pcprocore
 
Threat Modeling a Batch Job Framework - Teri Radichel - AWS re:Inforce 2025
Threat Modeling a Batch Job Framework - Teri Radichel - AWS re:Inforce 2025
2nd Sight Lab
 
Advance Doctor Appointment Booking App With Online Payment
Advance Doctor Appointment Booking App With Online Payment
AxisTechnolabs
 
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
Best Practice for LLM Serving in the Cloud
Best Practice for LLM Serving in the Cloud
Alluxio, Inc.
 
University Campus Navigation for All - Peak of Data & AI
University Campus Navigation for All - Peak of Data & AI
Safe Software
 
Test Case Design Techniques – Practical Examples & Best Practices in Software...
Test Case Design Techniques – Practical Examples & Best Practices in Software...
Muhammad Fahad Bashir
 
Y - Recursion The Hard Way GopherCon EU 2025
Y - Recursion The Hard Way GopherCon EU 2025
Eleanor McHugh
 
Foundations of Marketo Engage - Programs, Campaigns & Beyond - June 2025
Foundations of Marketo Engage - Programs, Campaigns & Beyond - June 2025
BradBedford3
 
OpenChain Webinar - AboutCode - Practical Compliance in One Stack – Licensing...
OpenChain Webinar - AboutCode - Practical Compliance in One Stack – Licensing...
Shane Coughlan
 
Key Challenges in Troubleshooting Customer On-Premise Applications
Key Challenges in Troubleshooting Customer On-Premise Applications
Tier1 app
 
Canva Pro Crack Free Download 2025-FREE LATEST
Canva Pro Crack Free Download 2025-FREE LATEST
grete1122g
 
HYBRIDIZATION OF ALKANES AND ALKENES ...
HYBRIDIZATION OF ALKANES AND ALKENES ...
karishmaduhijod1
 
Why Every Growing Business Needs a Staff Augmentation Company IN USA.pdf
Why Every Growing Business Needs a Staff Augmentation Company IN USA.pdf
mary rojas
 
How Automation in Claims Handling Streamlined Operations
How Automation in Claims Handling Streamlined Operations
Insurance Tech Services
 
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
IDM Crack with Internet Download Manager 6.42 Build 41 [Latest 2025]
IDM Crack with Internet Download Manager 6.42 Build 41 [Latest 2025]
pcprocore
 
Sysinfo OST to PST Converter Infographic
Sysinfo OST to PST Converter Infographic
SysInfo Tools
 
Microsoft-365-Administrator-s-Guide1.pdf
Microsoft-365-Administrator-s-Guide1.pdf
mazharatknl
 
arctitecture application system design os dsa
arctitecture application system design os dsa
za241967
 
IObit Driver Booster Pro 12 Crack Latest Version Download
IObit Driver Booster Pro 12 Crack Latest Version Download
pcprocore
 
Threat Modeling a Batch Job Framework - Teri Radichel - AWS re:Inforce 2025
Threat Modeling a Batch Job Framework - Teri Radichel - AWS re:Inforce 2025
2nd Sight Lab
 
Advance Doctor Appointment Booking App With Online Payment
Advance Doctor Appointment Booking App With Online Payment
AxisTechnolabs
 
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
Ad

Continuous Deployment with Kubernetes, Docker and GitLab CI

  • 1. Continuous Deployment with Kubernetes, Docker and GitLab CI @alexander_kiel
 Clojure Berlin 2016
  • 3. Outline • Continuous Deployment why? • Docker • Kubernetes • Sample Clojure Service • Deploy with GitLabCI
  • 4. Continuous Deployment • What do we want? • Increase responsiveness • Decrease time to market • Gain confidence by deploying often in small amounts • How to achieve that? • Automate everything • Always deploy the master into production • Use feature toggles when needed
  • 5. Simple Git Workflow • Works for in-house apps • not for libs or shipping apps • No versions, no tags, just SHA’s • Latest commit on master is always deployed to production • Feature/fix branches are merged when ready master feature/fix branches 1ebb95d be61dda 6e4010d
  • 6. Docker • Like VM’s but much more light-weight and shippable • Runs on Linux, executes processes in an isolated environment (resource limitation, filesystem, network) • Container principle: Can contain everything, but looks the same from the outside • A container platform can run every container • Developers have max. freedom what to do • In contrast: PaaS like Heroku - has to support the language
  • 7. Kubernetes • Container runtime platform • Originally designed by Google - now Open Source • One of the most active projects on GitHub - 20,000 stars, 40,000 commits, 15,000 issues, 200 releases • Alternatives: Apache Mesos, Docker Swarm (lacks features)
  • 8. Kubernetes Architecture k8s-master-1 k8s-master-2 k8s-master-3 load-balancer-1 load-balancer-2 DNS RR k8s-worker-1 proxy app-1 k8s-worker-2 proxy app-2 k8s-worker-n proxy app-k etcd cluster
 quorum HAProxy • Runs on VMware ESX • CoreOS Linux • Single YAML file as configuration • Everything in containers
  • 9. Kubernetes - Pods • A Pod is a deployable unit in Kubernetes • Pods can contain multiple containers • Containers inside a Pod share on port space, can use localhost and can communicate via IPC and shared memory • Idea: one process per container - many cooperating processes in one Pod apiVersion: v1
 kind: Pod
 metadata:
 name: <pod-name>
 labels:
 <key>: <value>
 spec:
 containers:
 - name: <container-name>
 image: <container-image>
 ports:
 - containerPort: 80
 env:
 - name: <key>
 value: <value>
  • 10. Kubernetes - Deployments • A Deployment ensures that certain number of Pods are always running • It consists of a Pod template and the number of replicas • It supports hot-redeployments by changing parts of the Pod template • Horizontal scaling is possible apiVersion: extensions/v1beta1
 kind: Deployment
 metadata:
 name: <deployment-name>
 spec:
 replicas: 2
 template:
 metadata: labels: <key>: <value> spec: containers: - name: <container-name> image: <container-image> ports: - containerPort: 80 env: - name: <key> value: <value>
  • 11. Kubernetes - Services • Kubernetes uses an overlay network to provide different address spaces (we use flannel) • Every Pod has an IP address - but it changes every time one is created • Services provide a stable IP address for groups of Pods • Service names are resolvable by an internal DNS • Service selectors are used to match Pods according to there labels apiVersion: v1 kind: Service metadata: name: clojure-berlin-2016 labels: app: lens spec: type: NodePort ports: - port: 80 targetPort: 80 protocol: TCP selector: service: clojure- berlin-2016
  • 12. Kubernetes - External Access • Kubernetes networks are internal only • External access through load balancers necessary • Certain Platforms like Google Compute Engine provide load balancer integration with Kubernetes • We have our own solution as a combination of HAProxy and Kubernetes NodePort • Kubernetes Services with type NodePort are exposed on every worker under a certain port frontend http bind 0.0.0.0:80 mode http option httplog acl host_clj hdr(host) clj.<domain> use_backend clj if host_clj backend clj mode http balance roundrobin option httplog server worker-1 <ip>:32599 check server worker-2 <ip>:32599 check
  • 13. Deployment Lifecycle GitLab CI Source Code build test Kubernetes Test Cluster Kubernetes Prod Cluster automatic deployment manual deployment git push
  • 14. Sample Clojure Service • .gitlab-ci.yml • Like .travis.yml contains instructions for GitLabCI how to test, build and deploy • Dockerfile • Instructions for Docker how to build the image of the app • Artifact of the build is a docker image - not uberjar • kube-deployment.yml • Kubernetes deployment instructions • kube-svc.yml • Kubernetes service description https://github.com/alexanderkiel/clojure-berlin-2016
  • 15. The Core Namespace (ns clojure-berlin-2016.core (:require [aleph.http :as http] [clojure.core.async :refer [<!! chan]])) (defn -main [& args] (-> (fn [_] {:status 200 :body "Clojure Berlin 2016"}) (http/start-server {:port 8080})) (<!! (chan))) • A simple web server returning "Clojure Berlin 2016"
  • 16. The Leiningen Project File (defproject clojure-berlin-2016 "<VERSION>" :dependencies [[aleph "0.4.1"] [org.clojure/clojure "1.8.0"] [org.clojure/core.async "0.2.395"]] :main clojure-berlin-2016.core) • <VERSION> is replaced at build time by the Git SHA • :main is for lein run to work
  • 17. .gitlab-ci.yml - test/build image: clojure:lein-2.7.1 stages: - test - build - deploy test: stage: test tags: - docker script: - lein test build: stage: build tags: - docker script: - sed -i "s/<VERSION>/$CI_BUILD_REF/" project.clj - docker build -t clojure-berlin-2016:$CI_BUILD_REF . - docker push clojure-berlin-2016:$CI_BUILD_REF
  • 18. .gitlab-ci.yml - deploy branch deploy-branch: stage: deploy environment: test image: dreg.life.uni-leipzig.local/kubectl:0.4 tags: - docker script: - sed -i "s/<VERSION>/$CI_BUILD_REF/" kube-deployment.yml - kubectl config use-context gitlab-ci-test - kubectl apply -f kube-deployment.yml except: - master when: manual • Used to test a feature/fix branch in a full environment
  • 19. .gitlab-ci.yml - deploy test deploy-master: stage: deploy environment: test image: dreg.life.uni-leipzig.local/kubectl:0.4 tags: - docker script: - sed -i "s/<VERSION>/$CI_BUILD_REF/" kube-deployment.yml - kubectl config use-context gitlab-ci-test - kubectl apply -f kube-deployment.yml only: - master
  • 20. .gitlab-ci.yml - deploy prod deploy-prod: stage: deploy environment: prod image: dreg.life.uni-leipzig.local/kubectl:0.4 tags: - docker script: - sed -i "s/<VERSION>/$CI_BUILD_REF/" kube-deployment.yml - kubectl config use-context gitlab-ci-prod-a - kubectl apply -f kube-deployment.yml only: - master when: manual
  • 21. Docker file FROM clojure:lein-2.7.1 COPY src /app/src COPY project.clj /app/ WORKDIR /app RUN lein with-profile production deps EXPOSE 80 CMD ["lein", "with-profile", "production", "run"] • Just copy the sources into the container • Use Leiningen itself to run in production
  • 22. kube-deployment.yml apiVersion: extensions/v1beta1 kind: Deployment metadata: name: clojure-berlin-2016 spec: replicas: 2 template: metadata: labels: app: lens service: clojure-berlin-2016 spec: containers: - name: clojure-berlin-2016 image: dreg.life.uni-leipzig.local/clojure-berlin-2016:<VERSION> ports: - containerPort: 8080 resources: requests: cpu: "125m" memory: "1Gi" limits: cpu: 1 memory: "2Gi"
  • 23. kube-svc.yml apiVersion: v1 kind: Service metadata: name: clojure-berlin-2016 labels: app: lens spec: type: NodePort ports: - port: 80 targetPort: 8080 protocol: TCP selector: service: clojure-berlin-2016
  • 24. Steps to Follow • Create the Kubernetes Service • kubectl create -f kube-svc.yml • Edit HAProxy Config • add rules and backend for the service • Push to GitLab • git push
  • 27. Environments in GitLabCI • Very good visibility of wich commit is deployed in which environment right now • Manual deployment to prod possible
  • 28. Environment History • Easy to see when what commit was deployed • Rollback possible
  • 29. Numbers • Our team has 4 developers • We run 2 Kubernetes clusters (test and prod) with about 96 GB RAM and and 24 vCPU’s each • We run about 60 pods in production • We have other services like central log aggregation running using Fluentd and Elasticsearch/Kibana
  • 30. Thank You • Sample Project on Github
 https://github.com/alexanderkiel/clojure-berlin-2016 • Twitter
 @alexander_kiel • Mail
 [email protected]