1 of 16

Kubernetes

From Beginner to Expert

@kubernetesio @briandorsey @jeffmendoza

2 of 16

Advanced Concepts

@kubernetesio @briandorsey @jeffmendoza

3 of 16

Jobs

Run-to-completion, as opposed to run-forever

  • Express parallelism vs. required completions
  • Workflow: restart on failure
  • Build/test: don’t restart on failure

Aggregates success/failure counts

Built for batch and big-data work

Status: GA in Kubernetes v1.2

...

@kubernetesio @briandorsey @jeffmendoza

4 of 16

Lab (Setup)

@kubernetesio @briandorsey @jeffmendoza

5 of 16

Pods

Pod

Lobsters

Log Grabber

Volume

Consumers

Log Aggregator

Can be used to group multiple containers & shared volumes

Containers within a pod are tightly coupled

Shared namespaces

  • Containers in a pod share IP, port and IPC namespaces
  • Containers in a pod talk to each other through localhost

@kubernetesio @briandorsey @jeffmendoza

6 of 16

Lab (Pod Patterns / Sidecar)

@kubernetesio @briandorsey @jeffmendoza

7 of 16

Generalized Labels (1.2)

Pod

Pod

frontend

Pod

frontend

Pod

Pod

env = qa

env = test

  • env = prod
  • tier != backend
  • env = prod, tier !=backend

Expressions

  • env in (test,qa)
  • release notin (stable,beta)
  • tier
  • !tier

env = prod

Pod

env = prod

Dashboard

selector:

env = notin(prod)

@kubernetesio @briandorsey @jeffmendoza

8 of 16

ReplicaSets (1.2)

Replication Controller

Pod

Pod

frontend

Pod

frontend

Pod

Pod

app = demo

app = demo

app = demo

ReplicaSet

#pods = 3

app = demo

color in (blue,grey)

show: version = v2

Similar to ReplicationController but supports generalized Selectors

selector:

matchLabels:

app: demo

matchExpressions:

- {key: color, operator: In, values: [blue,grey]}

color = blue

color = blue

color = grey

@kubernetesio @briandorsey @jeffmendoza

9 of 16

Deployments: Updates as a Service

Reliable mechanism for creating, updating and managing Pods

Deployment manages replica changes, including rolling updates and scaling

Edit Deployment configurations in place with kubectl edit or kubectl apply

Managed rollouts and rollbacks

Status: BETA in Kubernetes v1.2

...

@kubernetesio @briandorsey @jeffmendoza

10 of 16

Deployment Based Rolling Update

Deployment

API

Deployment

Create frontend-1234567

Deployment

Create frontend-1234567

Scale frontend-1234567 up to 1

Deployment

Create frontend-1234567

Scale frontend-1234567 up to 1

Scale frontend-7654321 down to 0

Deployment

Create frontend-1234567

Scale frontend-1234567 up to 1

Scale frontend-7654321 down to 0

Scale frontend-1234567 up to 2

Pod

Pod

frontend

Pod

version = v1

ReplicaSet

frontend-1234567

version = v2

type = BE

#pods = 0

show: version = v2

ReplicaSet

frontend-7654321

version = v1

type = BE

#pods = 2

show: version = v2

version = v2

ReplicaSet

frontend-7654321

version = v1

type = BE

#pods = 0

version= v1

ReplicaSet

frontend-1234567

version = v2

type = BE

#pods = 1

show: version = v2

ReplicaSet

frontend-1234567

version = v2

type = BE

#pods = 2

type = BE

type = BE

Pod

version = v2

type = BE

Service

Label selectors:

version = 1.0

type = Frontend

@kubernetesio @briandorsey @jeffmendoza

11 of 16

Canary

Service

Label selectors:

version = 1.0

type = Frontend

Service

name = backend

Label selector:

type = BE

Replication Controller

Pod

Pod

frontend

Pod

version= v1

version = v1

Replication Controller

version = v1

type = BE

#pods = 2

show: version = v2

type = BE

type = BE

Replication Controller

Replication Controller

version = v2

type = BE

#pods = 1

show: version = v2

Pod

frontend

Pod

version = v2

type = BE

@kubernetesio @briandorsey @jeffmendoza

12 of 16

Lab (Canary / Update / Rollback)

@kubernetesio @briandorsey @jeffmendoza

13 of 16

Autoscale

$ kubectl autoscale rc frontend-rc-v1 --min=1 --max=20

@kubernetesio @briandorsey @jeffmendoza

14 of 16

Pod Horizontal Autoscaling

Replication Controller

Pod

frontend

Pod

name=locust

name=locust

Replication Controller

name=locust

role=worker

#pods = 1

show: version = v2

Pod

frontend

Pod

name=locust

Replication Controller

name=locust

role=worker

#pods = 2

show: version = v2

Pod

Pod

name=locust

Scale

CPU Target% = 50

Heapster

role=worker

role=worker

role=worker

role=worker

Replication Controller

name=locust

role=worker

#pods = 4

70% CPU

40% CPU

> 50% CPU

< 50% CPU

@kubernetesio @briandorsey @jeffmendoza

15 of 16

Lab (Auto Scale)

@kubernetesio @briandorsey @jeffmendoza

16 of 16

Graceful Termination

Goal: Give pods time to clean up

  • finish in-flight operations
  • log state
  • flush to disk
  • 30 seconds by default

Catch SIGTERM, cleanup, exit ASAP

Pod status “Terminating”

Declarative: ‘DELETE’ appears as an object field in the API

@kubernetesio @briandorsey @jeffmendoza