Slide 1

Slide 1 text

Netflix OSS and Kubernetes Building a Microservice based Cloud platform dimitris@harbur.io @spiddy

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

How to Handle Peak Traffic?

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

Infrastructure at High Level

Slide 8

Slide 8 text

Why Docker Containers

Slide 9

Slide 9 text

Containers vs. VMs …

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Programmable Infrastructure vs Manual process Streamlined automation

Slide 13

Slide 13 text

Important Principles

Slide 14

Slide 14 text

Pets vs Cattle

Slide 15

Slide 15 text

Immutable Servers

Slide 16

Slide 16 text

Fault Tolerant Design

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

Why Kubernetes

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

Infrastructure at High Level

Slide 34

Slide 34 text

Spring Cloud Netflix Eureka

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

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 …

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

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 %

Slide 41

Slide 41 text

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

Slide 42

Slide 42 text

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 …

Slide 43

Slide 43 text

Spring Cloud Netflix Eureka

Slide 44

Slide 44 text

Infrastructure at High Level

Slide 45

Slide 45 text

Spring Cloud Config

Slide 46

Slide 46 text

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

Slide 47

Slide 47 text

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

Slide 48

Slide 48 text

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

Slide 49

Slide 49 text

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 …

Slide 50

Slide 50 text

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" } }, …

Slide 51

Slide 51 text

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" ]

Slide 52

Slide 52 text

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

Slide 53

Slide 53 text

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" ]

Slide 54

Slide 54 text

Infrastructure at High Level

Slide 55

Slide 55 text

Spring Cloud Microservices

Slide 56

Slide 56 text

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

Slide 57

Slide 57 text

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

Slide 58

Slide 58 text

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

Slide 59

Slide 59 text

Spring Cloud Microservice

Slide 60

Slide 60 text

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

Slide 61

Slide 61 text

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]

Slide 62

Slide 62 text

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

Slide 63

Slide 63 text

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]

Slide 64

Slide 64 text

Infrastructure at High Level

Slide 65

Slide 65 text

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

Slide 66

Slide 66 text

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

Slide 67

Slide 67 text

What we do

Slide 68

Slide 68 text

dimitris@harbur.io @spiddy Thank You!