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

Build systems like a Googler

Build systems like a Googler

gRPC and Kubernetes are two separate open source projects born at Google and with a similar goal: sharing Google's experience building distributed applications. This talk will cover the basic concepts of both projects and show how to build a simple application using both project plus a third Google open source project: Go

Francesc Campoy Flores

February 05, 2016
Tweet

More Decks by Francesc Campoy Flores

Other Decks in Programming

Transcript

  1. Developer Advocate at Google - Google Cloud Platform - Go

    team On: - @francesc | campoy.cat/+ - [email protected] Francesc Campoy
  2. @francesc Program v. tr. To engage in a pastime similar

    to banging one's head against a wall, but with fewer opportunities for reward. -- Anonymous
  3. Confidential & Proprietary Google Cloud Platform 8 Simple type system

    - Statically typed - Object oriented, but not what you think - No inheritance! Simple, readable, understandable specification Gophers like simplicity
  4. @francesc C makes it easy to shoot yourself in the

    foot. C++ makes it harder, but when you do, it blows away your whole leg. -- Bjarne Stroustrup
  5. Confidential & Proprietary Google Cloud Platform 10 Type safe -

    statically typed - no implicit numeric conversion - no *void Memory safe - pointers - no pointers arithmetic - no buffer overflow Garbage collected - no memory leaks (almost) Gophers like safety
  6. @francesc Some people, when confronted with a problem, think, "I

    know, I'll use threads," and then two they hav erpoblesms.
  7. Confidential & Proprietary Google Cloud Platform 12 Gophers like concurrency

    Goroutines communicate over channels. Not a new idea: Communicating sequential processes C. Hoare 1978 But still a very good one!
  8. Confidential & Proprietary Google Cloud Platform 13 at compilation So

    fast, you may forget about compilation at run time It's fast, and it keeps on becoming faster Gophers like speed
  9. @francesc job hello_world = { runtime = { cell =

    'ic' } // Cell (cluster) to run in binary = '.../hello_world_webserver' // Program to run args = { port = '%port%' } // Command line parameters requirements = { // Resource requirements ram = 100M disk = 100M cpu = 0.1 } replicas = 5 // Number of tasks } 10000 Developer View
  10. @francesc web browsers BorgMaster link shard UI shard BorgMaster link

    shard UI shard BorgMaster link shard UI shard BorgMaster link shard UI shard Scheduler borgcfg web browsers scheduler Borglet Borglet Borglet Borglet Config file BorgMaster link shard UI shard persistent store (Paxos) Binary Developer View What just happened?
  11. Hello world! Hello world! Hello world! Hello world! Hello world!

    Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Image by Connie Zhou Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world!
  12. @francesc Enter Kubernetes Greek for “Helmsman”; also the root of

    the word “Governor” • Container orchestrator • Runs 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
  13. Version 1.1 Hosted on GitHub 600+ contributors 24k+ commits 12,5k+

    GitHub stars CoreOS HP IBM Mesosphere Microsoft Project Partners Open Source Community Pivotal Red Hat SaltStack VMWare https://github.com/kubernetes/kubernetes
  14. @francesc web browsers Scheduler kubectl web browsers scheduler Kubelet Kubelet

    Kubelet Kubelet Config file Kubernetes Master Container Image Developer View What just happened?
  15. @francesc Group of containers Live and die together Shared network

    interface Shared volumes Unique Routable IP Pod App Log Collector Pods ...
  16. @francesc 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 Inter-Pods Networking
  17. @francesc Label anything Name-value pair Make your own Pod App

    Log Collector Labels ... type = Frontend version = 1.0
  18. @francesc Replication Controller Replicas → 2 Pod frontend Pod App

    Log Collector ... type = Frontend version = 1.0 Pod App Log Collector ... type = Frontend version = 1.0 Replication Controllers
  19. @francesc Replication Controller Replicas → 1 Pod App Log Collector

    ... type = Frontend version = 1.0 Replication Controllers
  20. @francesc Replication Controllers node 1 f0118 node 3 node 4

    node 2 d9376 b0111 a1209 Replication Controller - Desired = 4 - Current = 4
  21. @francesc Replication Controllers node 1 f0118 node 3 node 4

    node 2 Replication Controller - Desired = 4 - Current = 4 d9376 b0111 a1209
  22. @francesc Replication Controllers node 1 f0118 node 3 node 4

    Replication Controller - Desired = 4 - Current = 3 b0111 a1209
  23. @francesc Replication Controllers node 1 f0118 node 3 node 4

    Replication Controller - Desired = 4 - Current = 4 b0111 a1209 c9bad
  24. @francesc Replication Controller Replicas → 2 Pod frontend Pod type

    = Frontend version = 1.0 Pod type = Frontend version = 1.0 Services Service Label selectors: version = 1.0 type = Frontend
  25. @francesc Pod frontend Pod type = Frontend version = 1.0

    Pod type = Frontend version = 1.0 Services Service Label selectors: version = 1.0 type = Frontend Pod type = Frontend version = 2.0
  26. @francesc Pod frontend Pod type = Frontend version = 1.0

    Pod type = Frontend version = 1.0 Services Service Label selectors: type = Frontend Pod type = Frontend version = 2.0
  27. @francesc gRPC goals Enable developers to build micro- service-based applications

    Build an open source, standards-based, best-of-breed, feature-rich RPC system Create easy-to-use, efficient and idiomatic libraries micro-services performant and scalable efficient and idiomatic Provide a performant and scalable RPC framework
  28. @francesc IDL to describe the API Automatically generated servers and

    clients in 10+ languages Takes advantage of feature set of HTTP/2 Lightweight open connections Point to point Streaming! Bidirectional streaming! gRPC in a nutshell
  29. @francesc Getting Started Define a service in a .proto file

    using Protocol Buffers IDL Generate server and client code using the protocol buffer compiler Use the gRPC API to write a simple client and server for your service in the languages of your choice
  30. @francesc gRPC Language Support Implementations - C core - Native

    bindings in C++, Node.js, Python, Ruby, ObjC, PHP, C# - Java using Netty or OkHttp (+ inProcess for testing) - Go
  31. @francesc RPC Messages The most common use-case is a unary

    request-response RPC Msg1 MsgA Client Server
  32. @francesc Ordered Bidirectional Streaming RPC Msg1 Msg2 Msg3 MsgA MsgB

    Metadata Metadata Metadata Client Server The second most common use-case is sending multiple request or response messages in the context of a single RPC call
  33. • Improve end-user perceived latency • Address the "head of

    line blocking" • Not require multiple connections • Retain the semantics of HTTP/1.1 "HTTP/2 is a protocol designed for low- latency transport of content over the World Wide Web"
  34. @francesc • One TCP connection • Request → Stream ◦

    Streams are multiplexed ◦ Streams are prioritized • Binary framing layer ◦ Prioritization ◦ Flow control ◦ Server push • Header compression HTTP/2 in one slide…
  35. @francesc What are Protocol Buffers? Structured representation of data Google's

    lingua franca for data • 48k+ Message Types • 12k+ Proto files Evolutionary Development Incrementally solved problems, Now used for: • RPC Systems • Persistent Data Storage
  36. @francesc Protocol buffers: • Efficient and compact binary data representation

    • Clear compatibility rules; can easily be extended over time • Generates idiomatic, easy to use classes for many languages • Strongly typed; less error prone Why Protocol Buffers?
  37. @francesc Protocol Buffers language version 3 Specified by syntax =

    “proto3”; proto2 continues to be supported All fields are optional in proto3 No user specified default values No groups (FYI for those that use them) Message Format (proto3) syntax = “proto3”; message Person { string name = 1; int32 id = 2; string email = 3; enum PhoneType { MOBILE = 0; HOME = 1; WORK = 2; } message PhoneNumber { string number = 1; PhoneType type = 2; } repeated PhoneNumber phone = 4; }
  38. @francesc Add new fields without breaking backwards-compatibility old implementations ignore

    the new fields when parsing In proto3 any field can be removed, but don’t renumber existing fields Extensible syntax = “proto3”; message Person { string name = 1; int32 id = 2; string email = 3; address addr = 4; message address { string firstLine = 1; string secondLine = 2; string postalCode = 3; string country = 4; } ... }
  39. Go: golang.org Kubernetes: kubernetes.io Google Container Engine: cloud.google.com/container-engine/ Google Container

    Registry: gcr.io Festival speech synthesis: www.festvox.org/festival gRPC: grpc.io gRPC and Go (talk): talks.golang.org/2015/gotham-grpc.slide Resources