Slide 1

Slide 1 text

Kubernetes Beyond the basics @pbakker

Slide 2

Slide 2 text

Paul Bakker @pbakker

Slide 3

Slide 3 text

Automated, production ready Kubernetes cluster in steps 9

Slide 4

Slide 4 text

Step Understanding Kubernetes 0 Terminology, and concepts to build upon

Slide 5

Slide 5 text

Nodes, Pods, Controllers Docker container Docker container Docker container Docker container Pods Node Docker container Docker container Docker container Docker container Pods Node Docker container Docker container Docker container Replication Controller Master schedules schedules

Slide 6

Slide 6 text

Deployment 101 Push your Docker container Create a new replication controller JSON file kubectl  create  -­‐f  mycontroller.json   Replication Controller creates Pods

Slide 7

Slide 7 text

mycontroller.json  "spec":{              "replicas":3,              "selector":{                    "name":"frontend"              },              "template":{                    "metadata":{                          "labels":{                                "name":"frontend"                          }                    },                    "spec":{                          "containers":[                                {                                      "name":"php-­‐redis",                                      "image":"kubernetes/example-­‐guestbook-­‐php-­‐redis:v2",                                      "ports":[                                            {                                                  "containerPort":80                                            }                                      ]                                }                          ]                    }              }

Slide 8

Slide 8 text

Scaling kubectl  scale                                                                   —replicas=10  myreplication-­‐controller

Slide 9

Slide 9 text

Updating my app Create a new Replication Controller JSON file kubectl create -f my-new-rc.json Scale down and delete old RC

Slide 10

Slide 10 text

Step Automated deployment (simplistic) 1 This kubectl stuff seems a lot of typing!

Slide 11

Slide 11 text

The simplest Automated deployment Don’t use kubectl, use the API! Build server creates Replication Controller using REST Build server destroys old cluster using REST

Slide 12

Slide 12 text

Docker container Docker container Docker container Docker container Node Docker registry Build Server Docker container Docker container Docker container Docker container Node push Create RC Docker container Docker container Docker container Replication Controller Master schedules schedules API

Slide 13

Slide 13 text

Curl example curl  -­‐X  POST       http://k8-­‐master:8080/api/v1beta3/namespaces/default/replicationcontrollers  -­‐d  '{   #Pod  definition   }’

Slide 14

Slide 14 text

What about downtime? Not quite there yet

Slide 15

Slide 15 text

Step Load balancing 2 Our containers are running, but how do we access them!?

Slide 16

Slide 16 text

Pods come and go Pods have dynamic IP addresses First try - Kubernetes Services A service is a proxy to your Pods Fixed IP P O D S E
 R
 V
 I
 C E

Slide 17

Slide 17 text

Docker container Docker container Docker container Docker container Pods Node Docker container Docker container Docker container Docker container Pods Node MyService HTTP Virtual IP Virtual IP Fixed IP

Slide 18

Slide 18 text

What about SSL offloading? … better load balancing? … redirects, rewrites, etc? … and that “fixed” IP can’t be reached!? Services - Not quite right

Slide 19

Slide 19 text

Services are for communication within the k8 network (inter Pod communication) Services - A Hammer and screws…

Slide 20

Slide 20 text

Docker container Docker container Docker container Docker container Pods Node Docker container Docker container Docker container Docker container Pods Node Vulcan Proxy HTTP Virtual IP Virtual IP Fixed IP Custom load balancer etcd

Slide 21

Slide 21 text

Choosing a load balancer Vulcan uses etcd for all its config Can use Nginx / HA-proxy with templating

Slide 22

Slide 22 text

So you’re telling me… —link doesn’t work!? And now you’re telling me… —I can’t see my Pods!?

Slide 23

Slide 23 text

Step Weave 3 Each Pod gets its own IP Access Pods from outside k8

Slide 24

Slide 24 text

Docker container Docker container Docker container Docker container Node Docker container Docker container Docker container Docker container Pods Node Vulcan Proxy HTTP Virtual IP Virtual IP Fixed IP Weave network Pods

Slide 25

Slide 25 text

Step Load balancer registration 4 How does the load balancer keep track of pods?

Slide 26

Slide 26 text

Watch the Kubernetes API Kubernetes API Vulcan etcd Registrator Watch New Vulcan Config Uses new backends

Slide 27

Slide 27 text

Amdatu Vulcanized Open source tool connecting Kubernetes and Vulcan Written in Go Available as Docker container

Slide 28

Slide 28 text

Amdatu Vulcanized Kubernetes API Vulcan etcd Amdatu Vulcanized Watch New Vulcan Config Uses new backends

Slide 29

Slide 29 text

Step Blue / Green deployment 5 Auto deploy is great, but downtime not so much

Slide 30

Slide 30 text

Step 5 - Blue / Green Scale up new cluster Wait until healthy Switch backend in Load Balancer Dispose old cluster

Slide 31

Slide 31 text

How do we know a Pod is healthy? Its RUNNING status is not sufficient… Is the app fully started?

Slide 32

Slide 32 text

Introduce App level health checks Docker container Docker container Docker container Docker container Node Docker container Docker container Docker container Docker container Pods Node Deployer GET /health GET /health Pods Deploy Server

Slide 33

Slide 33 text

Running a Deployer This whole things starts be to complex! Our build server can’t access the Pods … how do we health check?

Slide 34

Slide 34 text

Kubernets API etcd Deployer Build Server Start deployment Kubernets API Kubernets API Kubernets API Pods GET /health Create RC Switch Vulcan Backend

Slide 35

Slide 35 text

Kubernets API Vulcan etcd Deployer Build Server Start deployment Kubernets API Kubernets API Kubernets API Pods GET /health Create RC Switch Vulcan Backend Amdatu Vulcanized Watch Create backends Read config

Slide 36

Slide 36 text

Deployment descriptor { "useHealthCheck": true, "newVersion": "${bamboo.deploy.version}", "appName": "todo", "replicas": 2, "vulcanFrontend": "rti-todo.amdatu.com", “podspec": { …. } }

Slide 37

Slide 37 text

"podspec": { "containers": [{ "image": “amdatu/mycontainer", "name": "todo", "ports": [{ "containerPort": 8080 }], "env": [ { "name": "version", "value": "${bamboo.deploy.version}" } ]}] }

Slide 38

Slide 38 text

One more thing… We need to tell Kubernetes replicas need to run on different machines! Docker container Docker container Docker container Docker container Node Docker container Docker container Docker container Docker container Node Create RC Docker container Docker container Docker container Replication Controller Master S E R V I C E

Slide 39

Slide 39 text

Deployment demo Demo

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

Step Canary deployment 6

Slide 42

Slide 42 text

Canary deployments Different strategy for the Deployer Add Replication Controller But don’t change the running cluster

Slide 43

Slide 43 text

K8 Node K8 Node K8 Node K8 Node Prod pod Canary Main Replication Controller K8 Node K8 Node K8 Node K8 Node Canary pod Canary Replication Controller Vulcan

Slide 44

Slide 44 text

Step Persistent data 7 How to deploy Mongo/MySQL/ElasticSearch in Kubernetes?

Slide 45

Slide 45 text

You don’t

Slide 46

Slide 46 text

Kubernetes is great for… Stateless containers Running lots of containers together Moving containers around

Slide 47

Slide 47 text

Datastores scaling mechanics Reactive scaling makes less sense Cluster should be tuned Scaling is expensive

Slide 48

Slide 48 text

Infra server(s) K8 Master K8 Node K8 Node K8 Node K8 Node K8 Node Vulcan Vulcanized Deployer Mongo Cluster ElasticSearch Cluster … Cluster Cluster topology

Slide 49

Slide 49 text

Step Logging 8 kubectl logs mypod?

Slide 50

Slide 50 text

Logging Centralised logging is key in a dynamic environment Assume you can’t access a pod ELK is very useful for this

Slide 51

Slide 51 text

Logging Docker container Docker container Docker container Docker container Docker container Docker container Docker container Docker container LogStash ElasticSearch Kibana

Slide 52

Slide 52 text

Logging example OSGi app OSGi LogService SLF4J Kafka

Slide 53

Slide 53 text

Logging example Kafka LogStash ElasticSearch Infra components Kibana Dashboard Developer

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

Step Configuration 9 Passing config to containers

Slide 56

Slide 56 text

Use environment variables dbName=todo-­‐app   host=${mongo} myconfig.cfg "podspec":  {                "env":  [                    {                      "name":  "mongo",                      "value":  "10.100.2.4"                      }, Deployment descriptor Approach 1

Slide 57

Slide 57 text

Use etcd etcd=localhost:2375 myconfig.cfg /apps/config/demo-­‐app etcd Approach 2 [    {      "name":  "mongo",      "value":  "10.100.2.4"    }   ]

Slide 58

Slide 58 text

And if you don’t want to do all this yourself…. RTI Fully managed Kubernetes based clusters Logging and Monitoring Automated deployments Not your standard PAAS

Slide 59

Slide 59 text

Thank you! Blog: http://paulbakker.io Twitter: @pbakker Mail: paul.bakker@luminis.eu