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

Clojure Berlin 2016
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

More Related Content

What's hot

Why you can't ignore GitLab
Why you can't ignore GitLabWhy you can't ignore GitLab
Why you can't ignore GitLab
Pivorak MeetUp
 
Workflows using Git GitHub | Edureka
Workflows using Git GitHub | EdurekaWorkflows using Git GitHub | Edureka
Workflows using Git GitHub | Edureka
Edureka!
 
Breaking Bad Habits with GitLab CI
Breaking Bad Habits with GitLab CIBreaking 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 4K–Kubernetes with Knative, Kafka and Kamel
4K–Kubernetes with Knative, Kafka and Kamel
Red Hat Developers
 
GitLab - Java User Group
GitLab - Java User GroupGitLab - Java User Group
GitLab - Java User Group
PhilippWestphalen
 
Docker based-Pipelines with Codefresh
Docker based-Pipelines with CodefreshDocker based-Pipelines with Codefresh
Docker based-Pipelines with Codefresh
Codefresh
 
Containerd + buildkit breakout
Containerd + buildkit breakoutContainerd + buildkit breakout
Containerd + buildkit breakout
Docker, Inc.
 
GitLab for CI/CD process
GitLab for CI/CD processGitLab for CI/CD process
GitLab for CI/CD process
HYS Enterprise
 
CI with Gitlab & Docker
CI with Gitlab & DockerCI 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 TalkQuarkus: 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 CIBreaking 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 PipelinesCloud 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 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 KubernetesThe 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 WorkshopDocker Best Practices Workshop
Docker Best Practices Workshop
Ahmed AbouZaid
 
Introduction to Kubernetes - Docker Global Mentor Week 2016
Introduction to Kubernetes - Docker Global Mentor Week 2016Introduction 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.2Puzzle 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-stepSetting 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 PipelinesVM vs Docker-Based Pipelines
VM vs Docker-Based Pipelines
Codefresh
 
Automate CI/CD with Rancher
Automate CI/CD with RancherAutomate CI/CD with Rancher
Automate CI/CD with Rancher
Nick Thomas
 

What's hot (20)

Why you can't ignore GitLab
Why you can't ignore GitLabWhy you can't ignore GitLab
Why you can't ignore GitLab
 
Workflows using Git GitHub | Edureka
Workflows using Git GitHub | EdurekaWorkflows using Git GitHub | Edureka
Workflows using Git GitHub | Edureka
 
Breaking Bad Habits with GitLab CI
Breaking Bad Habits with GitLab CIBreaking Bad Habits with GitLab CI
Breaking Bad Habits with GitLab CI
 
4K–Kubernetes with Knative, Kafka and Kamel
4K–Kubernetes with Knative, Kafka and Kamel 4K–Kubernetes with Knative, Kafka and Kamel
4K–Kubernetes with Knative, Kafka and Kamel
 
GitLab - Java User Group
GitLab - Java User GroupGitLab - Java User Group
GitLab - Java User Group
 
Docker based-Pipelines with Codefresh
Docker based-Pipelines with CodefreshDocker based-Pipelines with Codefresh
Docker based-Pipelines with Codefresh
 
Containerd + buildkit breakout
Containerd + buildkit breakoutContainerd + buildkit breakout
Containerd + buildkit breakout
 
GitLab for CI/CD process
GitLab for CI/CD processGitLab for CI/CD process
GitLab for CI/CD process
 
CI with Gitlab & Docker
CI with Gitlab & DockerCI with Gitlab & Docker
CI with Gitlab & Docker
 
Quarkus: From developer joy to Kubernetes nirvana! | DevNation Tech Talk
Quarkus: From developer joy to Kubernetes nirvana! | DevNation Tech TalkQuarkus: From developer joy to Kubernetes nirvana! | DevNation Tech Talk
Quarkus: From developer joy to Kubernetes nirvana! | DevNation Tech Talk
 
Breaking bad habits with GitLab CI
Breaking bad habits with GitLab CIBreaking bad habits with GitLab CI
Breaking bad habits with GitLab CI
 
Cloud Native CI/CD with Jenkins X and Knative Pipelines
Cloud Native CI/CD with Jenkins X and Knative PipelinesCloud Native CI/CD with Jenkins X and Knative Pipelines
Cloud Native CI/CD with Jenkins X and Knative Pipelines
 
