Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

64
Deploying DevOps Days PGH 2014.05.30 a.k.a. provisioning docker containers and images with Chef Deploying with Docker (or not)

description

Using Docker to bake configuration.

Transcript of Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

Page 1: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

Deployingwith Docker

DevOps Days PGH 2014.05.30

a.k.a. provisioning docker containers and images with Chef

Deployingwith Docker

(or not)

Page 2: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Page 3: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Page 4: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Page 5: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Page 6: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

Why do we still need<insert tool here>?

Page 7: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

But… we have Dockerfiles!

Page 8: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Page 9: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

It’s a shell-script?

$ cat SomeApp/DockerfileFROM ubuntu:13.10 RUN apt-get update; apt-get install apache RUN sed ’s/something/else/‘ /etc/apache/httpd.conf ADD shell-script.shRUN shell-script.shRUN [‘/usr/bin/apachectl’, ‘start’]

Page 10: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

I ♥ #!/bin/bash. oo # https://raw.githubusercontent.com/ # ewindisch/bashoo/master/lib/oo # Classes are created implicitly through functionsfunction MsgWriter::new { self=$1; shift msg=$1; shift instance_var $self msg $msg } function MsgWriter::write { self=$1; shift echo $($self.msg) } new terminal is MsgWriter “Hello World” terminal.write

Page 11: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

stack:~/devstack$ wc -l stack.sh functions \ functions-common \ lib/* lib/*/* | tail -n1 15490 total

Page 12: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

DevOpsor

crazy-sauce?

Page 13: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Page 14: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

$ cd ~/rpm-chef $ cat Dockerfile FROM fedora RUN yum update \ yum -y install chef

Do

cker

Chef

Page 15: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

$ cd ~/omnibus-chef $ cat Dockerfile FROM fedora"RUN curl -L \ https://www.opscode.com/chef/install.sh | /bin/bash

Do

cker

Chef

Page 16: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

Traditional Chef

Hardware

OS

Linux

Chef

Installs Chef

Runs

Configures

Page 17: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Page 18: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

Images on HWis usually mutable

Hardware

Image

Linux

Chef

Installs Chef

Image'

Linux

Chef

Creates

Replaces

Runs

Page 19: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

Ephemeral environmentsare (somewhat) immutable.

Hypervisor

Image

Linux

Chef

Runs

Image'

Linux

Chef

Chef

Runs

Configures

VM

Accesses

COW

Page 20: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Page 21: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

Chef-for-runtime

$ cat Dockerfile FROM fedora RUN yum update; \ yum -y install chef

ADD http://x/receipes.tar.gz /opt/chef"ADD solo.rb /etc/chef/solo.rb"CMD chef-solo -c /etc/chef/solo.rb ; \! apachectl start

Page 22: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Page 23: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Page 24: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Page 25: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Page 26: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Page 27: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Page 28: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Page 29: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

Containersare

THINGS

Page 30: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

X

Page 31: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

X

Page 32: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Page 33: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

Servers vs Things

Pets vs Cattle

Page 34: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Page 35: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

LET US BAKEIMAGES!

Let us

BAKE

images!

Page 36: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Page 37: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

Containers are like ephemeral VMs*

* Docker containers don’t HAVE to be ephemeral, but it’s TheRightThing

Docker

Image

Linux

Chef

Runs

Image'

Linux

Chef

Chef

Runs

Configures

Container

Accesses

COW

TM

Page 38: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

Bakery Chef

$ cat Dockerfile FROM fedora RUN yum update; \ yum -y install chef"ADD http://x/receipes.tar.gz /opt/chef"ADD solo.rb /etc/chef/solo.rb"RUN chef-solo -c /etc/chef/solo.rb

Page 39: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

Burning configuration into images.

Docker ContainerInitiates Creates

Image

Linux

Chef

Chef

Runs

Configures

Build Creates

Page 40: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

Expanded view:Burning configuration into

images.

Docker Image tagInitiates

Image'

Linux

Chef

Chef

Build

Image

Linux

Chef

Creates

Creates

Runs Creates

References1

2

Page 41: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Page 42: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Page 43: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

Anatomy of a Docker+Chef build & run

Docker ContainerInitiates Creates

Image

Linux

