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

Building a Scalable Python gRPC Service using Kubernetes

Building a Scalable Python gRPC Service using Kubernetes

Ian Lewis

June 17, 2015
Tweet

More Decks by Ian Lewis

Other Decks in Technology

Transcript

  1. Building a Scalable Python
    gRPC Service using Kubernetes
    @ PyCon APAC
    Ian Lewis, Developer Advocate

    View full-size slide

  2. Ian Lewis
    Developer Advocate
    Google Cloud Platform
    google.com/+IanLewis-hoge
    @IanMLewis

    View full-size slide

  3. gRPC Concepts
    gRPC & Python
    Containers & Kubernetes Concepts
    Running a Kubernetes Service
    Wrap Up
    1
    2
    3
    4
    Agenda
    5

    View full-size slide

  4. Section Slide Template Option 2
    Put your subtitle here. Feel free to pick from the handful of pretty Google colors available to you.
    Make the subtitle something clever. People will think it’s neat.
    gRPC Concepts
    Wait…. RPC? What happened to REST?

    View full-size slide

  5. Remote Procedure Call
    HTTP/2
    Protocol Buffers
    gRPC in a Nutshell

    View full-size slide

  6. ● is binary ( no telnet :( )
    ● is fully multiplexed (fewer connections)
    ● uses header compression to reduce overhead
    ● allows servers to “push” responses
    HTTP/2 ...

    View full-size slide

  7. Protocol Buffers

    View full-size slide

  8. ● are a way to serialize structured data
    ● are binary ( really no love for telnet :( )
    ● can be parsed quickly
    ● are flexible (easy to add new fields, supports addons)
    ● support code generation
    Protocol Buffers ...

    View full-size slide

  9. message Person {
    required string name = 1;
    required int32 id = 2;
    optional string email = 3;
    }
    Protocol Buffers

    View full-size slide

  10. // The greeting service definition.
    service Greeter {
    // Gets my Person data
    rpc GetMe () returns (Person) {}
    }
    Protocol Buffers

    View full-size slide

  11. Section Slide Template Option 2
    Put your subtitle here. Feel free to pick from the handful of pretty Google colors available to you.
    Make the subtitle something clever. People will think it’s neat.
    gRPC & Python
    Python!

    View full-size slide

  12. git clone https://github.com/grpc/grpc.git

    View full-size slide

  13. make shared_c static_c bins/opt/grpc_python_plugin

    View full-size slide

  14. protoc -I ../../protos --python_out=. --grpc_out=. --
    plugin=protoc-gen-
    grpc=/path/to/bins/opt/grpc_python_plugin ../..
    /protos/helloworld.proto
    Generate Code

    View full-size slide

  15. Section Slide Template Option 2
    Put your subtitle here. Feel free to pick from the handful of pretty Google colors available to you.
    Make the subtitle something clever. People will think it’s neat.
    Containers & Kubernetes
    Concepts
    What that thar be?!?!

    View full-size slide

  16. Current Practice

    View full-size slide

  17. Database
    Batch
    processing
    Cache
    Webservers
    Webservers
    Webservers
    Webservers

    View full-size slide

  18. kernel
    libs
    app
    app app
    No isolation
    No namespacing
    Common libs
    Highly coupled apps and OS
    app
    Shared Machines

    View full-size slide

  19. Some isolation
    Expensive and inefficient
    Still highly coupled to the guest OS
    Hard to manage
    app
    libs
    kernel
    libs
    app app
    kernel
    app
    libs
    libs
    kernel
    kernel
    Virtual Machines

    View full-size slide

  20. build and deploy vm images
    ● Curated runtimes
    ● Rich services
    ● Auto-everything
    ● … just add code
    ● Managed collections
    ● Declarative + Dynamic
    Compute as a Continuum
    Platform
    Cluster
    ● Basic atom
    ● Run anything
    VM
    More agility
    More Flexibility
    build and deploy containers build and deploy apps

    View full-size slide

  21. libs
    app
    kernel
    libs
    app
    libs
    app
    libs
    app
    Containers

    View full-size slide

  22. Everything at Google runs in
    containers:
    • Gmail, Web Search, Maps, ...
    • MapReduce, batch, ...
    • GFS, Colossus, ...
    • Even Google Compute Engine:
    VMs in containers!

    View full-size slide

  23. Everything at Google runs in
    containers:
    • Gmail, Web Search, Maps, ...
    • MapReduce, batch, ...
    • GFS, Colossus, ...
    • Even Google Compute Engine:
    VMs in containers!
    We launch over 2 billion
    containers per week.

    View full-size slide

  24. Why containers?
    • Performance
    • Repeatability
    • Isolation
    • Quality of service
    • Accounting
    • Visibility
    • Portability
    A fundamentally different way of
    managing applications

    View full-size slide

  25. Greek for “Helmsman”; also the root of
    the word “Governor”
    • Container orchestrator
    • Runs Docker 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

    View full-size slide

  26. ● 0.18.0 released
    ● 369 contributors
    ● over 8000 github stars
    ● CoreOS
    ● HP
    ● IBM
    ● Mesosphere
    ● Microsoft
    ● Pivotal
    ● Red Hat
    ● SaltStack
    ● VMWare
    ● Binary releases
    ● Logging and monitoring
    ● Richer scheduling
    ○ Labels based constraints
    ○ Smart bin-packing
    ○ Run-to-completion
    ● Updated service model
    ○ IP per service
    ● DNS integration
    Project Partners New
    Introducing Google Container Engine
    Community

    View full-size slide

  27. ● Group of containers
    ● Settings in a template
    ➔ Reuse across environments
    ➔ Repeatable, manageable
    Behavior Benefits
    Pod
    Web Server
    Content
    Management
    Server
    Pods
    more at pod.md

    View full-size slide

  28. Dashboard
    show: FE
    Labels
    ● Metadata with semantic meaning
    ● Membership identifier
    ➔ Allow for intent of many users (e.g. dashboards)
    ➔ Build higher level systems …
    Behavior Benefits
    Pod
    Pod
    frontend
    Pod
    frontend
    Pod Pod
    FE BI, FE v2
    Dashboard
    show: v2
    more at labels.md

    View full-size slide

  29. Replication Controllers
    Behavior Benefits
    Replication
    Controller
    #Pods → 2
    label selector: v1
    Pod
    Pod
    frontend
    Pod
    frontend
    Pod Pod
    v1 v1
    Replication
    Controller
    #Pods → 1
    label selector: v2
    v2
    more at rc.md
    ● Keeps Pods running
    ● Gives direct control of Pod #s
    ➔ Restarts Pods, desired state
    ➔ Fine-grained control for scaling

    View full-size slide

  30. Pod
    Services
    Behavior Benefits
    Pod
    FE FE
    Pod
    FE
    Service
    label selector: Front End
    more at services.md
    ➔ Clients shielded from implementation details
    ➔ Independently control each, build for resiliency
    ● Stable address
    ● Decoupled from Controllers

    View full-size slide

  31. Section Slide Template Option 2
    Put your subtitle here. Feel free to pick from the handful of pretty Google colors available to you.
    Make the subtitle something clever. People will think it’s neat.
    Running a Kubernetes Service
    Steer me ship captain!

    View full-size slide

  32. #pyconapac
    plus.google.com/+IanLewis-hoge
    twitter.com/IanMLewis
    Thank you!

    View full-size slide