Webinar - Unbox GitLab CI/CD
Webinar - Unbox GitLab CI/CD Webinar - Unbox GitLab CI/CD
Webinar - Unbox GitLab CI/CD
 
The path to a serverless-native era with Kubernetes
The path to a serverless-native era with KubernetesThe path to a serverless-native era with Kubernetes
The path to a serverless-native era with Kubernetes
 
Docker Best Practices Workshop
Docker Best Practices WorkshopDocker Best Practices Workshop
Docker Best Practices Workshop
 
Introduction to Kubernetes - Docker Global Mentor Week 2016
Introduction to Kubernetes - Docker Global Mentor Week 2016Introduction to Kubernetes - Docker Global Mentor Week 2016
Introduction to Kubernetes - Docker Global Mentor Week 2016
 
Puzzle ITC Talk @Docker CH meetup CI CD_with_Openshift_0.2
Puzzle ITC Talk @Docker CH meetup CI CD_with_Openshift_0.2Puzzle ITC Talk @Docker CH meetup CI CD_with_Openshift_0.2
Puzzle ITC Talk @Docker CH meetup CI CD_with_Openshift_0.2
 
Setting up CI/CD pipeline with Kubernetes and Kublr step-by-step
Setting up CI/CD pipeline with Kubernetes and Kublr step-by-stepSetting up CI/CD pipeline with Kubernetes and Kublr step-by-step
Setting up CI/CD pipeline with Kubernetes and Kublr step-by-step
 
VM vs Docker-Based Pipelines
VM vs Docker-Based PipelinesVM vs Docker-Based Pipelines
VM vs Docker-Based Pipelines
 
Automate CI/CD with Rancher
Automate CI/CD with RancherAutomate CI/CD with Rancher
Automate CI/CD with Rancher
 

Similar to Continuous Deployment with Kubernetes, Docker and GitLab CI

Setting up CI/CD Pipeline with Kubernetes and Kublr step by-step
Setting up CI/CD Pipeline with Kubernetes and Kublr step by-stepSetting 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 WORLDHOW 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 !Get you Java application ready for Kubernetes !
Get you Java application ready for Kubernetes !
Anthony Dahanne
 
Getting started with kubernetes
Getting started with kubernetesGetting started with kubernetes
Getting started with kubernetes
Bob Killen
 
Adf with docker
Adf with dockerAdf with docker
Adf with docker
Eugene Fedorenko
 
01 - VMUGIT - Lecce 2018 - Fabio Rapposelli, VMware
01 - VMUGIT - Lecce 2018 - Fabio Rapposelli, VMware01 - 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 TrainingK8s in 3h - Kubernetes Fundamentals Training
K8s in 3h - Kubernetes Fundamentals Training
Piotr Perzyna
 
Docker and Puppet for Continuous Integration
Docker and Puppet for Continuous IntegrationDocker 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 nutshellContainers, 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 PipelineDCEU 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 KubernetesKubeCI - Cloud Native Continuous Delivery for Kubernetes
KubeCI - Cloud Native Continuous Delivery for Kubernetes
Tobias Schneck
 
CKA_1st.pptx
CKA_1st.pptxCKA_1st.pptx
CKA_1st.pptx
YIJHEHUANG
 
Docker kubernetes fundamental(pod_service)_190307
Docker kubernetes fundamental(pod_service)_190307Docker kubernetes fundamental(pod_service)_190307
Docker kubernetes fundamental(pod_service)_190307
Inhye Park
 
Microservices with containers in the cloud
Microservices with containers in the cloudMicroservices with containers in the cloud
Microservices with containers in the cloud
Eugene Fedorenko
 
An intro to Kubernetes operators
An intro to Kubernetes operatorsAn 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-20Knative 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 WorkshopIntroduction to Kubernetes Workshop
Introduction to Kubernetes Workshop
Bob Killen
 
Continuous Delivery the Hard Way with Kubernetes
Continuous Delivery the Hard Way with Kubernetes Continuous Delivery the Hard Way with Kubernetes
Continuous Delivery the Hard Way with Kubernetes
Weaveworks
 
Detailed Introduction To Docker
Detailed Introduction To DockerDetailed Introduction To Docker
Detailed Introduction To Docker
nklmish
 
