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

Building Scalable Microservices with Kubernetes...

Sandeep Dinesh
September 30, 2015

Building Scalable Microservices with Kubernetes, gRPC, and Containers - API World 2015

Sandeep Dinesh

September 30, 2015
Tweet

More Decks by Sandeep Dinesh

Other Decks in Technology

Transcript

  1. @sandeepdinesh “Write programs that do one thing, and do it

    well. Write programs that work together” - Unix Philosophy UNIX
  2. Everything at Google runs in containers We launch over 2

    billion containers per week. • Gmail, Web Search, Maps, ... • MapReduce, batch, ... • GFS, Colossus, ...
  3. @sandeepdinesh JavaScript var http = require('http'); var server = http.createServer(function

    (request, response) { response.writeHead(200, {"Content-Type": "text/plain"}); response.end("Hello World\n"); }); server.listen(3000); App
  4. @sandeepdinesh Bash $ docker build -t api-world/frontend:1.0 . $ docker

    tag api-world/frontend:1.0 gcr.io/<project>/frontend:1.0 $ gcloud docker push gcr.io/<project>/frontend:1.0 Build the Container
  5. @sandeepdinesh YAML apiVersion: v1 kind: ReplicationController metadata: labels: name: frontend

    name: frontend spec: replicas: 2 selector: name: frontend Frontend Replication Controller template: metadata: labels: name: frontend spec: containers: - image: gcr.io/project-id/frontend:1.0 name: frontend ports: - containerPort: 3000 name: http-server
  6. @sandeepdinesh YAML apiVersion: v1 kind: Service metadata: name: frontend labels:

    name: frontend spec: type: LoadBalancer Frontend Service ports: - port: 80 targetPort: 3000 protocol: TCP selector: name: frontend
  7. @sandeepdinesh “The biggest issue in changing a monolith into microservices

    lies in changing the communication pattern.” - Martin Fowler
  8. message HelloRequest { string greeting = 1; } message HelloResponse

    { string reply = 1; } service HelloService { rpc SayHello(HelloRequest) returns (HelloResponse); } IDL (Interface definition language) Describe once and generate interfaces for any language. Data Model Structure of the request and response. Binary format for network transmission. Wire Format Protocol Buffers
  9. Multiplexing Bidirectional Streaming Flow Control HTTP/2 No more polling, sockets,

    or clunky SSE Control your congestion Single TCP connection
  10. @sandeepdinesh ProtoBuff package geo; service GeoService { rpc DistanceBetween (Points)

    returns (Distance) {} } message Point { float lat = 1; float lng = 2; } message Points { Point origin = 1; Point destination = 2; } message Distance { float distance = 1; } .proto
  11. @sandeepdinesh JavaScript var server = new GeoService({ 'geo.GeoService': { distanceBetween:

    function(call, callback) { callback(null, getDistance(call.request)); } } }); Backend Code
  12. @sandeepdinesh Bash $ docker build -t api-world/backend:1.0 . $ docker

    tag api-world/backend:1.0 gcr.io/<project>/backend:1.0 $ gcloud docker push gcr.io/<project>/backend:1.0 Build the Container
  13. @sandeepdinesh JavaScript var request = { origin: { lat: 0,

    lng: 0 }, destination: { lat: 15, lng: 15 } } Frontend Code
  14. @sandeepdinesh JavaScript client.distanceBetween(request, function(error, distance) { if (error) { response.end(JSON.stringify(error));

    } else { response.end("Distance = " + JSON.stringify(distance) + "\n"); } }); Frontend Code
  15. @sandeepdinesh Bash $ docker build -t api-world/frontend:2.0 . $ docker

    tag api-world/frontend:2.0 gcr.io/<project>/frontend:2.0 $ gcloud docker push gcr.io/<project>/frontend:2.0 Build the Container
  16. @sandeepdinesh YAML apiVersion: v1 kind: ReplicationController metadata: labels: name: backend

    name: backend spec: replicas: 4 selector: name: backend Backend Replication Controller template: metadata: labels: name: backend spec: containers: - image: gcr.io/project-id/backend:1.0 name: backend ports: - containerPort: 50051 name: grpc-server
  17. @sandeepdinesh YAML apiVersion: v1 kind: Service metadata: name: backend labels:

    name: backend spec: Backend Service ports: - port: 50051 targetPort: 50051 selector: name: backend