Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Using Chef to manage your container workflow

Tom Duffield
September 13, 2014

Using Chef to manage your container workflow

Slides from a talk I gave at Fossetcon2014 on how you can leverage Chef Container to manage your Docker container workflow.

Tom Duffield

September 13, 2014
Tweet

More Decks by Tom Duffield

Other Decks in Technology

Transcript

  1. Chef for Containers
    Using config management in your container workflow
    Tom Duffield
    Software Development Engineer at Chef
    Twitter: @tomduffield
    Fossetcon 2014

    View full-size slide

  2. Agenda
    Introduction to Docker
    Chef Container
    Knife Container Workflow
    More Information
    Questions

    View full-size slide

  3. Introduction to Docker

    View full-size slide

  4. What are Linux containers?
    • Lightweight virtualization provided by libraries inside the
    Linux Kernel.
    • cgroups
    • namespaces
    • capabilities
    • selinux
    • apparmor
    • netlink
    • netfilter

    View full-size slide

  5. 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)

    View full-size slide

  6. 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

    View full-size slide

  7. Docker Containers
    Server
    Host OS
    bins/libs
    app b app d
    app c
    Container
    Docker Engine
    bins/libs
    app a

    View full-size slide

  8. Benefits & Gaps of Containers
    Benefits Gaps
    Speed
    Portability
    Density
    Security
    Persistent State
    Credentials

    View full-size slide

  9. Simple Docker Workflow
    Pull
    (Download)
    Run
    (Launch)
    Commit
    (Snapshot)

    View full-size slide

  10. docker pull ubuntu:12.04
    ubuntu 12.04

    View full-size slide

  11. docker run ubuntu:12.04 apt-get update
    ubuntu 12.04
    apt-get update
    012345678

    View full-size slide

  12. docker commit 012345678
    ubuntu 12.04
    apt-get update
    012345678

    View full-size slide

  13. docker run 012345678 apt-get upgrade
    ubuntu:12.04
    apt-get update
    012345678
    apt-get upgrade
    ABCDEFG

    View full-size slide

  14. docker commit ABCDEFG
    ubuntu:12.04
    apt-get update
    ABCDEFG
    apt-get upgrade

    View full-size slide

  15. The Dockerfile
    FROM ubuntu:12.04
    RUN apt-get update
    RUN apt-get upgrade

    View full-size slide

  16. Dockerfile Workflow
    Pull Build Run
    Run Commit

    View full-size slide

  17. 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

    View full-size slide

  18. Chef Container

    View full-size slide

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

    View full-size slide

  20. 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.

    View full-size slide

  21. 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.

    View full-size slide

  22. Consistency Across Architectures
    Physical Virtual Cloud Container

    View full-size slide

  23. Mixed Architecture Applications
    Development Test QA Prod

    View full-size slide

  24. Understanding the PID1 Problem
    $ docker run busybox ps -ef
    PID USER COMMAND
    1 root ps -ef
    • The command you specify via docker run replaces init
    and becomes the root process (PID1).

    View full-size slide

  25. 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.

    View full-size slide

  26. Chef Container Components
    chef-client
    runit
    chef-init

    View full-size slide

  27. runit is a lightweight, cross-platform init scheme
    you can use to ensure all child processes are
    properly managed.
    http://smarden.org/runit/

    View full-size slide

  28. chef-init is a root process which can launch and
    manage multiple processes inside a container.
    https://github.com/opscode/chef-init

    View full-size slide

  29. debian logo redhat logo centos logo
    init init init init

    View full-size slide

  30. debian logo redhat logo centos logo
    docker

    View full-size slide

  31. debian logo redhat logo centos logo
    chef-init chef-init chef-init chef-init
    docker
    runit runit runit runit

    View full-size slide

  32. Knife Container Workflow

    View full-size slide

  33. knife container TOOL SUBCOMMAND
    chef gem install knife-container

    View full-size slide

  34. knife container docker init
    Generate Docker Context
    Download Base Docker Image
    Docker Components
    Chef Components

    View full-size slide

  35. 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.

    View full-size slide

  36. v0
    ubuntu-12.04
    knife container docker init
    myorg/myapp

    View full-size slide

  37. knife container docker build
    Resolve Chef Dependencies
    Build Docker Image
    Cleanup Chef Artifacts

    View full-size slide

  38. knife container docker build
    $ knife container docker build NAMESPACE/IMAGE_NAME [options]
    Frequently Used Options
    Flag Description
    --force Force the resolution of Chef dependencies.

    View full-size slide

  39. v0
    ubuntu-12.04
    knife container docker build
    myorg/myapp
    v1

    View full-size slide

  40. v0
    ubuntu-12.04
    knife container docker build
    myorg/myapp
    v1 v2

    View full-size slide

  41. Long Term Speed Benefits
    A B C D
    L1 L2 L3 L4
    R1 R2 R3 R4

    View full-size slide

  42. Long Term Speed Benefits
    A B C D
    L1 L2 L3 L4
    R1 R2 R3 R4

    View full-size slide

  43. ubuntu:12.04
    L1
    Image v1
    ubuntu-12.04
    CCR1 : R1-4
    Image v1
    L2
    L3
    L4

    View full-size slide

  44. ubuntu:12.04
    L1
    Image v2
    ubuntu-12.04
    CCR1 : R1-4
    Image v2
    L2
    L3
    L4
    CCR2 : R2

    View full-size slide

  45. 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.

    View full-size slide

  46. More Information

    View full-size slide

  47. Documentation
    Documentation: http://docs.getchef.com/containers.html
    Docker Images: https://hub.docker.com/u/chef
    Feedback:
    http://github.com/opscode/chef-init
    http://github.com/opscode/knife-container

    View full-size slide

  48. 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/issues
    http://github.com/opscode/chef-init/issues

    View full-size slide

  49. Questions?
    Tom Duffield | @tomduffield

    View full-size slide