Build optimization mechanisms in GitLab and Docker
Build optimization mechanisms in GitLab and DockerBuild optimization mechanisms in GitLab and Docker
Build optimization mechanisms in GitLab and Docker
Dmytro Patkovskyi
 

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-stepSetting up CI/CD Pipeline with Kubernetes and Kublr step by-step
Setting up CI/CD Pipeline with Kubernetes and Kublr step by-step
 
HOW TO DRONE.IO IN CI/CD WORLD
HOW TO DRONE.IO IN CI/CD WORLDHOW TO DRONE.IO IN CI/CD WORLD
HOW TO DRONE.IO IN CI/CD WORLD
 
Get you Java application ready for Kubernetes !
Get you Java application ready for Kubernetes !Get you Java application ready for Kubernetes !
Get you Java application ready for Kubernetes !
 
Getting started with kubernetes
Getting started with kubernetesGetting started with kubernetes
Getting started with kubernetes
 
Adf with docker
Adf with dockerAdf with docker
Adf with docker
 
01 - VMUGIT - Lecce 2018 - Fabio Rapposelli, VMware
01 - VMUGIT - Lecce 2018 - Fabio Rapposelli, VMware01 - VMUGIT - Lecce 2018 - Fabio Rapposelli, VMware
01 - VMUGIT - Lecce 2018 - Fabio Rapposelli, VMware
 
K8s in 3h - Kubernetes Fundamentals Training
K8s in 3h - Kubernetes Fundamentals TrainingK8s in 3h - Kubernetes Fundamentals Training
K8s in 3h - Kubernetes Fundamentals Training
 
Docker and Puppet for Continuous Integration
Docker and Puppet for Continuous IntegrationDocker and Puppet for Continuous Integration
Docker and Puppet for Continuous Integration
 
Containers, Serverless and Functions in a nutshell
Containers, Serverless and Functions in a nutshellContainers, Serverless and Functions in a nutshell
Containers, Serverless and Functions in a nutshell
 
DCEU 18: Building Your Development Pipeline
DCEU 18: Building Your Development PipelineDCEU 18: Building Your Development Pipeline
DCEU 18: Building Your Development Pipeline
 
KubeCI - Cloud Native Continuous Delivery for Kubernetes
KubeCI - Cloud Native Continuous Delivery for KubernetesKubeCI - Cloud Native Continuous Delivery for Kubernetes
KubeCI - Cloud Native Continuous Delivery for Kubernetes
 
CKA_1st.pptx
CKA_1st.pptxCKA_1st.pptx
CKA_1st.pptx
 
Docker kubernetes fundamental(pod_service)_190307
Docker kubernetes fundamental(pod_service)_190307Docker kubernetes fundamental(pod_service)_190307
Docker kubernetes fundamental(pod_service)_190307
 
Microservices with containers in the cloud
Microservices with containers in the cloudMicroservices with containers in the cloud
Microservices with containers in the cloud
 
An intro to Kubernetes operators
An intro to Kubernetes operatorsAn intro to Kubernetes operators
An intro to Kubernetes operators
 
Knative build for open whisk runtimes phase 1 - 2018-02-20
Knative build for open whisk runtimes   phase 1 - 2018-02-20Knative build for open whisk runtimes   phase 1 - 2018-02-20
Knative build for open whisk runtimes phase 1 - 2018-02-20
 
Introduction to Kubernetes Workshop
Introduction to Kubernetes WorkshopIntroduction to Kubernetes Workshop
Introduction to Kubernetes Workshop
 
Continuous Delivery the Hard Way with Kubernetes
Continuous Delivery the Hard Way with Kubernetes Continuous Delivery the Hard Way with Kubernetes
Continuous Delivery the Hard Way with Kubernetes
 
Detailed Introduction To Docker
Detailed Introduction To DockerDetailed Introduction To Docker
Detailed Introduction To Docker
 
Build optimization mechanisms in GitLab and Docker
Build optimization mechanisms in GitLab and DockerBuild optimization mechanisms in GitLab and Docker
Build optimization mechanisms in GitLab and Docker
 

Recently uploaded

How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
XfilesPro
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
KrzysztofKkol1
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
varshanayak241
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
ayushiqss
 

Recently uploaded (20)

How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
 

Continuous Deployment with Kubernetes, Docker and GitLab CI

  • 1. Continuous Deployment with Kubernetes, Docker and GitLab CI @alexander_kiel
 Clojure Berlin 2016
  • 2.
  • 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
 alexanderkiel@gmx.net