Continuous deployment with Jenkins and Salt LinuxCon CloudOpen - - PowerPoint PPT Presentation

continuous deployment with jenkins and salt
SMART_READER_LITE
LIVE PREVIEW

Continuous deployment with Jenkins and Salt LinuxCon CloudOpen - - PowerPoint PPT Presentation

Continuous deployment with Jenkins and Salt LinuxCon CloudOpen ContainerCon North America 2015, Seattle Anirban Saha About me Techie Traveller Thinker Author of Salt Cookbook Deployment Should be Simple Stable


slide-1
SLIDE 1

Continuous deployment with Jenkins and Salt

LinuxCon CloudOpen ContainerCon North America 2015, Seattle Anirban Saha

slide-2
SLIDE 2

About me

Techie… Traveller… Thinker… Author of ‘Salt Cookbook’

slide-3
SLIDE 3

Deployment

Should be…

  • Simple
  • Stable
  • Fast (good to have…)
  • Reliable
  • One click
slide-4
SLIDE 4

Problems faced

  • Code distribution
  • Additional tasks (commands, migrations)
  • Latency
  • Parallel execution
  • Batch deployments
  • Ensuring uptime
slide-5
SLIDE 5

Methods available

Deployment

Configuration management tools :

  • Puppet, Chef, Ansible, Salt

Remote execution tools:

  • SSH, Parallel SSH, Rundeck

Packages:

  • Code packaged as RPM or DEB files
slide-6
SLIDE 6

Code storage

  • GIT server (Github, Gitlab, Bitbucket, etc.)
  • Object storage (Amazon S3, Swift, etc.)
  • Package repositories (YUM/Debian)
  • Configuration management repositories
  • File servers managed manually
slide-7
SLIDE 7

Problems

Deployment:

  • Remote execution tools :
  • Time consuming (over SSH)
  • Need to maintain inventory of hosts

Code storage:

  • GIT repositories:
  • Usually centrally located, latency when deployed from GIT
  • Package repositories (RPM/DEB):
  • Problems in simultaneously updating repo metadata

Rollback:

  • Version manipulation is a problem with most configuration

management and remote execution tools

slide-8
SLIDE 8

Salt

Provides…

  • Agent based communication
  • Fast execution
  • Orchestration
  • Batch execution
  • Strong Integration with providers and

services

slide-9
SLIDE 9

Salt features

Targeting deployment nodes :

  • By hostname
  • ‘myappweb*’
  • By specific grains
  • -G ‘node_type:webserver’
  • By nodegroups
  • -N webgroup
slide-10
SLIDE 10

Salt features

Task dependencies :

  • Salt requisites to make tasks dependent on each other

get_archive: module.run: . . deploy_app: module.run: . .

  • require:
  • module: get_archive
slide-11
SLIDE 11

Salt features

Orchestration : webgrp2_deploy: salt.state:

  • tgt: ' webgrp2'
  • tgt_type: nodegroup
  • sls:
  • webserver.deploy
  • require:
  • salt: webgrp1_deploy

webgrp1_deploy: salt.state:

  • tgt: 'webgrp1'
  • tgt_type: nodegroup
  • sls:
  • webserver.deploy
slide-12
SLIDE 12

Salt features

Batch Execution :

  • By number of hosts
  • --batch-size 5
  • Executes on 5 hosts at a time
  • By percentage of hosts
  • --batch-size 25%
  • Executes on 25% of total target

hosts at a time

slide-13
SLIDE 13

Salt features

Salt API:

# curl -H "Accept: application/json"

  • d secretkey= "mysupersecretkey"
  • k https://10.0.0.2:8080/hook/deploy

{"success": true}

slide-14
SLIDE 14

Tools

To be used…

  • GIT for code repository
  • Jenkins for CI
  • Ant for build and tasks
  • Amazon S3 for code archive storage
  • Salt for deployment
  • Shell scripts (good old bash) for

additional tasks

slide-15
SLIDE 15

Salt deployment methods

  • Salt hosted on the Jenkins server.

Jenkins calls Salt binary

  • Salt hosted independently.

Jenkins calls Salt via SSH

  • Jenkins calls Salt via Salt API
slide-16
SLIDE 16

Objective

slide-17
SLIDE 17

Steps

  • salt-cloud used to launch instances
  • Post install actions used to synchronize EC2 grains
  • Salt reactor used to run states on new instances ,

perform deployment and register with load balancer

  • Jenkins build job used to build new code, create tags

and push new deployment ready archive to Amazon S3

  • Jenkins deploy job used to fetch new code version

and deploy code on target servers

slide-18
SLIDE 18

Steps explained

  • Salt cloud is used to spawn instances
  • Following parameter is provided in the profile to push custom EC2 grains,
  • sync_after_install: grains
  • The node is registered and deregistered from the load balancer with the

following module definition, register: module.run:

  • name: boto_elb.register_instances
  • m_name: mywebapp
  • instances:
  • {{ grains['ec2']['instance_id'] }}
  • Here ['ec2']['instance_id'] is one of the custom grains pushed to the node
slide-19
SLIDE 19

Steps explained

Fetching archive: Salt s3 execution module used to get code archive from Amazon S3 fetch_app_archive: module.run:

  • name: s3.get
  • bucket: mywebapp-us
  • path: mywebapp-{{ app_version }}.tar
  • local_file: /tmp/mywebapp-{{ app_version }}.tar
slide-20
SLIDE 20

Steps explained

Setting App version grain: After every deploy, a grain is set to record the app version deployed for tracking, app_version: grains.present:

  • value: {{ app_version }}
  • require:
  • cmd: deploy_app
slide-21
SLIDE 21

Steps explained

Deployment based on App version: At every deploy, it is checked if the version to be deployed is already on the node using the app_version grain, {% if grains['app_version'] != app_version %} deregister: fetch_app_archive: deploy_app: register: {% endif %}

slide-22
SLIDE 22

Lets do it then !!!

slide-23
SLIDE 23

Demo repository

Get the demo repository at the following location, https://github.com/rosesnthornz/ cloudopen-na-2015

slide-24
SLIDE 24

Questions ?

slide-25
SLIDE 25

Contact

Email : sahaanirban1988@gmail.com Twitter : @rosesnthornz

slide-26
SLIDE 26

Thank You !!!