what are containers anyway? · 2020-03-11 · outline notanewtech thecontainermindset...

55
What are containers anyway? Maciej Pasternacki <[email protected]> Polish BSD User Group, 2018-10-11 @mpasternacki 3ofcoins

Upload: others

Post on 03-Aug-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

What are containers anyway?

Maciej Pasternacki <[email protected]>

Polish BSD User Group, 2018-10-11

@mpasternacki3ofcoins

Page 2: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

Outline

Not a New Tech

The Container Mindset

The Moving Parts

Page 3: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

Not a New Tech

Page 4: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

OS–level Virtualization

Single host kernel

Multiple guest userspaces

Page 5: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

Full VirtualisationHardware

Host HypervisorGuest OSUserspace

Guest OSUserspace

Guest OSUserspace

Page 6: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

OS–level VirtualisationHardwareHost OS

Host Userspace

GuestUserspace

GuestUserspace

GuestUserspace

Page 7: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

OS–level Virtualizationversus full virtualization

❧ Less isolation❧ Guest must have same OS as host1❧ Lower overhead❧ Adjustable isolation level❧ Resource sharing is possible

1or binary–compatible: Solaris branded zones, FreeBSDLinuxulator, CloudABI

Page 8: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

1982The Stone Age

chroot(2)CHROOT(2) FreeBSD System Calls Manual CHROOT(2)

NAMEchroot – change root directory

LIBRARYStandard C Library (libc, -lc)

SYNOPSIS#include <unistd.h>

intchroot(const char *dirname);

DESCRIPTIONThe dirname argument is the address of the pathname of a directory,terminated by an ASCII NUL. The chroot() system call causes dirname tobecome the root directory, that is, the starting point for path searchesof pathnames beginning with ‘/’.

Page 9: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

1998–2012The Industrial Age

2000 FreeBSD Jail2001 Linux–VServer, Virtuozzo2002 Linux namespaces2005 OpenVZ, Solaris Containers2008 Linux cgroups, LXC

Page 10: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

1998–2012The Industrial Age

❧ Isolated filesystem, process tree,networking

❧ Restricted interaction betweenenvironments

❧ Restricted administrative system calls❧ Resource usage limits

Page 11: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

VM MindsetGuest is a complete system:❧ managed from the inside❧ runs multiple services❧ long-running and mutable❧ opaque to host

Management overhead of a whole server

Page 12: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

2013Modern Age

Jan 2013 DockerOct 2013 lmctfy†

Dec 2014 App Container Specification,CoreOS Rocket

Jan 2015 Jetpack†

Page 13: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

2013Modern Age

❧ Inspired by PaaS, service–oriented❧ Guest managed from the outside❧ Immutable, distributable images❧ Fast copy–on–write provisioning

Page 14: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

2014–2015Standardization & Orchestration

Apr ’14 KubernetesDec ’14 Docker SwarmApr ’15 Google Borg paper1

Jun ’15 Open Container InitiativeJul ’15 Cloud Native Computing FoundationSep ’15 Hashicorp Nomad

1Mentions “operating Borg in production for more thana decade.”

Page 15: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

The Container Mindset

Page 16: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

Container MindsetOS–level virtualization plus:❧ Layered storage❧ Explicit interaction points❧ Immutable images, volatile containers❧ Service–oriented

Page 17: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

Layered StorageUbuntu LTS Image (RO)

Page 18: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

Layered StorageUbuntu LTS Image (RO)

Ruby-2.1.5 Redis server

Page 19: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

Layered StorageUbuntu LTS Image (RO)

Ruby-2.1.5 Redis server

Rails app

Page 20: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

Layered StorageUbuntu LTS Image (RO)

Ruby-2.1.5 Redis server

Rails app

Bob's AppContainer (R/W, volatile)

Page 21: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

Layered StorageUbuntu LTS Image (RO)

Ruby-2.1.5 Redis server

Rails app

Bob's AppContainer (R/W, volatile)

User Uploads

Volume (persistent)

Page 22: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

Layered StorageUbuntu LTS Image (RO)

Ruby-2.1.5 Redis server

Rails app

Bob's AppContainer (R/W, volatile)

User Uploads

Redis B

Persistence

Volume (persistent)

Page 23: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

Layered StorageUbuntu LTS Image (RO)

Ruby-2.1.5 Redis server

Rails app

Bob's AppContainer (R/W, volatile)

User Uploads

Redis B

PersistenceVolume (persistent)

Page 24: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

