1 of 20

Docker, Kubernetes & OpenShift

Build, containerize & orchestrate

Marko Lukša, Red Hat

mluksa@redhat.com

2 of 20

Docker

  • Platform for building, distributing and running applications
  • Lightweight container virtualization
  • 10s of VMs => 100s, 1000s of containers per host

3 of 20

Docker concepts

  • Images
    • A read-only package of an app & environment
    • Consists of Layers (some layers shared by images)
  • Registries
    • Pull images from & push images to registry
    • Private & public registries (Docker Hub)
  • Containers
    • A running image (“Process in a box”)
    • Read-Write layer on top of base image

4 of 20

Docker layers

5 of 20

Creating Docker images

  • Use existing image (e.g. fedora, jboss/wildfly)
  • Run a command (anything, even a shell)
    • Docker creates a new container from image
    • Allocates a read-write layer on top of image
    • Executes the command
  • Run additional commands
  • Look up last container id
  • Commit the container as new image

6 of 20

Dockerfile

  • Build an image automagically
  • Specifies base image and instructions:
    • FROM <existing image>
    • ADD <local file> <path inside image>
    • RUN <cmd>
    • EXPOSE <port>
    • ENV <name> <value>
    • CMD <cmd>

7 of 20

Dockerfile - example

# Use latest jboss/base-jdk:7 image as the baseFROM jboss/base-jdk:7��# Set the WILDFLY_VERSION env variableENV WILDFLY_VERSION 8.1.0.Final��# Add the WildFly distribution to /optRUN cd $HOME && curl http://download.jboss.org/wildfly/$WILDFLY_VERSION/wildfly-$WILDFLY_VERSION.tar.gz | tar zx && mv $HOME/wildfly-$WILDFLY_VERSION $HOME/wildfly��# Set the JBOSS_HOME env variableENV JBOSS_HOME /opt/jboss/wildfly��# Expose the ports we're interested inEXPOSE 8080 9990��# Set the default command to run on bootCMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0"]

8 of 20

Kubernetes

  • Orchestration system for Docker containers
  • Provides basic mechanisms for:
    • deployment
    • maintenance
    • scaling
  • Auto-restarting, re-scheduling & replicating containers

9 of 20

Kubernetes architecture

  • Master node
    • etcd (distributed key value store)
    • Kubernetes API Server (REST) (+ Scheduler)
    • Kubernetes Controller Manager Server
  • Minions
    • Docker
    • Kubelet
    • Kubernetes Proxy

10 of 20

Kubernetes concepts

  • Pods
  • Volumes
  • Labels
  • Replication controllers
  • Services

11 of 20

Pods

apiVersion: v1beta1

id: www

desiredState:

manifest:

version: v1beta1

id: X

containers:

- name: nginx

image: dockerfile/nginx

- name: mydb

image: foo/mycooldb

Minion (Host) 1

A

Pod X

B

12 of 20

Pods (continued)

  • Resource sharing & communication
  • Not fully isolated
  • Scheduled to a node
  • Containers are auto-restarted
  • If a node dies, its pods are deleted (not rescheduled)

Minion (Host) 1

A

Pod X

B

13 of 20

Volumes

desiredState: manifest:

containers:

- name: A

image: foo/A

volumeMounts:

- name: vol1

mountPath: /data/vol1

volumes:

- name: vol1

source:

emptyDir: {}

Or:

hostDir: /opt/data/vol1

Minion (Host) 1

A

Pod X

B

Vol 1

14 of 20

Labels

  • key-value pairs
  • for categorizing things

“env”:”dev”, “env”:”prod”, “env”:”qa”

“rel”:”stable”, “rel”:”canary”

“partition”:”custA”, “partition”:”custB”

  • label selectors

Minion (Host) 1

A

Pod X

B

Vol 1

“name”: “podX”,

“env”: “dev”

15 of 20

Replication controllers

id: replicationControllerY

kind: ReplicationController

desiredState:

replicas: 2

replicaSelector:

env: prod

rel: stable

podTemplate:

desiredState:

manifest:

...

labels:

- env: prod

- rel: stable

Minion (Host) 1

A

Pod X

Minion 2

Replication controller Y

(replicas: 2, podTemplate, replicaSelector: {“env”:”prod”, “rel”:”stable”})

B

Vol 1

“name”: “podX”,

“env”: “dev”

C

D

Pod Y1

“env”: “prod”,

“rel”: “stable”

C

D

Pod Y2

“env”: “prod”,

“rel”: “stable”

16 of 20

Services

id: myApp

kind: Service

apiVersion: v1beta1

port: 1234

selector:

env: prod

containerPort: 2345

  • Env vars: MYAPP_SERVICE_HOST, MYAPP_SERVICE_PORT
  • future: DNS

Minion (Host) 1

A

Pod X

Minion 2

Replication controller Y

(replicas: 2, podTemplate, replicaSelector: {“env”:”prod”, “rel”:”stable”})

B

Vol 1

“name”: “podX”,

“env”: “dev”

C

D

Pod Y1

“env”: “prod”,

“rel”: “stable”

C

D

Pod Y2

“env”: “prod”,

“rel”: “stable”

myApp (selector: {env:prod})

17 of 20

Phased rollout / canary releases

  • New replication controller (rel:canary)
  • stable controller: replicas--
  • canary controller:�replicas++

Minion (Host) 1

A

Pod X

Minion 2

Replication controller Y

(replicas: 1, podTemplate, replicaSelector: {“env”:”prod”, “rel”:”stable”})

B

Vol 1

“name”: “podX”,

“env”: “dev”

Replication controller Y’ (replicas: 1, podTemplate, replicaSelector: {“env”:”prod”, “rel”:”canary”})

C

D

Pod Y1

“env”: “prod”,

“rel”: “stable”

myApp (selector: {env:prod})

“env”: “prod”,

“rel”: “stable”

C

D

Pod Y2

C’

D’

Pod Y’1

“env”: “prod”,

“rel”: “canary”

18 of 20

Remove/debug malfunctioning pod

  • labels of a running pod can be changed
  • way of adding or removing pods from services or replication controllers

Minion (Host) 1

A

Pod X

Minion 2

Replication controller Y

(replicas: 2, podTemplate, replicaSelector: {“env”:”prod”, “rel”:”stable”})

B

Vol 1

“name”: “podX”,

“env”: “dev”

C

D

Pod Y1

“env”: “prod”,

“rel”: “stable”

myApp (selector: {env:prod})

“env”: “prod”,

“rel”: “stable”

C

D

Pod Y2

C

D

Pod Y3

“env”: “prod”,

“rel”: “stable”

“env”: “debug”,

“rel”: “stable”

19 of 20

OpenShift v3

  • Platform-As-A-Service
  • Kubernetes extensions
    • Application Templates
      • Single JSON file for configuring Kube resources
      • Parameterizable (see example)
    • Builds
      • Hosts source code in git repos
      • Performs builds and hosts private docker images
      • Kick off new builds on git-push

20 of 20

Resources