Chef

Chef

Runs

Configures

Chef

Runs

Configures

Build Creates

Stage 1 Stage 2

Page 44: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

For All The Things!

$ cat Dockerfile FROM fedora RUN yum update; \ yum -y install chef ADD http://x/receipes.tar.gz /opt/chef"ADD solo-stage1.rb /etc/chef/solo-stage1.rb"ADD solo-stage2.rb /etc/chef/solo-stage2.rb"RUN chef-solo -c /etc/chef/solo-stage1.rb"CMD chef-solo -c /etc/chef/solo-stage2.rb; \" apachectl start

Page 45: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

Does it converge?

$ docker build —rm . $ echo $? # pass or fail

(This is great use of Docker as an alternative to VMs for testing Chef recipes targeting non-Docker production systems)

Page 46: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

Deploying Docker (for real this time)

Page 47: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

#!/bin/bash -x aws ec2 run-instances \ --image-id ami-e55a648c \ --key-name my-key \ --user-data "#include https://get.docker.io” ip=$(aws ec2 describe-instances \ --output json \ --filter Name=instance-state-name,Values=running | python \ -c 'import json; import sys; print json.load(sys.stdin)[“Reservations”][0]["Instances"][0]["PublicIpAddress"]') ssh ubuntu@$ip sudo docker run cirros

Page 48: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

# using https://github.com/bflad/chef-docker $ cat cookbooks/docker-registry/default.rb# Pull latest image docker_image 'samalba/docker-registry' !# Run container exposing ports docker_container 'samalba/docker-registry' do detach true port '5000:5000' env 'SETTINGS_FLAVOR=local' volume '/mnt/docker:/docker-storage' end $ knife ec2 server create # yada yada yada

Page 49: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

docker::run { 'helloworld': image => 'base', command => '/bin/sh -c "while true; do echo hello world; sleep 1; done"', ports => ['4444', '4555'], links => ['mysql:db'], use_name => true, volumes => ['/var/lib/couchdb', '/var/log'], volumes_from => '6446ea52fbc9', memory_limit => 10485760, # bytes username => 'example', hostname => 'example.com', env => ['FOO=BAR', 'FOO2=BAR2'], dns => ['8.8.8.8', '8.8.4.4'], restart_service => true, }

Page 50: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

7KH�'RFNHU�SOXJLQ�IRU�+HDW%\�XVLQJ�WKH�SOXJLQ��+HDW�FDQ�WDON�GLUHFWO\�WR�'RFNHU

Orchestration for Dockerwith OpenStack Heat

DockerInc::Docker::Container

VMs

Baremetal

Page 51: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

Heat Workflow

Heat API

VM

Docker

NovaNova resource

Docker resource

Container1

Container2

Container3

HOT

Page 52: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

heat_template_version: 2013-05-23 description: shared volumes example resources: my_instance: type: OS::Nova::Server properties: key_name: ewindisch_key image: ubuntu-precise flavor: m1.large user_data: #include https://get.docker.io ftp_container: type: DockerInc::Docker::Container properties: docker_endpoint: { get_attr: [my_instance, first_address] } image: mikz/vsftpd ports: [ “21:21” ] volumes: [ “/ftp” ] name: “FTP”

apache_container: type: DockerInc::Docker::Container properties: docker_endpoint: { get_attr: [my_instance, first_address] } image: fedora/apache ports: [ “80:80” ] volumes-from: “FTP” cmd: “rm -rf /var/www; ln -s /ftp /var/www; /run-apache.sh”

Page 53: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

Ansible- hosts: web sudo: yes tasks: - name: ensure redis container is running docker: image=crosbymichael/redis name=redis - name: ensure redis_ambassador container is running docker: image=svendowideit/ambassador ports=6379:6379 links=redis:redis name=redis_ambassador_ansible

Page 54: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

Mesos Flynn.io

Page 55: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

Creating Containers is Easy

Page 56: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

Managing them SUCKS

needs improvement

Page 57: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

This is probably material for another

talk…

Page 58: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

Container Inventory

• discoverd / sdutil • serf • skydock • others?

Page 59: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

X

Page 60: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

X

Page 61: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Page 62: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Page 63: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Page 64: Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

Q & A

@ewindisch