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

Kubernetes - Beyond the Basics

Kubernetes - Beyond the Basics

Learn about automated deployments, blue/green and rolling updates, load balancing and networking in Kubernetes

Paul Bakker

June 24, 2015
Tweet

More Decks by Paul Bakker

Other Decks in Programming

Transcript

  1. 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
  2. Deployment 101 Push your Docker container Create a new replication

    controller JSON file kubectl  create  -­‐f  mycontroller.json   Replication Controller creates Pods
  3. 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                                            }                                      ]                                }                          ]                    }              }
  4. Scaling kubectl  scale              

                                                        —replicas=10  myreplication-­‐controller
  5. Updating my app Create a new Replication Controller JSON file

    kubectl create -f my-new-rc.json Scale down and delete old RC
  6. 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
  7. 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
  8. 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
  9. 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
  10. What about SSL offloading? … better load balancing? … redirects,

    rewrites, etc? … and that “fixed” IP can’t be reached!? Services - Not quite right
  11. Services are for communication within the k8 network (inter Pod

    communication) Services - A Hammer and screws…
  12. 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
  13. Choosing a load balancer Vulcan uses etcd for all its

    config Can use Nginx / HA-proxy with templating
  14. 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
  15. Step 5 - Blue / Green Scale up new cluster

    Wait until healthy Switch backend in Load Balancer Dispose old cluster
  16. How do we know a Pod is healthy? Its RUNNING

    status is not sufficient… Is the app fully started?
  17. 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
  18. Running a Deployer This whole things starts be to complex!

    Our build server can’t access the Pods … how do we health check?
  19. Kubernets API etcd Deployer Build Server Start deployment Kubernets API

    Kubernets API Kubernets API Pods GET /health Create RC Switch Vulcan Backend
  20. 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
  21. "podspec": { "containers": [{ "image": “amdatu/mycontainer", "name": "todo", "ports": [{

    "containerPort": 8080 }], "env": [ { "name": "version", "value": "${bamboo.deploy.version}" } ]}] }
  22. 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
  23. 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
  24. 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
  25. Logging Centralised logging is key in a dynamic environment Assume

    you can’t access a pod ELK is very useful for this
  26. Logging Docker container Docker container Docker container Docker container Docker

    container Docker container Docker container Docker container LogStash ElasticSearch Kibana
  27. Use environment variables dbName=todo-­‐app   host=${mongo} myconfig.cfg "podspec":  {  

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

     {      "name":  "mongo",      "value":  "10.100.2.4"    }   ]
  29. 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