Layered StorageUbuntu LTS Image (RO)

Ruby-2.1.5 Redis server

Rails app

Bob's AppContainer (R/W, volatile)

User Uploads

Redis B

PersistenceVolume (persistent)

Alice's App

Redis AUser Uploads

Persistence

Page 25: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

Layered StorageUbuntu LTS Image (RO)

Ruby-2.1.5 Redis server

Rails app

Bob's AppContainer (R/W, volatile)

User Uploads

Redis B

PersistenceVolume (persistent)

Alice's App

Redis AUser Uploads

Persistence

Sinatra app

Claire's App

Redis C

Persistence

Page 26: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

Layered StorageUbuntu LTS Image (RO)

Ruby-2.1.5 Redis server

Rails app

Bob's AppContainer (R/W, volatile)

User Uploads

Redis B

PersistenceVolume (persistent)

Page 27: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

Layered StorageUbuntu LTS Image (RO)

Ruby-2.1.5 Redis server

Rails app

Bob's AppContainer (R/W, volatile)

User Uploads

Redis B

PersistenceVolume (persistent)

Bob's App 2

Page 28: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

Layered StorageUbuntu LTS Image (RO)

Ruby-2.1.5 Redis server

Rails app

Bob's AppContainer (R/W, volatile)

User Uploads

Redis B

PersistenceVolume (persistent)

Alice's App

Redis AUser Uploads

Persistence

Bob's App 2

Sinatra app

Claire's App

Redis C

Persistence

Page 29: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

Explicit Interaction Points❧ Command line arguments❧ Environment variables❧ Network ports❧ Persistent/shared volumes❧ Stdin, stdout, stderr❧ Exit status

Page 30: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

Immutability❧ Images, once built, are read-only

⇒ reusable; uniquely identified; verifiable

❧ Containers’ write layer is throwaway

⇒ exchangeable; upgradeable

❧ Volumes are persistent and shareable

⇒ precious user data is clearly declared

Page 31: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

Immutability❧ Images, once built, are read-only

⇒ reusable; uniquely identified; verifiable❧ Containers’ write layer is throwaway

⇒ exchangeable; upgradeable

❧ Volumes are persistent and shareable

⇒ precious user data is clearly declared

Page 32: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

Immutability❧ Images, once built, are read-only

⇒ reusable; uniquely identified; verifiable❧ Containers’ write layer is throwaway

⇒ exchangeable; upgradeable❧ Volumes are persistent and shareable

⇒ precious user data is clearly declared

Page 33: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

Immutability❧ Images, once built, are read-only

⇒ reusable; uniquely identified; verifiable❧ Containers’ write layer is throwaway

⇒ exchangeable; upgradeable❧ Volumes are persistent and shareable

⇒ precious user data is clearly declared

Page 34: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

Service–oriented❧ One container—one service❧ Well–defined images can be shared

& reused across applications❧ Containers can be meaningfully managed

& monitored by hostManagement overhead of a single service

Page 35: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

The Moving Parts

Page 36: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

Open Container InitiativeSpecify Critical Interfaces

❧ Runtime Specification+ runC , a reference implementation

❧ Image Format Specification❧ Distribution Specification

https://github.com/opencontainers/

Page 37: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

OCI Runtime SpecConfiguration

❧ filesystem: root fs path, mounts, devices❧ process: command+args, cwd,

environment, uid+gids❧ isolation: namespaces, rlimits, apparmor,

capabilities, cgroups❧ hostname❧ hookshttps://github.com/opencontainers/runtime-spec

Page 38: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

OCI Runtime SpecRuntime Operations

❧ state ID — query state❧ create ID PATH_TO_BUNDLE❧ start ID❧ kill ID SIGNAL❧ delete ID

https://github.com/opencontainers/runtime-spec

Page 39: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

OCI Runtime SpecImplementations

General: opencontainers/runc (Go)⇒ The reference implementation

oracle/railcar (Rust) giuseppe/crun (C)

Page 40: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

OCI Runtime SpecImplementations

Hypervisor–based: hyperhq/runv⇒ KVM, Xen

clearcontainers/runtime⇒ Intel VT–x kata-containers/runtime⇒ Intel VT-x, ARM Hyp, IBM Power Systems;combines ideas from runV & clearcontainers

Page 41: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

OCI Runtime SpecImplementations

Security–focused: google/gvisor (Go)⇒ Intercepts system calls and acts as guest’skernel in the userspace.

Page 42: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

OCI Runtime SpecImplementations

