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

Building hybrid microservices

Building hybrid microservices

Building hybrid microservices with Docker, Apache Mesos/Marathon & Kubernetes. Talk at Day of Docker, Oslo, see also http://www.code-conf.com/day-of-docker-osl15/program/#microservices

Michael Hausenblas

December 01, 2015
Tweet

More Decks by Michael Hausenblas

Other Decks in Technology

Transcript

  1. © 2015 Mesosphere, Inc. All Rights Reserved. BUILDING HYBRID MICROSERVICES


    WITH DOCKER,
 APACHE MESOS/MARATHON & KUBERNETES 2 Day of Docker | Oslo | 2015-12-01
  2. © 2015 Mesosphere, Inc. All Rights Reserved. AGENDA 3 1.

    Background (30 min) 2. Hands-on (50 min) 3. Wrap up and Q & A (25 min)
  3. © 2015 Mesosphere, Inc. All Rights Reserved. LINUX
 CONTAINERS 6

    The why and the what • Containers vs VMs • app-level dependency management • lightweight (startup time, footprint, average runtime) • security considerations • pets vs cattle (and flock of birds)
  4. © 2015 Mesosphere, Inc. All Rights Reserved. LINUX
 CONTAINERS 7

    • namespaces • Isolate PIDs between processes • Isolate network resources (stacks, devices, etc.) • Isolate hostname/NIS (UTS) • Isolate filesystem mount (chroot) • Isolate inter process communication (IPC) • Isolate users/groups • cgroups
 https://sysadmincasts.com/episodes/14-introduction-to-linux-control-groups-cgroups
  5. © 2015 Mesosphere, Inc. All Rights Reserved. DOCKER 9 Registries

    • Docker Hub
 https://hub.docker.com/ • Google Cloud
 https://cloud.google.com/tools/container-registry/ • AWS
 https://aws.amazon.com/ecr/ • Run your own
 https://docs.docker.com/registry/deploying/
  6. © 2015 Mesosphere, Inc. All Rights Reserved. ARE CONTAINERS SECURE?

    11 • containers share same kernel (!) • namespaces (user NS: UID 0 recently introduced) • lock down networking (ICC, for example) • apply common sense when handling credentials
  7. © 2015 Mesosphere, Inc. All Rights Reserved. ARE CONTAINERS SECURE?

    12 Please, don't bake credentials into images … rather do: $ docker run -d -e API_TOKEN=SECRET somedatabase $ docker run -d -v $(pwd):/fsecret:/fsecret:ro somedatabase → even better: use a key-value in-memory store such as Square's KeyWhiz, HashiCorp's Vault, or Crypt or native solutions such as Kubernetes Secrets for credentials.
  8. © 2015 Mesosphere, Inc. All Rights Reserved. PETS VS CATTLE

    13 Pets are individuals that you give names and when they get ill you nurse them back to health. Cattle are anonymous, identical to other cattle you assign numbers and when they get ill → next one. http://www.theregister.co.uk/2013/03/18/servers_pets_or_cattle_cern/
  9. © 2015 Mesosphere, Inc. All Rights Reserved. … AND FLOCK

    OF BIRDS 14 https://medium.com/@mhausenblas/pets-vs-cattle-vs-flock-of-birds-12f1da3abfc3 Flock of birds. Per-task computing: unit of compute is a function + dynamically allocated resources. • AWS Lambda • webtask.io • StackHut
  10. © 2015 Mesosphere, Inc. All Rights Reserved. A WORD ON

    MICROSERVICES
 AND CONTAINERS 15
  11. © 2015 Mesosphere, Inc. All Rights Reserved. WORKLOADS* … 16

    *) kudos to Timothy St. Clair, @timothysc batch streaming PaaS MapReduce
  12. © 2015 Mesosphere, Inc. All Rights Reserved. 22 Kubernetes, Mesos+Marathon,

    Nomad, etc. >>
 write your own container manager >>
 manually managing containers http://www.cloudtp.com/2015/11/30/docker-container-landscape/
  13. © 2015 Mesosphere, Inc. All Rights Reserved. • A top-level

    ASF project • A cluster resource negotiator • Scalable to 10,000s of nodes but also useful for a handful of nodes • Fault-tolerant, battle-tested • An SDK for distributed apps • Native Docker support 23 Apache Mesos
  14. © 2015 Mesosphere, Inc. All Rights Reserved. ARCHITECTURE 24 Mesos

    http://mesos.berkeley.edu/mesos_tech_report.pdf *) now: agent *
  15. © 2015 Mesosphere, Inc. All Rights Reserved. RESOURCES 25 Mesos

    • resource == anything a task/executor consumes in order to do their work • standard resources: cpu, mem, disk, ports • DRF
  16. © 2015 Mesosphere, Inc. All Rights Reserved. MARATHON 42 An

    init System for datacenters • starts instances of a long-running service somewhere in the cluster, for example, as
 Docker containers • restarts the instances if they crash • provides composition primitives • supports health checks • supports rolling upgrades
  17. © 2015 Mesosphere, Inc. All Rights Reserved. MARATHON 43 {

    "id": "webserver", "cmd": "python3 -m http.server 8080", "cpus": 0.5, "mem": 32.0, "container": { "type": "DOCKER", "docker": { "image": "python:3", "network": "BRIDGE", "portMappings": [ { "containerPort": 8080, "hostPort": 0 } ] } }, "acceptedResourceRoles": [ "slave_public" ], "constraints": [ [ "hostname", "UNIQUE" ] ] }
  18. © 2015 Mesosphere, Inc. All Rights Reserved. WHAT IS KUBERNETES?

    44 • open source container orchestration system • scheduling apps onto nodes + scaling • manages apps to match declared intentions • based on Google's internal cluster managers such as Borg
  19. © 2015 Mesosphere, Inc. All Rights Reserved. KUBERNETES CONCEPTS 46

    • container—sealed application package (Docker) • pod—small group of tightly coupled containers • labels—identifying metadata attached to objects (pods, services, etc.) • selector—query against labels, producing a set result • controller—control loop driving current state towards desired state • service—set of pods that work together (incl. proxy/load balancer)
  20. © 2015 Mesosphere, Inc. All Rights Reserved. KUBERNETES: PODS 47

    • unit of scheduling • data sharing between its containers • shared mount point (volumes) • shared network namespace (same IP, see each other on localhost)
  21. © 2015 Mesosphere, Inc. All Rights Reserved. KUBERNETES: LABELS &

    SELECTORS 48 • arbitrary metadata (in key-value format) attached to any API object • used for grouping, queryable by selectors • examples • pods managed by a replication controller • nodes capabilities for scheduling
  22. © 2015 Mesosphere, Inc. All Rights Reserved. KUBERNETES: REPLICATION CONTROLLERS

    49 • constitutes a control loop • ensures a desired state (x pods running) • scoped by selector
  23. © 2015 Mesosphere, Inc. All Rights Reserved. KUBERNETES: SERVICES 50

    • compensate for dynamics of pods • provides a stable VIP (through proxy) • access policy: load-balanced or headless
  24. © 2015 Mesosphere, Inc. All Rights Reserved. KUBERNETES: CLUSTER-WIDE SERVICES

    51 • monitoring (e.g.: cAdvisor + InfluxDB + Heapster) • logging (e.g.: fluentd + ES + Kibana) • DNS (e.g.: skydns + kube2sky) • all of the above can be replaced by custom solutions (GCP, AWS, etc.)
  25. © 2015 Mesosphere, Inc. All Rights Reserved. LOCAL OS VS.

    DISTRIBUTED OS 53 http://bitly.com/os-vs-dcos
  26. © 2015 Mesosphere, Inc. All Rights Reserved. MEET THE DATACENTER

    OPERATING SYSTEM 54 Any Service or Container Any Infrastructure Mesosphere DCOS Your favorite services, container formats, and those yet to come Build apps once on DCOS, and run it anywhere Runs distributed apps anywhere 
 as simply as running apps on your laptop
  27. © 2015 Mesosphere, Inc. All Rights Reserved. DCOS BENEFITS 55

    • Run stateless services such as Web servers, app servers (via Marathon) and stateful services like Crate, Kafka, HDFS, Cassandra, ArangoDB etc. together on one cluster • Dynamic partitioning of your cluster, depending on your needs (business requirements) • Increased utilization (10% → 80% an more)
  28. © 2015 Mesosphere, Inc. All Rights Reserved. DCOS ARCHITECTURE 56

    https://docs.mesosphere.com/getting-started/dcosarchitecture/
  29. © 2015 Mesosphere, Inc. All Rights Reserved. LOOK MA, I

    FIXED SLACK … 60 mattermost.org DCOS
  30. © 2015 Mesosphere, Inc. All Rights Reserved. 61 A SOMEWHAT

    MORE COMPLETE EXAMPLE mesosphere.com/blog/2015/11/18/dcos-time-series-demo/
  31. © 2015 Mesosphere, Inc. All Rights Reserved. 64 WHERE CAN


    I LEARN MORE? http://shop.oreilly.com/product/9781939902184.do 64 http://shop.oreilly.com/product/0636920035671.do
  32. © 2015 Mesosphere, Inc. All Rights Reserved. 65 WHERE CAN


    I LEARN MORE? http://shop.oreilly.com/product/0636920039952.do https://manning.com/books/mesos-in-action 65
  33. © 2015 Mesosphere, Inc. All Rights Reserved. 66 WHERE CAN


    I LEARN MORE? 66 http://shop.oreilly.com/product/0636920043874.do http://www.oreilly.com/webops-perf/free/kubernetes.csp http://mhausenblas.info/dnsd/toc.pdf
  34. © 2015 Mesosphere, Inc. All Rights Reserved. 67 WHERE CAN


    I LEARN MORE? http://p24e.io 67 http://k8s.info