Anzeige

Container Patterns

Product Manager um Instana
8. Mar 2016
Anzeige

Más contenido relacionado

Similar a Container Patterns(20)

Anzeige
Anzeige

Container Patterns

  1. Matthias Lübken Container Patterns
  2. @luebken
  3. “ Easily create lightweight, portable, self-sufficient containers from any application.”
  4. “App Container (appc) is a well-specified and community developed specification for application containers. ”
  5. nginx Proxy Rails Frontend A Go Backend A Node Backend An Application
  6. Reuse
  7. How does a good building block look like? How do we assemble them?
  8. Related Work • 12factor.net apps • Cloud-native application architectures: Matt Stine Free Ebook • Microservices • Continuous Delivery
  9. Container Patterns •For designing “cloud” applications. •Container runtime agnostic. •Are there general applicable patterns? •How would we describe them? •What are concrete examples and best-practices?
  10. github.com/luebken/container-patterns
  11. How does a good building block look like? How do we assemble them?
  12. “Module-Container”
  13. A “Module-Container” is a well behaving building block in the architecture of an application.
  14. A Module Container is 1. Linux process 2. API 3. Descriptive 4. Disposable 5. Immutable 6. Self-contained 7. Small
  15. 1.Linux Process
  16. 1. Linux Process • React to signals • Return exit codes • Use standard streams • Handle arguments Examples: module-container.md#1-linux-process
  17. 2. API
  18. 2. API • ENV variables • Available ports • Volume mounts • Lifecycle hooks Examples: module-container.md#2-api
  19. 3. Descriptive
  20. 3. Descriptive • Use standard labels (e.g. proposal generic labels) • url, summary, vcs-url … • Use custom labels: • api.ENV • api.EXPOSE • api.LINKS Examples: module-container.md#3-descriptive
  21. POC github.com/luebken/container-api
  22. 4. Disposable
  23. 4. Disposable • Don’t rely on a particular instance • Be aware of shots at your cattle • Be robust against sudden death Examples: module-container.md#4-disposable
  24. 5. Immutable
  25. 5. Immutable • Don’t change your container after build • Strive or a dev/prod parity Examples: module-container.md#5-immutable
  26. 6. Self-contained
  27. 6. Self-contained • Add dependencies on build time • Sensible defaults Examples: module-container.md#6-self-contained
  28. 7. Small
  29. 7. Small • Don’t use large base images • Use the minimal footprint e.g. Alpine Examples: module-container.md#6-small
  30. Recap: A Module Container is 1. Linux process 2. API 3. Descriptive 4. Disposable 5. Immutable 6. Self-contained 7. Small
  31. How does a good building block look like? How do we assemble them?
  32. nginx Proxy Rails Frontend A Go Backend A Node Backend
  33. nginx Proxy Rails Frontend A Go Backend A Node Backend Redis Cache Logging Adapter Service Ambassador
  34. A group of closely related containers. Deployed as a single unit and share namespaces.
  35. A Node Backend Redis Cache Logging Adapter Service Ambassador
  36. Pattern: Sidecar / Sidekick Enhance & extend the main container. K8S: transparently. Netflix: platform features. UDSA Node Backend MAIN CONTAINER Redis Cache SIDECAR Pod
  37. A Node Backend Redis Cache Logging Adapter Service Ambassador
  38. Pattern: Adapter Standardise and normalize output. E.g. logging and metrics. localhost or A Node Backend MAIN CONTAINER Logging Adapter ADAPTER Pod
  39. A Node Backend Redis Cache Logging Adapter Service Ambassador
  40. Proxy a local connection to the world: Service Discovery, Client Side LB, Circuit Breaker A Node Backend MAIN CONTAINER Service Discovery AMBASSADOR Pattern: Ambassador localhost (Pod)
  41. Pattern: Container chains Defined order of starting and stopping sidecar containers. A Node Backend MAIN CONTAINER Storage Config SIDECAR Discovery SIDECAR Network Config SIDECAR (Pod)
  42. Summary: Container Patterns QCON 08.03.2016 Module container 1. Linux process 2. API 3. Descriptive 4. Disposable 5. Immutable 6. Self-contained 7. Small Composite • Sidecar • Adapter • Ambassador • Chains How does a good building block look like? And how would you assemble them? github.com/luebken/container-patterns @luebken
  43. matthias@luebken.com Dankeschön. @luebken
  44. Credits • https://www.flickr.com/photos/skynoir/8241460998 (Cover image) • https://www.flickr.com/photos/amlz/8664728590 (Lego) • https://www.flickr.com/photos/guidedbycthulhu/6810361241 (Socket) • https://www.flickr.com/photos/seektan/2074853585/ (Label) • https://www.flickr.com/photos/gullevek/2122873934 (Trash) • https://www.flickr.com/photos/grantmac/4852826923 (Lock) • https://www.flickr.com/photos/mhirano/13236048424 (Hand)

