2015 Spring IO Barcelona - Spring-Boot Microservices, Container, Kubernetes How To

2015 Spring IO Barcelona - Spring-Boot Microservices, Container, Kubernetes How To

5e0c801ac1a5d0512bb9774ab158d06d?s=128

Ray Tsang

May 04, 2015
Tweet

Transcript

  1. @saturnism #springio15 #kubernetes Kubernetes With Spring Boot Microservices

  2. @saturnism #springio15 #kubernetes Ray Tsang Developer Advocate twitter: @saturnism github:

    saturnism © 2015 Ray Tsang
  3. @saturnism #springio15 #kubernetes Ray Tsang Enterprise Architect Open Source Traveler

    flickr: saturnism © 2015 Ray Tsang
  4. @saturnism © 2015 Ray Tsang

  5. @saturnism © 2015 Ray Tsang

  6. @saturnism #springio15 #kubernetes Spring Boot + Groovy + Microservices? Remember

    Josh’s Tweet? https://twitter.com/starbuxman/status/580517687006216193
  7. @saturnism #springio15 #kubernetes Demo Application Hello World UI Hello World

    Service Redis session replication greeting
  8. @saturnism #springio15 #kubernetes Old way: Shared machines kernel libs app

    app app No isolation No namespacing Common libs Highly coupled apps and OS app
  9. @saturnism #springio15 #kubernetes App Server libs app app app app

    Old way: Java No isolation No namespacing Common libs - shouldn’t really happen in Java apps...
  10. @saturnism #springio15 #kubernetes Spring Boot + Containers A good match!

  11. @saturnism #springio15 #kubernetes Old way: Virtual machines Good isolation Expensive

    and inefficient Still highly coupled to the guest OS Hard to manage app libs kernel libs app app kernel app libs libs kernel kernel
  12. @saturnism #springio15 #kubernetes New way: Containers libs app kernel libs

    app libs app libs app
  13. @saturnism #springio15 #kubernetes Lightweight

  14. @saturnism #springio15 #kubernetes Process isolation CPU, Memory, Network, Filesystem, ...

  15. @saturnism #springio15 #kubernetes Static binaries no library dependencies

  16. @saturnism #springio15 #kubernetes Runs on any machine physical, virtual, cloud

    - OS agnostic
  17. @saturnism #springio15 #kubernetes Write once - run everywhere! Development, Test,

    Staging, Production...
  18. @saturnism #springio15 #kubernetes Containerize Dockerfile

  19. @saturnism #springio15 #kubernetes Containerize mvn docker:build

  20. @saturnism #springio15 #kubernetes Let’s run the container! docker run -ti

    -p 8080:8080 spring-boot-demo
  21. @saturnism #springio15 #kubernetes Redis container docker run --rm -ti --name

    redis redis
  22. @saturnism #springio15 #kubernetes Microservice container docker run --rm -ti --name

    helloworldservice helloworld-service-demo
  23. @saturnism #springio15 #kubernetes Link containers docker run -ti --rm --link

    redis:redis --link helloworldservice:helloworldservice, -p 8080:8080 helloworld-ui-demo:latest
  24. @saturnism #springio15 #kubernetes Docker Compose docker-compose up

  25. @saturnism #springio15 #kubernetes Everything at Google runs in containers Launch

    over 2 billion containers per week.
  26. @saturnism #springio15 #kubernetes More than one... libs app kernel libs

    app libs app libs app libs app kernel libs app libs app libs app libs app kernel libs app libs app libs app
  27. @saturnism #springio15 #kubernetes Enter Kubernetes Greek for “Helmsman”; also the

    root of the word “Governor” • Container orchestrator • Runs Docker containers • Supports multiple cloud and bare- metal environments • Inspired and informed by Google’s experiences and internal systems • Open source, written in Go Manage applications, not machines
  28. @saturnism #springio15 #kubernetes Kubernetes cluster libs app kernel libs app

    libs app libs app libs app kernel libs app libs app libs app libs app kernel libs app libs app libs app Kubernetes Master
  29. @saturnism #springio15 #kubernetes Distributed process scheduler cluster of machines as

    one!
  30. @saturnism #springio15 #kubernetes Open source community Version 0.16 Hosted on

    GitHub 327+ contributors 10,000+ commits 7,000+ GitHub stars CoreOS HP IBM Mesosphere Microsoft Project Partners Pivotal Red Hat SaltStack VMWare kubernetes.io
  31. @saturnism #springio15 #kubernetes Pod Group of containers Live and die

    together Shared network interface Pod App Log Collector ...
  32. @saturnism #springio15 #kubernetes Pod networking Pod IPs are routable •

    Docker default is private IP Pods can reach each other without NAT • even across nodes No brokering of port numbers This is a fundamental requirement • several SDN solutions
  33. @saturnism #springio15 #kubernetes Pod networking 10.1.1.0/24 10.1.1.93 10.1.1.113 10.1.2.0/24 10.1.2.118

    10.1.3.0/24 10.1.3.129
  34. @saturnism #springio15 #kubernetes Labels Label anything Name-value pair Make your

    own Pod App Log Collector ... type = Frontend version = 1.0
  35. @saturnism #springio15 #kubernetes Replication controllers Replication Controller Replicas → 2

    Pod App Log Collector ... type = Frontend version = 1.0 Pod App Log Collector ... type = Frontend version = 1.0
  36. @saturnism #springio15 #kubernetes Replication controllers Replication Controller Replicas → 1

    Pod App Log Collector ... type = Frontend version = 1.0 Pod App Log Collector ... type = Frontend version = 1.0
  37. @saturnism #springio15 #kubernetes Replication controllers node 1 f0118 node 3

    node 4 node 2 d9376 b0111 a1209 Replication Controller - Desired = 4 - Current = 4
  38. @saturnism #springio15 #kubernetes Replication controllers node 1 f0118 node 3

    node 4 node 2 d9376 b0111 a1209 Replication Controller - Desired = 4 - Current = 4
  39. @saturnism #springio15 #kubernetes Replication controllers node 1 f0118 node 3

    node 4 b0111 a1209 Replication Controller - Desired = 4 - Current = 3
  40. @saturnism #springio15 #kubernetes Replication controllers node 1 f0118 node 3

    node 4 a1209 Replication Controller - Desired = 4 - Current = 4 b0111 c9bad
  41. @saturnism #springio15 #kubernetes Services Replication Controller Replicas → 2 Pod

    frontend Pod type = Frontend version = 1.0 Pod type = Frontend version = 1.0 Service Label selectors: version = 1.0 type = Frontend
  42. @saturnism #springio15 #kubernetes Let’s deploy the microservices! Demo effect time

  43. @saturnism #springio15 #kubernetes Docker Repository DockerHub or … Private Repository

    (e.g., gcr.io)
  44. @saturnism #springio15 #kubernetes DevOps with Kubernetes

  45. @saturnism #springio15 #kubernetes Versioning container image docker tag spring-boot-demo spring-boot-demo:1.0

  46. @saturnism #springio15 #kubernetes Staging vs. production Use labels - deploy

    in the same infrastructure
  47. @saturnism #springio15 #kubernetes Canary Use service, and replication controllers to

    canary new versions
  48. @saturnism #springio15 #kubernetes Rolling upgrade Similar to canary, but slowly

    let the new version take over
  49. @saturnism #springio15 #kubernetes Rollback Super simple with versioned containers

  50. @saturnism #springio15 #kubernetes Vagrant export KUBERNETES_PROVIDER=vagrant curl -sS https://get.k8s.io |

    bash Google Container Engine - Alpha http://cloud.google.com/container-engine http://kubernetes.io/gettingstarted/
  51. @saturnism #springio15 #kubernetes Tips and Tricks

  52. @saturnism #springio15 #kubernetes Service discovery Read service IP addresses via

    environmental variables
  53. @saturnism #springio15 #kubernetes Test locally! Set environmental variables REDIS_PORT=tcp://localhost:6379 spring

    run .
  54. @saturnism #springio15 #kubernetes SecureRandom - slow =( Use a different

    source -Djava.security.egd=file:/dev/urandom
  55. @saturnism #springio15 #kubernetes Clean up disk spaces Every image, layer,

    and, even containers litters docker rm $(docker ps -a -q) docker rmi $(docker images -q --filter dangling=true)
  56. @saturnism #springio15 #kubernetes Try out Google Container Engine https://cloud.google.com/container-engine/

  57. @saturnism #springio15 #kubernetes Thanks! kubernetes.io http://bit.ly/1QLg5E1