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

Containers outside Containers

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →
Avatar for Tiago Scolari Tiago Scolari
November 07, 2016

Containers outside Containers

Lightning talk about techniques containers use but that could be used outside a container's context.

There is a missing video demo that didn't worked out when importing the slides. You can check it out here: https://www.youtube.com/watch?v=EQbc2CPgMbU

Avatar for Tiago Scolari

Tiago Scolari

November 07, 2016

Other Decks in Technology

Transcript

  1. WHAT MAKES A CONTAINER A CONTAINER? CGROUPS “cgroups is a

    Linux kernel feature that limits, accounts for, and isolates the resource usage (CPU, memory, disk I/O, network, etc.) of a collection of processes.” NAMESPACES “Namespaces are a feature of the Linux kernel that isolates and virtualizes system resources of a collection of processes. Examples of resources that can be virtualized include process IDs, hostnames, user IDs, network access, interprocess communication, and filesystems.”
  2. Each subsystem limits things in one topic: • cpu -

    uses the scheduler to provide cgroup tasks access to the CPU • cpuset - assigns individual CPUs and memory nodes to tasks in a cgroup • memory - sets limits on memory use by tasks in a cgroup • blkio - sets limits on input/output access to and from block devices • devices - allows or denies access to devices by tasks in a cgroup • ... SUBSYSTEMS
  3. Each subsystem limits things in one topic: • /sys/fs/cgroup/cpu •

    /sys/fs/cgroup/cpuset • /sys/fs/cgroup/memory • /sys/fs/cgroup/devices • /sys/fs/cgroup/blkio • ... SUBSYSTEMS
  4. ANATOMY OF A SUBSYSTEM ( ls cgroup/memory ) cgroup.clone_children cgroup.sane_behavior

    memory.kmem.failcnt memory.kmem.slabinfo memory.kmem.tcp.max_usage_in_bytes memory.limit_in_bytes memory.memsw.limit_in_bytes memory.move_charge_at_immigrate memory.soft_limit_in_bytes memory.usage_in_bytes release_agent cgroup.event_control memory.failcnt memory.kmem.limit_in_bytes memory.kmem.tcp.failcnt memory.kmem.tcp.usage_in_bytes memory.max_usage_in_bytes memory.max_usage_in_bytes memory.memsw.max_usage_in_bytes memory.oom_control memory.stat memory.use_hierarchy tasks cgroup.procs memory.force_empty memory.kmem.max_usage_in_bytes memory.kmem.tcp.limit_in_bytes memory.kmem.usage_in_bytes memory.memsw.failcnt memory.memsw.usage_in_bytes memory.pressure_level memory.swappiness notify_on_release
  5. ./cgroup.procs List of pids belonging to this cgroup. EVERYTHING IS

    A FILE Write to the files to set values to limits ./<directory> Creates a subgroup in the group. Inherits parent’s files when not specified.
  6. One process (PID) may belong to more than one cgroup

    NOTES Everything is done at PID level
  7. E.G. 1: Limit <APP> memory IN 10Mb # create a

    group mkdir /sys/fs/cgroup/memory/my-example # add the app to the new created group echo “<app-pid>” >> /sys/fs/cgroup/memory/my-example/cgroup.procs # add a limit to the group echo “10M” > /sys/fs/cgroup/memory/my-example/memory.limit_in_bytes
  8. # show current usage for memory cat /../memory/my-example/memory.usage_in_bytes => 7036928

    # show the number of memory usage hits limits cat /../memory/my-example/memory.failcnt => 0 # show max memory usage recordedits cat /../memory/my-example/memory.max_usage_in_bytes => 7716864 E.g. 2: READ STATISTICS FOR <APP> FROM MEM CGROUP
  9. ... memory.memsw.usage_in_bytes # show current usage for memory+Swap memory.failcnt #

    show the number of memory usage hits limits memory.memsw.failcnt # show the number of memory+Swap hits limits memory.max_usage_in_bytes # show max memory usage recorded memory.memsw.max_usage_in_bytes # show max memory+Swap usage recorded memory.soft_limit_in_bytes # set/show soft limit of memory usage memory.stat # show various statistics memory.kmem.limit_in_bytes # set/show hard limit for kernel memory memory.kmem.usage_in_bytes # show current kernel memory allocation memory.kmem.max_usage_in_bytes # show max kernel memory usage recorded memory.kmem.failcnt # show the number of kernel memory usage hits limits ... AVAILABLE METRICS FOR MEMORY