Hinweis der Redaktion

  1. About me developer: OSGi, {team, group, department} lead product guy Slides and code examples will be available online
  2. Docker introduced the term “application container”. Containers are not just a lightweight VM.
  3. Others have incorporated that term like the appc standard.
  4. An application usually consists of multiple containers. How would I design my containers that they well behave in my application?
  5. Let’s take a close look the building blocks. What color, size? Kind of connectors? Reasons for having multiple building blocks.
  6. These are the questions we should ask ourselves when designing and developing applications with containers.
  7. There is a lot related work / prior art: Modules, Distributed systems, Continuos integration See especially cloud native / paas experience.
  8. We need to remember that a container is foremost a Linux process. Which is separated by namespaces and controlled by cgroups.
  9. React to signals Use the `exec` form Catch signals: SIGINT: Interrupt by Ctrl-C, SIGTERM: Process termination by schedular like `docker stop` Return exit codes: `0` for successful termination, `>0` for a failure Handle arguments: Use conventions like POSIX or a library Use standard streams Use standard out for logging let the infrastructure (or sidecar) handle the forwarding
  10. env usage was proposed by 12Factor easy to change between deploys, no danger go checking in set default in image and let user overwrite with `docker -e` use simple tools like `envtpl` https://github.com/andreasjansson/envtpl ports: use `EXPOSE` they will show up in `docker ps` and `docker inspect` can be enforced with `iptables = true` && `icc = false volume mounts different patterns depend on this like data-container hooks sometimes the container lifecycle is not enough. e.g. database init kubernetes and runc have them. you can build them with docker events
  11. TODO: schema for labels
  12. start with `docker — rm` many reasons for a container instance going away Rescheduling because of limit or bad resources Down-scaling Errors within the container Migration to new hardware / locality of services Be robust against sudden death. Minimal setup Counter argument: OPs argues they want to keep as much as possible after a crash TODO what does kubernetes do with logs Pets vs. Cattle: Treat your container as part of a cattle. You number them and when get sick you shoot them Note: Most argued slide so far.
  13. dev / prod parity extract runtime state in volumes Anti-pattern: `docker exec`
  14. E.g. Build Uber-Jar and include webserver Generate dynamic config files on the fly.: confd
  15. Build from scratch Use small base-image busybox, alpine Reuse custom base image Anti-Pattern: VM Container
  16. You can hook up containers just as ordinary services. Let’s look into something special with containers.
  17. Hands up: Who knows Docker? Who knows Pods? Pods: Kubernetes and rkt. (Docker working on something?) Share all available namespaces Network, IPC, UTS (hostname), Volumes, PID The pod as a whole can be limited or the individual container.
  18. A general pattern about adding functionality for the main container Netflix: coined the term for adding platform features Burns: uses examples with transparent sidecars
  19. Special purpose side-car Full-fill a contract to the outside e.g.Present a consistent interface for a monitoring system
  20. All connections are proxied by the Ambassadors Resolves endpoint and establish connections More logic like client-side load balancing circuit breakers Pods optional: depend on the implementation Coined by Docker implemented using Docker links Next brought to a wider audience by CoreOS using etcd Nowadays seen many times using Consul
  21. starting all containers at once will end in chaos (e.g. storage not being ready for example) some things have to wait on each other (e.g. discovery needs network access) shutdowns also have order (e.g. de-register a consul node before the node backend shuts down & finish open requests) an error in one of the process will result in a restart of the whole chain Implementation Basically we are talking about requirements for an init process with systemd with attributes e.g. “Requires=” and “After=” But also custom implementations (e.g. a Golang binary taking care of this) // Wandering how this could be implemented with Kubernetes The example: Storage: ensure that the volume data that the container requires is available Network: setup network for custom networks like weave or shared network between user pods Main Container: Well, thats your business service, man! Discovery: Announce the world that your business is running! So other services can use it. Note: Pods are fro many use-cases optional. Most containers shown here do need to run as a group (start together, die together), but not necessarily run in the same cgroups/namespaces etc.
Anzeige