Wrappers:NVIDIA/nvidia-container-runtime⇒ runC, patched to allow GPU access for guest

projectatomic/bwrap-oci⇒ C, uses Bubblewrap as sandbox

Page 43: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

OCI Image SpecImage Layout

Content–addressable blobs:blobs/sha256/afff…2d51

Referenced by content descriptors:❧ Media type❧ Digest (e.g. sha256:afff…2d51)❧ Size❧ Optional URLs

https://github.com/opencontainers/image-spec/

Page 44: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

OCI Image SpecImage Layout

❧ Index (JSON) points to manifest blobs❧ Manifest (JSON) points to layer blobs

and a configuration blob❧ Layers are tar files with filesystem

contents❧ Configuration (JSON) is metadata and

base configuration for runtime bundle

https://github.com/opencontainers/image-spec/

Page 45: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

OCI Image SpecImplementations

projectatomic/skopeo openSUSE/umoci cloudfoundry/grootfs containerd/containerd containers/image, containers/build coreos/rkt– Amazon Elastic Container Registry

https://github.com/opencontainers/image-spec/

Page 46: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

OCI Distribution SpecAPI protocol for distribution of images

❧ Based on Docker Registry HTTP API V2❧ Namespace–oriented URI layout❧ Image verification❧ Resumable push & pull❧ Layer deduplication

Seems to be WIP.

https://github.com/opencontainers/distribution-spec

Page 47: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

Containerd❧ High–level runtime (image push/pull,

storage, etc) on top of OCI runtime❧ Exposes gRPC API❧ CNCF member project

https://github.com/containerd/containerd

Page 48: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

Containerd

https://github.com/containerd/containerd

Page 49: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

Docker Architecture

https://blog.docker.com/2016/04/docker-engine-1-11-runc/

Page 50: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

Kubernetes & CRIContainer Runtime Interface

Kubernetes’ gRPC API for runtime plugins:❧ dockershim

(kubelet → dockershim →docker → containerd → OCI runtime)

❧ containerd/cri

(calls containerd directly)

❧ kubernetes-incubator/rktlet

(calls rocket)

❧ kubernetes-sigs/cri-o

(Made forKubernetes, manages everything anddirectly calls OCI runtime)

Page 51: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

Kubernetes & CRIContainer Runtime Interface

Kubernetes’ gRPC API for runtime plugins:❧ dockershim (kubelet → dockershim →

docker → containerd → OCI runtime)❧ containerd/cri

(calls containerd directly)

❧ kubernetes-incubator/rktlet

(calls rocket)

❧ kubernetes-sigs/cri-o

(Made forKubernetes, manages everything anddirectly calls OCI runtime)

Page 52: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

Kubernetes & CRIContainer Runtime Interface

Kubernetes’ gRPC API for runtime plugins:❧ dockershim (kubelet → dockershim →

docker → containerd → OCI runtime)❧ containerd/cri (calls containerd directly)❧ kubernetes-incubator/rktlet

(calls rocket)

❧ kubernetes-sigs/cri-o

(Made forKubernetes, manages everything anddirectly calls OCI runtime)

Page 53: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

Kubernetes & CRIContainer Runtime Interface

Kubernetes’ gRPC API for runtime plugins:❧ dockershim (kubelet → dockershim →

docker → containerd → OCI runtime)❧ containerd/cri (calls containerd directly)❧ kubernetes-incubator/rktlet (calls rocket)❧ kubernetes-sigs/cri-o

(Made forKubernetes, manages everything anddirectly calls OCI runtime)

Page 54: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

Kubernetes & CRIContainer Runtime Interface

Kubernetes’ gRPC API for runtime plugins:❧ dockershim (kubelet → dockershim →

docker → containerd → OCI runtime)❧ containerd/cri (calls containerd directly)❧ kubernetes-incubator/rktlet (calls rocket)❧ kubernetes-sigs/cri-o (Made for

Kubernetes, manages everything anddirectly calls OCI runtime)

Page 55: What are containers anyway? · 2020-03-11 · Outline NotaNewTech TheContainerMindset TheMovingParts. NotaNewTech. OS–levelVirtualization Singlehostkernel ... 2008 Linuxcgroups,LXC

DIY Container Environment❧ OCI Runtime (any)❧ containers/storage❧ projectatomic/skopeo /

containers/image❧ openSUSE/umoci❧ containernetworking/cni +

containernetworking/plugins❧ projectatomic/buildah❧ A bit of duct tape