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

Spring Cloud and Netflix OSS in a Nutshell

Spring Cloud and Netflix OSS in a Nutshell

Alexander Müller

May 12, 2017
Tweet

More Decks by Alexander Müller

Other Decks in Technology

Transcript

  1. Netflix OSS 3 Eureka Hystrix Zuul Ribbon Prana Archaius Governator

    Fenzo Karyon Hollow Dynomite Dyno Security Monkey Scumblr FIDO Falcor Restify Raigad Priam EVCache Aminator Spinnaker Nebula Photon VMAF Atlas Edda Spectator Vector Vizceral Chaos Monkey Simian Army Genie Inviso Lipstick Aegisthus
  2. Netflix OSS 4 Eureka Hystrix Zuul Ribbon Prana Archaius Governator

    Fenzo Karyon Hollow Dynomite Dyno Security Monkey Scumblr FIDO Falcor Restify Raigad Priam EVCache Aminator Spinnaker Nebula Photon VMAF Atlas Edda Spectator Vector Vizceral Chaos Monkey Simian Army Genie Inviso Lipstick Aegisthus
  3. Netflix OSS 5 Eureka Hystrix Zuul Ribbon Prana Archaius Governator

    Fenzo Karyon Hollow Dynomite Dyno Security Monkey Scumblr FIDO Falcor Restify Raigad Priam EVCache Aminator Spinnaker Nebula Photon VMAF Atlas Edda Spectator Vector Vizceral Chaos Monkey Simian Army Genie Inviso Lipstick Aegisthus Big Data Data Persistence Build and Delivery Tools Common Runtime Services & Libraries Content Encoding Insight, Reliability and Performance Security User Interface
  4. Netflix OSS 7 Ribbon ! Inter Process Communication ! Built-in

    Load Balancer ! optionally uses Hystrix
  5. Netflix OSS 8 Zuul ! Gateway Service ! Dynamic Routing

    ! Monitoring ! Resiliency ! Security ! optionally uses Ribbon Ribbon Service ID Path GET /movies/actors GET /actors Gateway movie-service
  6. Netflix OSS 9 Eureka ! Service Registry ! Mid-Tier Load

    Balancing ! Failover Discovery Service movie-service 172.10.0.1 movie-service 172.10.0.2 user-service 172.10.0.3 REGISTER REGISTER WHO IS movie-service 172.10.0.1 (simplified)
  7. Spring Cloud 11 Spring Cloud Config Spring Cloud Netflix Spring

    Cloud Bus Spring Cloud for CloudFoundry Spring Cloud Cloud Foundry Service Broker Spring Cloud Cluster Spring Cloud Consul Spring Cloud Security Spring Cloud Sleuth Spring Cloud Data Flow Spring Cloud Stream Spring Cloud Stream App Starters Spring Cloud Task Spring Cloud Task App Starters Spring Cloud Zookeeper Spring Cloud for Amazon Web Services Spring Cloud Connectors Spring Cloud Starters Spring Cloud CLI
  8. Spring Cloud 12 Spring Cloud Starters ! One Dependency, all

    Libraries! ! Compatibility of Library Versions well tested
  9. Spring Cloud 14 Spring Cloud Netflix ! Integration with Netflix

    OSS ! Auto-Configuration Register µService with Eureka Discovery Server Make this application an API gateway Enable Circuit Breaker
  10. Spring Cloud 15 Service Discovery ! Services register themselves with

    the Discovery Service and can find other services with the service registry. Discovery Service Service A REGISTER Service B FETCH REGISTRY DISCOVERY SERVICE = 172.10.0.1 SERVICE A = 172.10.0.11 SERVICE B = 172.10.0.12 172.10.0.11
  11. Spring Cloud 16 Externalized Configuration ! Services fetch their configuration

    from the Config Service during bootstrap. Config Service Service A Service B service-a.yml spring: application: name: service a … service-b.yml: …
  12. Spring Cloud 17 Chicken & Egg ! The Discovery Service

    is configured using
 a Config Service that is discovered using
 the Discovery Service which is configured using
 a Config Service that is discovered ... Discovery Service Config Service REGISTER
  13. Spring Cloud 18 Discovery First Bootstrap vs.
 Config First Bootstrap

    ! Discovery First: ! All services know where the Discovery Service is and fetch the registry. ! Once the Config Service is registered, services will resolve its location and fetch their configuration. ! Drawback: Additional roundtrip necessary during bootstrap in order to fetch the service registry. ! Config First: ! All services know where the Config Service is and fetch their configuration. ! Once they are configured, they register themselves with the Discovery Service. ! Drawback: The Config Server cannot relocate. ! Always prefer Config First Bootstrap (default).
  14. Goal of this Workshop 19 Cloud Native µServices with Netflix

    OSS and Spring ! Spring Boot application with a REST endpoint ! Spring Boot application that consumes the REST endpoint ! Config Service with Spring Cloud Config ! Externalize REST application configuration ! Discovery Service with Eureka ! Register all services ! Edge Service with Zuul ! Make all services accessible
  15. Goal of this Workshop 20 Edge Service REST Service REST

    Consumer Discovery Service Config Service REGISTER REGISTER REGISTER GET /resource GET /doSomething GET /consumer/doSomething
  16. Hands on 21 You need: ! IDE ! Maven or

    Gradle Optional: ! Docker ! Docker Compose
  17. Hands on 22 Step 1: ! Create an empty parent

    directory ! Create a Spring Boot application ! Add a @RestController with an action
 (/resource) that returns the string Hello, World! ! Set the HTTP listening port to 9001 REST Service
  18. Hands on 23 Step 2: ! Create a second Spring

    Boot application ! Add a @RestController with an action (/doSomething) ! Make this action call the first Spring Boot application’s REST endpoint using RestTemplate. ! Set the HTTP listening port to 9002 REST Service REST Consumer GET /resource GET /doSomething
  19. Hands on 24 Step 3: ! Create a third Spring

    Boot application ! Make it a Configuration Server using @EnableConfigServer ! Move the configuration from both previously created applications to the Configuration Server ! The default port is 8888. REST Service REST Consumer GET /resource GET /doSomething Config Service
  20. Hands on 25 Step 4: ! Create a fourth Spring

    Boot application ! Make it a Discovery Service using @EnableEurekaServer ! Set the HTTP listening port to 9003 ! Register other services (except Config Service) with the Discovery Service ! Rewrite call from REST Consumer to REST Service using Ribbon GET /doSomething REST Service REST Consumer Discovery Service Config Service REGISTER REGISTER GET /resource
  21. Hands on 26 Step 5: ! Create a fifth Spring

    Boot application ! Make it an Edge Service using @EnableZuulProxy ! Set the HTTP listening port to 9004 ! Configure a route to the REST Consumer
  22. Production-ready? 29 Edge Service REST Service REST Consumer Discovery Service

    Config Service REGISTER REGISTER REGISTER GET /resource GET /doSomething GET /consumer/doSomething Task Edge Service REST Service REST Consumer Discovery Service Config Service REGISTER REGISTER REGISTER GET /resource GET /doSomething GET /consumer/doSomething Task Docker EC2 Container Instance Edg REST Service REST Consumer RE GET /resource GET /doSomething Task Docker EC2 Container Instance Availability Zone Elastic Load Balancer Internet ECS Agent ECS Agent
  23. Production-ready? 30 Task Task Docker EC2 Container Instance Availability Zone

    Elastic Load Balancer Internet ECS Agent Task Task Docker EC2 Container Instance ECS Agent Elastic Load Balancer Task Task Docker EC2 Container Instance Availability Zone Agent Communication Service Amazon ECS API Cluster Management Engine Key/Value Store
  24. Service Discovery and Scaling 31 Option 1: Use Container Links

    !easy !Similar to Docker Compose Links !Can be generated from docker-compose.yml files. !Services connect only to Services of the same Task !That implies: Services are part of the same Task and run on the same EC2 Instance !Scales on Task-Level
  25. Service Discovery and Scaling 32 Option 2: Use an Elastic

    Load Balancer !hard !Every Service can connect to every other Service !Services must not be part of the same Task and can run on different EC2 Instances !Many Load Balancers need to be configured !One per Task Definition !Scales on Service-Level
  26. Option 1: Container Links 33 Task Docker EC2 Instance Availability

    Zone Service A Service B Task Service A Service B
  27. Option 2: Elastic Load Balancer 34 Elastic Load Balancer Availability

    Zone service-a-load-balancer-123456789.eu-central-1.elb.amazonaws.com Task Service A service-a-load-balancer.myvpc.vpc translated by Route 53 EC2 Instance Service B Task Docker EC2 Instance Docker Task Service B Task Service B
  28. Some Hints 35 Inter-Instance Task Connectivity !Docker Containers have their

    own host-specific IP address. !If the Bridge Network Mode is used, the host- specific IP addresses will be registered with the Discovery Service. !i.e.: Tasks won’t be able to communicate if placed on different instances. ! Solution: Use Host Network Mode.
  29. Questions? Alexander Müller, Senior IT Consultant codecentric AG Hochstraße 11

    42697 Solingen, Deutschland mobil: +49 (0) 172. 5252240 www.codecentric.de blog.codecentric.de visusnet 41