51

[Fossetcon] Chef Container

Embed Size (px)

DESCRIPTION

A talk given at Fossetcon2014 describing the new Chef Container functionality.

Citation preview

Page 1: [Fossetcon] Chef Container
Page 2: [Fossetcon] Chef Container

Chef for ContainersUsing config management in your container workflowTom DuffieldSoftware Development Engineer at ChefTwitter: @tomduffield

Fossetcon 2014

Page 3: [Fossetcon] Chef Container

AgendaIntroduction to DockerChef ContainerKnife Container WorkflowMore InformationQuestions

Page 4: [Fossetcon] Chef Container

Introduction to Docker

Page 5: [Fossetcon] Chef Container

What are Linux containers?• Lightweight virtualization provided by libraries inside the

Linux Kernel.

• cgroups• namespaces• capabilities• selinux

• apparmor• netlink• netfilter

Page 6: [Fossetcon] Chef Container

What is Docker?• Utility that improves the usability of Linux Containers by

providing:• a layered file system (Docker Images)• a cross-platform execution engine (Docker Engine)• a social space to share common libraries (Docker Hub)

Page 7: [Fossetcon] Chef Container

Hypervisor Virtualization

Server

Host OS

Hypervisor

Guest OS

bins/libs

app a

Guest OS

bins/libs

app d

Guest OS

bins/libs

app b

Guest OS

bins/libs

app c

Virtual Machine

Page 8: [Fossetcon] Chef Container

Docker Containers

Server

Host OS

bins/libs

app b app dapp cContainer

Docker Engine

bins/libs

app a

Page 9: [Fossetcon] Chef Container

Benefits & Gaps of Containers

Benefits GapsSpeed

Portability

Density

Security

Persistent State

Credentials

Page 10: [Fossetcon] Chef Container

Simple Docker Workflow

Pull(Download)

Run(Launch)

Commit(Snapshot)

Page 11: [Fossetcon] Chef Container

docker pull ubuntu:12.04

ubuntu 12.04

Page 12: [Fossetcon] Chef Container

docker run ubuntu:12.04 apt-get update

ubuntu 12.04

apt-get update

012345678

Page 13: [Fossetcon] Chef Container

docker commit 012345678

ubuntu 12.04

apt-get update

012345678

Page 14: [Fossetcon] Chef Container

docker run 012345678 apt-get upgrade

ubuntu:12.04

apt-get update

012345678

apt-get upgrade

ABCDEFG

Page 15: [Fossetcon] Chef Container

docker commit ABCDEFG

ubuntu:12.04

apt-get update

ABCDEFG

apt-get upgrade

Page 16: [Fossetcon] Chef Container

The DockerfileFROM ubuntu:12.04

RUN apt-get update

RUN apt-get upgrade

Page 17: [Fossetcon] Chef Container

Dockerfile Workflow

Pull Build Run

Run Commit

Page 18: [Fossetcon] Chef Container

docker build mycontext

FROM ubuntu:12.04

RUN apt-get update

RUN apt-get install apache2

ADD myconf.conf \

/etc/apache2/sites-enabled/mysite

ADD mysite /var/www/mysite

Dockerfile

myconf.conf

mycontext

mysite

index.html

Dockerfile

Page 19: [Fossetcon] Chef Container

Chef Container

Page 20: [Fossetcon] Chef Container

Chef Container is a package that provides configuration management for your containers.

Page 21: [Fossetcon] Chef Container

Chef Container allows you to:• define your container configuration using Chef recipes.• idempotently manage the running state of your container.• safely manage multiple services inside your container.

Page 22: [Fossetcon] Chef Container

Chef Container is a great for handling:• installation and configuration of complex applications.• transitioning traditional architecture to containers.• handling last-mile configuration when container boots.

Page 23: [Fossetcon] Chef Container

Consistency Across Architectures

Physical Virtual Cloud Container

Page 24: [Fossetcon] Chef Container

Mixed Architecture Applications

Development Test QA Prod

Page 25: [Fossetcon] Chef Container

Understanding the PID1 Problem

$ docker run busybox ps -ef

PID USER COMMAND1 root ps -ef

• The command you specify via docker run replaces init and becomes the root process (PID1).

