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

Netflix OSS and Kubernetes - Building a Microservice based Cloud platform

spiddy
June 18, 2016

Netflix OSS and Kubernetes - Building a Microservice based Cloud platform

There is a need these days to break monolithic solutions to distributed microservices. This need arise along with the need to restructure organizations from separate silos to DevOps.

Here we'll talk how to enable such migration using Spring Cloud, Spring Boot, Netflix OSS & Kubernetes and create a Cloud Platflorm where Microservices can be deployed easily using Docker containers.

We'll discuss about the benefits of using NetflixOSS Eureka as Service Discovery, either on-premise or on-cloud environments and how zero downtime deployments can be easily achieved using rolling updates of Kubernetes.

Lastly we'll focus on resiliency using health checks, auto healing, auto scaling and multiple data-centers on cloud providers.

spiddy

June 18, 2016
Tweet

More Decks by spiddy

Other Decks in Technology

Transcript

  1. Netflix OSS and Kubernetes
    Building a Microservice based Cloud platform
    [email protected]
    @spiddy

    View Slide

  2. Dimitris Kapanidis
    ● Founder and Senior Consultant at Harbur
    ● Organizer of Docker BCN Meetup
    ● Member of Docker Captains

    View Slide

  3. View Slide

  4. View Slide

  5. How to Handle Peak Traffic?

    View Slide

  6. What will we cover
    - Use Docker Containers as deployable units
    - Use Kubernetes as Orchestration Framework
    - Use Spring Cloud microservices
    - Use Spring Cloud Config for config management
    - Use Netflix Eureka for service discovery
    - Use Amazon AWS as our Cloud provider

    View Slide

  7. Infrastructure at High Level

    View Slide

  8. Why Docker Containers

    View Slide

  9. Containers vs. VMs

    View Slide

  10. View Slide

  11. View Slide

  12. Programmable Infrastructure
    vs
    Manual process
    Streamlined automation

    View Slide

  13. Important Principles

    View Slide

  14. Pets vs Cattle

    View Slide

  15. Immutable Servers

    View Slide

  16. Fault Tolerant Design

    View Slide

  17. The Twelve-Factor App
    I. Codebase
    II. Dependencies
    III. Config
    IV. Backing services
    V. Build, release, run
    VI. Processes
    VII. Port binding
    VIII. Concurrency
    IX. Disposability
    X. Dev/prod parity
    XI. Logs
    XII. Admin processes

    View Slide

  18. Why Kubernetes

    View Slide

  19. Kubernetes
    Kubernetes is an open-source platform for automating
    deployment, scaling, and operations of application
    containers across clusters of hosts, providing container-
    centric infrastructure
    Characteristics
    - Portable: public, private, hybrid, multi-cloud
    - Extensible: modular, pluggable, hookable, composable
    - Self-healing: auto-placement, auto-restart, auto-
    replication, auto-scaling

    View Slide

  20. Imperative vs Declarative
    ➜ repeat 5 docker run -d redis
    bfa241fe07c8b50826e349fbb200392d35ef8b91e0d4a95446e6e2285df6d567
    9ffe117f66c542770cdc6bcf80d4131639bd34168f499c25cfa2d1a7a8932656
    aef96ffc6521232e980fdbc962432766000c0357f31434329a9b843c68b97079
    337424bd5adff427dfe69b979e17c42e7cd99b59cac0b61612a924143fbcc617
    59c11b8f24a9bc5b7dcfa0810082205234228e20b3dbee02010b9b0601ec9c28
    ➜ kubectl run redis --image=redis --replicas=5
    deployment "redis" created

    View Slide

  21. http://es.slideshare.net/SpringCentral/spring-boot-microservices-containers-and-kubernetes-how-to

    View Slide

  22. View Slide

  23. View Slide

  24. View Slide

  25. View Slide

  26. View Slide

  27. View Slide

  28. View Slide

  29. View Slide

  30. View Slide

  31. View Slide

  32. View Slide

  33. Infrastructure at High Level

    View Slide

  34. Spring Cloud
    Netflix Eureka

    View Slide

  35. Spring Cloud Netflix Eureka
    Spring Cloud Netflix provides Netflix OSS integrations for
    Spring Boot apps through autoconfiguration and binding to
    the Spring Environment and other Spring programming
    model idioms.
    Characteristics
    - Service Discovery: Eureka instances can be registered
    and clients can discover the instances using Spring-
    managed beans
    - Service Discovery: an embedded Eureka server can be
    created with declarative Java configuration

    View Slide

  36. Spring Cloud Netflix Eureka
    http://start.spring.io/

    View Slide

  37. Spring Cloud Netflix Eureka
    @SpringBootApplication
    @EnableEurekaServer
    public class EurekaApplication {
    public static void main(String[] args) {
    SpringApplication.run(EurekaApplication.class.class, args);
    }
    }
    src/main/java/com/example/EurekaApplication.java
    spring.application.name=eureka
    eureka.client.serviceUrl.defaultZone=http://eureka:8080/eureka/
    src/main/resources/bootstrap.properties

    View Slide

  38. Spring Cloud Netflix Eureka
    ➜ mvn clean install
    [INFO] Scanning for projects...
    [INFO]
    [INFO] ------------------------------------------------------------------------
    [INFO] Building eureka 0.0.1-SNAPSHOT
    [INFO] ------------------------------------------------------------------------

    ➜ java -jar target/eureka-0.0.1-SNAPSHOT.jar
    . ____ _ __ _ _
    /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
    ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
    \\/ ___)| |_)| | | | | || (_| | ) ) ) )
    ' |____| .__|_| |_|_| |_\__, | / / / /
    =========|_|==============|___/=/_/_/_/
    :: Spring Boot :: (v1.3.5.RELEASE)
    2016-06-14 11:48:10.562 INFO 45242 --- [ main] com.example.EurekaApplication
    : No active profile set, falling back to default profiles: default

    View Slide

  39. Spring Cloud Netflix Eureka
    http://localhost:8080/

    View Slide

  40. Dockerize
    ➜ echo "FROM bankmonitor/spring-boot" > Dockerfile
    ➜ cp target/eureka-0.0.1-SNAPSHOT.jar app.jar
    ➜ captain build
    [CAPTAIN] No configuration found captain.yml - inferring values
    [CAPTAIN] Building image spiddy/eureka:latest
    Step 1 : FROM bankmonitor/spring-boot
    # Executing 1 build trigger...
    Step 1 : COPY app.jar /app/app.jar
    ---> Using cache
    ---> 1a3a103d7001
    Successfully built 1a3a103d7001
    ➜ docker run -d -p 8080:8080 spiddy/eureka
    984f68a39e894e1a0a63058a95fb4754548a1bae5649cd44feef142a5f1ba12b
    ➜ curl -s localhost:8080/eureka/apps

    1

    %

    View Slide

  41. Deploy to Kubernetes
    ➜ kubectl run eureka --image=spiddy/eureka \
    --overrides='{ "spec":{"template":{"spec": {"containers":[{"name":"demo","image":"spiddy/eureka", "imagePullPolicy":"Never"}]}}}}'
    deployment "eureka" created
    ➜ kubectl get pods
    NAME READY STATUS RESTARTS AGE
    eureka-4130299362-gqdyi 1/1 Running 0 13m
    ➜ kubectl scale deployment eureka --replicas=5
    deployment "eureka" scaled
    ➜ kubectl get pods
    NAME READY STATUS RESTARTS AGE
    eureka-4130299362-ea8pg 1/1 Running 0 4s
    eureka-4130299362-gqdyi 1/1 Running 0 14m
    eureka-4130299362-mzdbs 1/1 Running 0 4s
    eureka-4130299362-ryflq 1/1 Running 0 14m
    eureka-4130299362-w0c9y 1/1 Running 0 4s

    View Slide

  42. Expose Kubernetes Service
    ➜ kubectl expose deployment eureka --port 8080
    service "config" exposed
    ➜ kubectl get services -l run=eureka
    NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
    eureka 10.17.139.244 8080/TCP 59m
    ➜ curl -s 10.17.139.244:8080/eureka/apps

    1
    UP_3_

    UNKNOWN

    View Slide

  43. Spring Cloud Netflix Eureka

    View Slide

  44. Infrastructure at High Level

    View Slide

  45. Spring Cloud
    Config

    View Slide

  46. Spring Cloud Config
    Spring Cloud Config provides server and client-side support for externalized
    configuration in a distributed system.
    Characteristics
    - HTTP, resource-based API for external configuration (name-value pairs, or
    equivalent YAML content)
    - Encrypt and decrypt property values (symmetric or asymmetric)
    - Embeddable easily in a Spring Boot application using
    @EnableConfigServer

    View Slide

  47. http://start.spring.io/
    Spring Cloud Config

    View Slide

  48. src/main/resources/application.properties
    spring.cloud.config.server.git.uri: https://github.com/spiddy/config-repo
    @SpringBootApplication
    @EnableConfigServer
    @EnableEurekaClient
    public class ConfigApplication {
    public static void main(String[] args) {
    SpringApplication.run(ConfigApplication.class, args);
    }
    }
    src/main/java/com/example/ConfigApplication.java
    Spring Cloud Config

    View Slide

  49. Spring Cloud Config
    ➜ mvn clean install
    [INFO] Scanning for projects...
    [INFO]
    [INFO] ------------------------------------------------------------------------
    [INFO] Building config 0.0.1-SNAPSHOT
    [INFO] ------------------------------------------------------------------------

    ➜ java -jar target/config-0.0.1-SNAPSHOT.jar
    . ____ _ __ _ _
    /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
    ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
    \\/ ___)| |_)| | | | | || (_| | ) ) ) )
    ' |____| .__|_| |_|_| |_\__, | / / / /
    =========|_|==============|___/=/_/_/_/
    :: Spring Boot :: (v1.3.5.RELEASE)
    2016-06-13 17:26:30.262 INFO 32376 --- [ main] com.example.ConfigApplication
    : No active profile set, falling back to default profiles: default

    View Slide

  50. Spring Cloud Config
    ➜ curl -s localhost:8080/demo/test | jq .
    {
    "name": "demo",
    "profiles": [
    "test"
    ],
    "label": null,
    "version": "96fe1fa3f8d8ebb726a83ea6070c02aa9ad3a957",
    "propertySources": [
    {
    "name": "https://github.com/spiddy/config-repo/demo.properties",
    "source": {
    "my.message": "Hello world"
    }
    },

    View Slide

  51. Dockerize
    ➜ echo "FROM bankmonitor/spring-boot" > Dockerfile
    ➜ cp target/config-0.0.1-SNAPSHOT.jar app.jar
    ➜ captain build
    ➜ docker run -d -p 8080:8080 spiddy/config
    f2daa49ea9a5886443cb127184f08252b3bd90b8f0fe914c5b7bdf3b87665a82
    ➜ curl -s localhost:8080/demo/test | jq .profiles
    [
    "test"
    ]

    View Slide

  52. Deploy to Kubernetes
    ➜ kubectl run config --image=spiddy/config \
    --overrides='{ "spec":{"template":{"spec": {"containers":[{"name":"demo","image":"spiddy/config", "imagePullPolicy":"Never"}]}}}}'
    deployment "config" created
    ➜ kubectl get pods
    NAME READY STATUS RESTARTS AGE
    config-3041615316-abqdl 1/1 Running 0 23s
    ➜ kubectl scale deployment config --replicas=5
    deployment "config" scaled
    ➜ kubectl get pods
    NAME READY STATUS RESTARTS AGE
    config-3041615316-7ccta 1/1 Running 0 9s
    config-3041615316-abqdl 1/1 Running 0 52s
    config-3041615316-jp0om 1/1 Running 0 9s
    config-3041615316-jwrux 1/1 Running 0 9s
    config-3041615316-owig8 1/1 Running 0 9s

    View Slide

  53. Expose Kubernetes Service
    ➜ kubectl expose deployment config --port 8080
    service "config" exposed
    ➜ kubectl get services -l run=config
    NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
    config 10.26.208.52 8080/TCP 26s
    ➜ curl -s 10.26.208.52:8080/demo/test | jq .profiles
    [
    "test"
    ]

    View Slide

  54. Infrastructure at High Level

    View Slide

  55. Spring Cloud
    Microservices

    View Slide

  56. Spring Boot
    Spring Boot makes it easy to create stand-alone, production-grade Spring
    based Applications that you can "just run".
    Characteristics
    - Create stand-alone Spring applications
    - Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)
    - Provide opinionated 'starter' POMs to simplify your Maven configuration
    - Automatically configure Spring whenever possible
    - Provide production-ready features such as metrics, health checks and
    externalized configuration
    - Absolutely no code generation and no requirement for XML configuration

    View Slide

  57. Spring Cloud
    Spring Cloud provides tools for developers to quickly build some of the
    common patterns in distributed systems (e.g. configuration management,
    service discovery, circuit breakers, intelligent routing, micro-proxy, control bus,
    one-time tokens, global locks, leadership election, distributed sessions, cluster
    state)
    - Circuit Breakers
    - Global locks
    - Leadership election and cluster state
    - Distributed messaging
    Characteristics
    - Distributed/versioned configuration
    - Service registration and discovery
    - Routing
    - Service-to-service calls
    - Load balancing

    View Slide

  58. Spring Cloud Microservice
    http://start.spring.io/

    View Slide

  59. Spring Cloud Microservice

    View Slide

  60. Spring Cloud Microservice
    ➜ mvn clean install
    [INFO] Scanning for projects...
    [INFO]
    [INFO] ------------------------------------------------------------------------
    [INFO] Building demo 0.0.1-SNAPSHOT
    [INFO] ------------------------------------------------------------------------

    ➜ java -jar target/demo-0.0.1-SNAPSHOT.jar
    . ____ _ __ _ _
    /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
    ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
    \\/ ___)| |_)| | | | | || (_| | ) ) ) )
    ' |____| .__|_| |_|_| |_\__, | / / / /
    =========|_|==============|___/=/_/_/_/

    ➜ curl -s localhost:8080
    Hello World! [ds-MacBook-Pro.local]
    src/main/resources/bootstrap.properties
    spring.application.name=demo
    spring.cloud.config.uri=http://config:8080

    View Slide

  61. Dockerize
    ➜ echo "FROM bankmonitor/spring-boot" > Dockerfile
    ➜ cp target/demo-0.0.1-SNAPSHOT.jar app.jar
    ➜ captain build
    [CAPTAIN] No configuration found captain.yml - inferring values
    [CAPTAIN] Building image spiddy/demo:latest
    Step 1 : FROM bankmonitor/spring-boot
    # Executing 1 build trigger...
    Step 1 : COPY app.jar /app/app.jar
    ---> Using cache
    ---> 1a3a103d7001
    Successfully built 1a3a103d7001
    ➜ docker run -d -p 8080:8080 spiddy/demo
    393b2c1d84d4c94ce4115af0bfd6816ca546d7b6eee266306d9ed47e00e45533
    ➜ curl localhost:8080
    Hello World! [393b2c1d84d4]

    View Slide

  62. Deploy to Kubernetes
    ➜ kubectl run demo --image=spiddy/demo \
    --overrides='{ "spec":{"template":{"spec":{"containers":[{"name":"demo","image":"spiddy/demo", "imagePullPolicy":"Never"}]}}}}'
    deployment "demo" created
    ➜ kubectl get pods
    NAME READY STATUS RESTARTS AGE
    demo-1703894066-8yixg 1/1 Running 0 27s
    ➜ kubectl scale deployment demo --replicas=5
    deployment "demo" scaled
    ➜ kubectl get pods
    NAME READY STATUS RESTARTS AGE
    demo-1703894066-8yixg 1/1 Running 0 53s
    demo-1703894066-ethep 1/1 Running 0 53s
    demo-1703894066-hh7is 1/1 Running 0 3m
    demo-1703894066-jr059 1/1 Running 0 53s
    demo-1703894066-nbk4l 1/1 Running 0 53s

    View Slide

  63. Expose Kubernetes Service
    ➜ kubectl expose deployment demo --port 8080
    service "demo" exposed
    ➜ kubectl get services
    NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
    demo 10.22.67.197 8080/TCP 2m
    kubernetes 10.16.0.1 443/TCP 1h
    ➜ repeat 10 curl -s 10.22.67.197:8080
    Hello World! [demo-1703894066-ethep]
    Hello World! [demo-1703894066-nbk4l]
    Hello World! [demo-1703894066-hh7is]
    Hello World! [demo-1703894066-hh7is]
    Hello World! [demo-1703894066-hh7is]
    Hello World! [demo-1703894066-jr059]
    Hello World! [demo-1703894066-hh7is]
    Hello World! [demo-1703894066-ethep]
    Hello World! [demo-1703894066-ethep]
    Hello World! [demo-1703894066-jr059]

    View Slide

  64. Infrastructure at High Level

    View Slide

  65. What we do
    We help modernize enterprise development workflows
    focusing on containers as first-class citizens
    1 ½ years running Docker Containers in Production
    Services
    - Consulting
    - Training

    View Slide

  66. What we do
    Onebox
    30% Cost Reduction
    on AWS servers
    Bpulse
    Cloud-Native Infrastructure
    (AWS,GCP,On-Prem,Azure)
    Tourism Sector
    Infrastructure for 22M
    daily hits

    View Slide

  67. What we do

    View Slide

  68. [email protected]
    @spiddy
    Thank You!

    View Slide