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

Linux Conf Australia 2016 - The Twelve-Factor Container

Casey West
February 01, 2016

Linux Conf Australia 2016 - The Twelve-Factor Container

In 2012 Adam Wiggins wrote [the twelve-factor app](http://12factor.net/), an essay widely considered canon for building cloud-native applications. The advent of the container ecosystem transformed these principles into hard constraints. This talk will review what you can _and cannot_ do with containers if you want to maintain repeatability, reliability, and portability.

Casey West

February 01, 2016
Tweet

More Decks by Casey West

Other Decks in Technology

Transcript

  1. The Twelve-Factor Container
    • Twitter @caseywest
    • Email [email protected]
    • Web http://caseywest.com
    • Days since I last used that joke zero
    1 @caseywest

    View Slide

  2. Thanks a lot, Pivotal
    2 @caseywest

    View Slide

  3. This isn't really a talk
    about containers
    3 @caseywest

    View Slide

  4. This is a talk about
    operational maturity
    4 @caseywest

    View Slide

  5. You must be this tall to
    ride this ride
    5 @caseywest

    View Slide

  6. Audience Participation
    • Containers?
    • Schedulers?
    • Cloud?
    6 @caseywest

    View Slide

  7. Docker
    Docker
    Docker
    Docker
    Docker
    Docker
    Docker
    Docker
    7 @caseywest

    View Slide

  8. The factors
    8 @caseywest

    View Slide

  9. 1: One codebase
    tracked in revision
    control, many deploys
    9 @caseywest

    View Slide

  10. Anti-pattern
    Building separate
    images for staging and
    production
    10 @caseywest

    View Slide

  11. Anti-pattern
    Tags for dev and prod
    11 @caseywest

    View Slide

  12. Best Practice
    Use the environment
    and/or feature flags
    12 @caseywest

    View Slide

  13. 2: Explicitly declare and
    isolate dependencies
    13 @caseywest

    View Slide

  14. 2: Explicitly declare and
    isolate dependencies
    14 @caseywest

    View Slide

  15. Anti-pattern
    latest
    15 @caseywest

    View Slide

  16. Best Practice
    Declare version
    numbers of upstream
    dependencies
    16 @caseywest

    View Slide

  17. Best Practice
    Depend on base images
    for default filesystem
    and runtimes
    17 @caseywest

    View Slide

  18. 3: Store config in the
    environment
    18 @caseywest

    View Slide

  19. Anti-pattern
    config.yml
    19 @caseywest

    View Slide

  20. Anti-pattern
    properties.xml
    20 @caseywest

    View Slide

  21. Anti-pattern
    Hard-coded feature
    flags
    21 @caseywest

    View Slide

  22. Best Practice
    This one is literally
    about environment
    variables
    22 @caseywest

    View Slide

  23. Best Practice
    This one is literally
    about environment
    variables ! ‑
    23 @caseywest

    View Slide

  24. 4: Treat backing
    services as attached
    resources
    24 @caseywest

    View Slide

  25. Anti-pattern
    No local disk
    25 @caseywest

    View Slide

  26. Anti-pattern
    No local disk
    26 @caseywest

    View Slide

  27. Anti-pattern
    No local disk
    27 @caseywest

    View Slide

  28. Best Practice
    Connect to network-
    attached services using
    connection info from
    the environment
    28 @caseywest

    View Slide

  29. 5: Strictly separate
    build and run stages
    29 @caseywest

    View Slide

  30. Anti-pattern
    Install on deploy
    30 @caseywest

    View Slide

  31. Best Practice
    Build immutable
    images then run those
    images
    31 @caseywest

    View Slide

  32. Painfully Obvious Best Practices
    Eat when hungry
    Sleep when tired
    Book Casey West for
    speaking gigs
    32 @caseywest

    View Slide

  33. Best Practice
    Respect the lifecycle:
    buid, run, destroy
    33 @caseywest

    View Slide

  34. 6: Execute the app as
    one or more stateless
    processes
    34 @caseywest

    View Slide

  35. Best Practice
    Schedule LRPs by
    distributing them
    across a cluster of
    physical hardware
    35 @caseywest

    View Slide

  36. Anti-pattern
    NFS
    36 @caseywest

    View Slide

  37. Anti-pattern
    NFS
    Need I say more?
    37 @caseywest

    View Slide

  38. 7: Export services via
    port binding
    38 @caseywest

    View Slide

  39. Best Practice
    port = Env.fetch(:port)
    39 @caseywest

    View Slide

  40. Best Practice
    my $port = $ENV{PORT};
    40 @caseywest

    View Slide

  41. Best Practice
    private String getPort() {
    Map env = System.getenv();
    return env.get("PORT");
    }
    41 @caseywest

    View Slide

  42. Best Practice
    let port = env::var("PORT").unwrap()
    42 @caseywest

    View Slide

  43. 8: Scale out via the
    process model
    43 @caseywest

    View Slide

  44. Best Practice
    Horizontally scale by
    adding instances
    44 @caseywest

    View Slide

  45. 9: Maximize robustness
    with fast startup and
    graceful shutdown
    45 @caseywest

    View Slide

  46. 10: Keep development,
    staging, and production
    as similar as possible
    46 @caseywest

    View Slide

  47. Best Practice
    Run containers in
    development
    47 @caseywest

    View Slide

  48. 11: Treat logs as event
    streams
    48 @caseywest

    View Slide

  49. Anti-pattern
    Random log files
    #yolo'd all over the file
    system
    49 @caseywest

    View Slide

  50. Anti-pattern
    Random log files
    #yolo'd all over the file
    system, bro
    50 @caseywest

    View Slide

  51. Best Practice
    STDOUT
    STDOUT
    STDOUT
    STDOUT
    51 @caseywest

    View Slide

  52. 12: Run admin/
    management tasks as
    one-off processes
    52 @caseywest

    View Slide

  53. Anti-pattern
    Custom containers for
    tasks
    53 @caseywest

    View Slide

  54. Best Practice
    Reuse application
    images with specific
    entrypoints for tasks
    54 @caseywest

    View Slide

  55. You are now cloud-native
    55 @caseywest

    View Slide

  56. Repeatability
    Reliability
    Resiliency
    56 @caseywest

    View Slide

  57. Thank you
    Questions?
    57 @caseywest

    View Slide

  58. @caseywest
    Let's be friends
    58 @caseywest

    View Slide