Linux Conf Australia 2016 - The Twelve-Factor Container

1ed0b822068d34032bca7d2beeb2f846?s=47 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.

1ed0b822068d34032bca7d2beeb2f846?s=128

Casey West

February 01, 2016
Tweet

Transcript

  1. The Twelve-Factor Container • Twitter @caseywest • Email casey@geeknest.com •

    Web http://caseywest.com • Days since I last used that joke zero 1 @caseywest
  2. Thanks a lot, Pivotal 2 @caseywest

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

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

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

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

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

  8. The factors 8 @caseywest

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

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

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

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

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

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

  15. Anti-pattern latest 15 @caseywest

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

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

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

  19. Anti-pattern config.yml 19 @caseywest

  20. Anti-pattern properties.xml 20 @caseywest

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

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

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

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

  25. Anti-pattern No local disk 25 @caseywest

  26. Anti-pattern No local disk 26 @caseywest

  27. Anti-pattern No local disk 27 @caseywest

  28. Best Practice Connect to network- attached services using connection info

    from the environment 28 @caseywest
  29. 5: Strictly separate build and run stages 29 @caseywest

  30. Anti-pattern Install on deploy 30 @caseywest

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

    @caseywest
  32. Painfully Obvious Best Practices Eat when hungry Sleep when tired

    Book Casey West for speaking gigs 32 @caseywest
  33. Best Practice Respect the lifecycle: buid, run, destroy 33 @caseywest

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

    34 @caseywest
  35. Best Practice Schedule LRPs by distributing them across a cluster

    of physical hardware 35 @caseywest
  36. Anti-pattern NFS 36 @caseywest

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

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

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

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

  41. Best Practice private String getPort() { Map<String, String> env =

    System.getenv(); return env.get("PORT"); } 41 @caseywest
  42. Best Practice let port = env::var("PORT").unwrap() 42 @caseywest

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

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

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

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

    46 @caseywest
  47. Best Practice Run containers in development 47 @caseywest

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

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

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

    bro 50 @caseywest
  51. Best Practice STDOUT STDOUT STDOUT STDOUT 51 @caseywest

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

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

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

    54 @caseywest
  55. You are now cloud-native 55 @caseywest

  56. Repeatability Reliability Resiliency 56 @caseywest

  57. Thank you Questions? 57 @caseywest

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