Thanks to visit codestin.com
Credit goes to www.slideshare.net

Continuous Delivery to
Kubernetes using
Helm
Adnan Abdulhussein - @prydonius
CI/CD
•Run Unit/Functional Tests
… also for PRs
•Automatically Build and Push Images
•Rollout New Version
Code/config change
Build
Test
Push Docker image
Staging/QA deployment
Production deployment
Manual verification
Code/config change
Build
Test
Push Docker image
Staging/QA deployment
Production deployment
Manual verification
Example: Kubernetes resource
apiVersion: v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 1
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: prydonius/seanmeme:v1.0.0
ports:
- containerPort: 80
livenessProbe:
httpGet:
path: /
port: http
initialDelaySeconds: 120
timeoutSeconds: 5
kubectl apply -f manifests/
Rolling Upgrade
sed -i.bak
's#prydonius/seanmeme:v1.0.0#${imageTag}#'
deployment.yaml
Package Manager
for Kubernetes
a little bit about Helm...
• an easier way to manage and share manifests
• tweak definitions for different environments
• manage the lifecycle of our application
Charts(packages)
● Are application definitions
● Consist of metadata, definitions, config and
documentation
● Live in chart repositories
todo
├── Chart.yaml
├── README.md
├── templates
│ ├── NOTES.txt
│ ├── _helpers.tpl
│ ├──
deployment.yaml
│ └── service.yaml
└── values.yaml
Tiller
• In-cluster component
• Renders Chart templates
• Creates/updates resources
• Tracks state of applications
Kubernetes
Helm
Client
gRPC Kube
API
Tiller
helm install my-app --set image.tag=${imageTag}
Seek. Locate. Deploy.
Demo!
Pipeline Stages: Build
environment {
IMAGE_NAME = 'prydonius/seanmeme'
}
stage('Build') {
agent any
steps {
checkout scm
sh 'docker build -t $IMAGE_NAME:$BUILD_ID .'
}
}
Pipeline Stages: Push
stage('Image Release') {
agent any
when {
expression { env.BRANCH_NAME == 'master' }
}
steps {
withCredentials([[$class: 'UsernamePasswordMultiBinding',
credentialsId: 'dockerhub',
usernameVariable: 'DOCKER_USERNAME', passwordVariable:
'DOCKER_PASSWORD']]) {
sh '''
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
docker push $IMAGE_NAME:$BUILD_ID
'''
}
}
}
Only release master builds
Pipeline Stages: Staging Deployment
stage('Staging Deployment') {
...
environment {
RELEASE_NAME = 'seanmeme-staging'
SERVER_HOST = 'staging.seanmeme.k8s.prydoni.us'
}
steps {
sh '''
. ./helm/helm-init.sh
helm upgrade --install --namespace staging $RELEASE_NAME ./helm/seanmeme 
--set image.tag=$BUILD_ID,ingress.host=$SERVER_HOST
'''
}
}
Pipeline Stages: Manual Verification
stage('Deploy to Production?') {
when {
expression { env.BRANCH_NAME == 'master' }
}
steps {
// Prevent any older builds from deploying to production
milestone(1)
input 'Deploy to Production?'
milestone(2)
}
}
Pipeline Stages: Production Deployment
stage('Production Deployment') {
...
environment {
RELEASE_NAME = 'seanmeme-production'
SERVER_HOST = 'seanmeme.k8s.prydoni.us'
}
steps {
sh '''
. ./helm/helm-init.sh
helm upgrade --install --namespace production $RELEASE_NAME ./helm/seanmeme 
--set image.tag=$BUILD_ID,ingress.host=$SERVER_HOST
'''
}
}
Helm Community
• Over 187 contributors
• Helm 2.6.1 released last week!
• Slack channel: Kubernetes #helm-users
• Public dev meetings: Thursdays @ 5:30pm BST (Helm), @ 7pm BST (Charts)
• Weekly updates & demos at SIG-Apps meetings:
Mondays @ 9am pacific (5pm BST)
Join
us!
Thank You