Page 26: [Fossetcon] Chef Container

Addressing the PID1 Problem• The root process (PID1) is responsible for:

• telling the container what processes it should run.

• ensuring all child processes are properly managed.

Page 27: [Fossetcon] Chef Container

Chef Container Components

chef-client

runit

chef-init

Page 28: [Fossetcon] Chef Container

runit is a lightweight, cross-platform init scheme you can use to ensure all child processes are properly managed.

http://smarden.org/runit/

Page 29: [Fossetcon] Chef Container

chef-init is a root process which can launch and manage multiple processes inside a container.

https://github.com/opscode/chef-init

Page 30: [Fossetcon] Chef Container

debian logo redhat logo centos logo

init init init init

Page 31: [Fossetcon] Chef Container

debian logo redhat logo centos logo

docker

Page 32: [Fossetcon] Chef Container

debian logo redhat logo centos logo

chef-init chef-init chef-init chef-init

docker

runit runit runit runit

Page 33: [Fossetcon] Chef Container

Knife Container Workflow

Page 34: [Fossetcon] Chef Container

knife container TOOL SUBCOMMAND

chef gem install knife-container

Page 35: [Fossetcon] Chef Container

knife container docker init

Generate Docker Context

Download Base Docker Image

Docker Components

Chef Components

Page 36: [Fossetcon] Chef Container

knife container docker init

$ knife container docker init NAMESPACE/IMAGE_NAME [options]

Frequently Used Options

Flag Description

-f The base Docker image to use. The default is chef/ubuntu-12.04.

-r Your Chef run list.

-z Use chef-client local mode.

-b Use Berkshelf to manage cookbook dependencies.

Page 37: [Fossetcon] Chef Container

v0

ubuntu-12.04

knife container docker init

myorg/myapp

Page 38: [Fossetcon] Chef Container

knife container docker build

Resolve Chef Dependencies

Build Docker Image

Cleanup Chef Artifacts

Page 39: [Fossetcon] Chef Container

knife container docker build

$ knife container docker build NAMESPACE/IMAGE_NAME [options]

Frequently Used Options

Flag Description

--force Force the resolution of Chef dependencies.

Page 40: [Fossetcon] Chef Container

v0

ubuntu-12.04

knife container docker build

myorg/myapp

v1

Page 41: [Fossetcon] Chef Container

v0

ubuntu-12.04

knife container docker build

myorg/myapp

v1 v2

Page 42: [Fossetcon] Chef Container

Long Term Speed Benefits

A B C D

L1 L2 L3 L4

R1 R2 R3 R4

Page 43: [Fossetcon] Chef Container

Long Term Speed Benefits

A B C D

L1 L2 L3 L4

R1 R2 R3 R4

Page 44: [Fossetcon] Chef Container

ubuntu:12.04

L1

Image v1

ubuntu-12.04

CCR1 : R1-4

Image v1

L2

L3

L4

Page 45: [Fossetcon] Chef Container

ubuntu:12.04

L1

Image v2

ubuntu-12.04

CCR1 : R1-4

Image v2

L2

L3

L4

CCR2 : R2

Page 46: [Fossetcon] Chef Container

Why use Chef Container?1) Fast and easy transition from existing architecture. 2) Consistent configuration model across containerization

solutions and types of architectures.3) Mixed infrastructure environments.4) Idempotency in your image build process and in your

running containers.5) Decreased overhead for configuration changes.

Page 47: [Fossetcon] Chef Container

More Information

Page 48: [Fossetcon] Chef Container

DocumentationDocumentation: http://docs.getchef.com/containers.htmlDocker Images: https://hub.docker.com/u/chef

Feedback: http://github.com/opscode/chef-init http://github.com/opscode/knife-container

Page 49: [Fossetcon] Chef Container

Roadmap• Rebuild images from a fresh base image.• Add multiple, custom tags to your Docker images.• Improved management of secure credentials.

What would you like to see? Submit input and feedback!http://github.com/opscode/knife-container/issueshttp://github.com/opscode/chef-init/issues

Page 50: [Fossetcon] Chef Container

Questions?

Tom Duffield | @tomduffield

Page 51: [Fossetcon] Chef Container