Continous Delivery to Kubernetes using Helm

  • 2.
    Continuous Delivery to Kubernetesusing Helm Adnan Abdulhussein - @prydonius
  • 4.
    CI/CD •Run Unit/Functional Tests …also for PRs •Automatically Build and Push Images •Rollout New Version
  • 5.
    Code/config change Build Test Push Dockerimage Staging/QA deployment Production deployment Manual verification
  • 6.
    Code/config change Build Test Push Dockerimage Staging/QA deployment Production deployment Manual verification
  • 8.
    Example: Kubernetes resource apiVersion:v1 kind: Deployment metadata: name: my-app spec: replicas: 1 template: metadata: labels: app: my-app spec: containers: - name: my-app image: prydonius/seanmeme:v1.0.0 ports: - containerPort: 80 livenessProbe: httpGet: path: / port: http initialDelaySeconds: 120 timeoutSeconds: 5
  • 9.
    kubectl apply -fmanifests/
  • 10.
  • 11.
  • 12.
  • 13.
    a little bitabout Helm... • an easier way to manage and share manifests • tweak definitions for different environments • manage the lifecycle of our application
  • 14.
    Charts(packages) ● Are applicationdefinitions ● Consist of metadata, definitions, config and documentation ● Live in chart repositories todo ├── Chart.yaml ├── README.md ├── templates │ ├── NOTES.txt │ ├── _helpers.tpl │ ├── deployment.yaml │ └── service.yaml └── values.yaml
  • 15.
    Tiller • In-cluster component •Renders Chart templates • Creates/updates resources • Tracks state of applications Kubernetes Helm Client gRPC Kube API Tiller
  • 16.
    helm install my-app--set image.tag=${imageTag}
  • 17.
  • 18.
  • 21.
    Pipeline Stages: Build environment{ IMAGE_NAME = 'prydonius/seanmeme' } stage('Build') { agent any steps { checkout scm sh 'docker build -t $IMAGE_NAME:$BUILD_ID .' } }
  • 22.
    Pipeline Stages: Push stage('ImageRelease') { agent any when { expression { env.BRANCH_NAME == 'master' } } steps { withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'dockerhub', usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD']]) { sh ''' docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD docker push $IMAGE_NAME:$BUILD_ID ''' } } } Only release master builds
  • 23.
    Pipeline Stages: StagingDeployment stage('Staging Deployment') { ... environment { RELEASE_NAME = 'seanmeme-staging' SERVER_HOST = 'staging.seanmeme.k8s.prydoni.us' } steps { sh ''' . ./helm/helm-init.sh helm upgrade --install --namespace staging $RELEASE_NAME ./helm/seanmeme --set image.tag=$BUILD_ID,ingress.host=$SERVER_HOST ''' } }
  • 24.
    Pipeline Stages: ManualVerification stage('Deploy to Production?') { when { expression { env.BRANCH_NAME == 'master' } } steps { // Prevent any older builds from deploying to production milestone(1) input 'Deploy to Production?' milestone(2) } }
  • 25.
    Pipeline Stages: ProductionDeployment stage('Production Deployment') { ... environment { RELEASE_NAME = 'seanmeme-production' SERVER_HOST = 'seanmeme.k8s.prydoni.us' } steps { sh ''' . ./helm/helm-init.sh helm upgrade --install --namespace production $RELEASE_NAME ./helm/seanmeme --set image.tag=$BUILD_ID,ingress.host=$SERVER_HOST ''' } }
  • 26.
    Helm Community • Over187 contributors • Helm 2.6.1 released last week! • Slack channel: Kubernetes #helm-users • Public dev meetings: Thursdays @ 5:30pm BST (Helm), @ 7pm BST (Charts) • Weekly updates & demos at SIG-Apps meetings: Mondays @ 9am pacific (5pm BST) Join us!
  • 27.