Successfully reported this slideshow.
Your SlideShare is downloading. ×

gRPC & Kubernetes

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Loading in …3
×

Check these out next

1 of 25 Ad

gRPC & Kubernetes

Download to read offline

In this talk we will discuss the use of gRPC to build a microservices-based application on Kubernetes. We’ll firstly focus on the basic concepts of gRPC: protocol buffers, code generation and HTTP 2.0. We’ll then discuss some more intermediate-level features, such as native Kubernetes load balancing, gRPC streaming, error propagation, HTTP tunneling and instrumentation. Finally we’ll touch on some of the newer, exciting developments in the space: middleware and context propagation for distributed tracing, gRPC Web for client-side rich web apps and gogoproto for blazing-fast generated code. This talk is based on my experience building a hosted, Prometheus-based monitoring service, which itself used gRPC for all intra-server communication and runs on Kubernetes. There’ll be live coding, real world examples and discussion of the benefits (and drawbacks) of gRPC.

Presented at GDG Devfest Ukraine 14th Oct 2017.

In this talk we will discuss the use of gRPC to build a microservices-based application on Kubernetes. We’ll firstly focus on the basic concepts of gRPC: protocol buffers, code generation and HTTP 2.0. We’ll then discuss some more intermediate-level features, such as native Kubernetes load balancing, gRPC streaming, error propagation, HTTP tunneling and instrumentation. Finally we’ll touch on some of the newer, exciting developments in the space: middleware and context propagation for distributed tracing, gRPC Web for client-side rich web apps and gogoproto for blazing-fast generated code. This talk is based on my experience building a hosted, Prometheus-based monitoring service, which itself used gRPC for all intra-server communication and runs on Kubernetes. There’ll be live coding, real world examples and discussion of the benefits (and drawbacks) of gRPC.

Presented at GDG Devfest Ukraine 14th Oct 2017.

Advertisement
Advertisement

More Related Content

Slideshows for you (20)

Similar to gRPC & Kubernetes (20)

Advertisement

Recently uploaded (20)

Advertisement

gRPC & Kubernetes

  1. 1. & Tom Wilkie, GDG DevFest Ukraine, Oct 2017 tom@kausal.co @tom_wilkie github.com/tomwilkie
  2. 2. • Founder Kausal, “transforming observability” • Prometheus developer • Home brewer Previously: • Worked on Kubernetes & Prometheus at Weaveworks • SRE for Google Analytics • Founder/CTO at Acunu, worked on Cassandra
  3. 3. Introduction What is gRPC? What makes it different? Example Hello World! Scratching the surface… Load balancing; Error propagation; Instrumentation… Advanced Topics Distributed tracing; gogoprotobuf…
  4. 4. Introduction
  5. 5. type request struct { Name string `json:"name"` } type response struct { Message string `json:"message"` } func server(addr string) { http.Handle("/greeter", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { var req request if err := json.NewDecoder(r.Body).Decode(&req); err != nil { http.Error(w, err.Error(), http.StatusBadRequest) return } res := response{ Message: "Hello " + req.Name, } if err := json.NewEncoder(w).Encode(&res); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } })) log.Fatalf("listen err: %v", http.ListenAndServe(addr, nil)) } func client(address, name string) { req := request{ Name: name, } var buf bytes.Buffer if err := json.NewEncoder(&buf).Encode(req); err != nil { log.Fatalf("encoding error: %v", err) } resp, err := http.Post(address, "application/json", &buf) if err != nil { log.Fatalf("failed to post: %v", err) } defer resp.Body.Close() if resp.StatusCode/100 != 2 { log.Fatalf("request error: %d", resp.StatusCode) } var res response if err := json.NewDecoder(resp.Body).Decode(&res); err != log.Fatalf("decoding error: %v", err) } fmt.Println(res.Message) } Have you ever had to write code like this?
  6. 6. gRPC is here to save you…
  7. 7. syntax = “proto3”; package hello; option go_package = "main"; service Greeter { rpc SayHello (HelloRequest) returns (HelloReply) {} } message HelloRequest { string name = 1; } message HelloReply { string message = 1; }
  8. 8. Everything Old Is New Again • 1991: CORBA • 1997: Java RMI • 1999: SOAP & WSDL • 2000: REST HTTP/JSON • 2008: Protocol Buffers • 2009: Thrift • 2015: gRPC
  9. 9. HTTP/2http://http2demo.io https://www.nginx.com/blog/7-tips-for-faster-http2-performance/
  10. 10. Idiomatic support for 10 languages C/C++ C#
  11. 11. Who is using gRPC?
  12. 12. Example
  13. 13. Scratching the surface…
  14. 14. KubeResolver (I) Client Pod Pods for service B Service B
  15. 15. KubeResolver (II) Client Pod Pods for service B https://github.com/sercand/kuberesolver
  16. 16. KubeResolver (III) balancer := kuberesolver.NewWithNamespace(namespace) address := fmt.Sprintf("kubernetes://%s:%s", service, port) dialOptions := []grpc.DialOption{} conn, err := grpc.Dial( address, balancer.DialOption(), grpc.WithInsecure())
  17. 17. HTTP over gRPC (I)https://www.weave.works/turtles-way-http-grpc/ Reverse Proxy BackendClient HTTP gRPC
  18. 18. HTTP over gRPC (II) message HTTPRequest { string method = 1; string url = 2; repeated Header headers = 3; bytes body = 4; } message HTTPResponse { int32 Code = 1; repeated Header headers = 2; bytes body = 3; } https://github.com/weaveworks/common/tree/master/httpgrpc
  19. 19. Middleware grpcMiddleware := []grpc.UnaryServerInterceptor{ middleware.ServerLoggingInterceptor, middleware.ServerInstrumentInterceptor(requestDuration), otgrpc.OpenTracingServerInterceptor(opentracing.GlobalTracer()), } grpcServer := grpc.NewServer( grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer( grpcMiddleware…, )), ) https://github.com/weaveworks/common/blob/master/middleware/grpc_instrumentation.go
  20. 20. Instrumentation
  21. 21. Advanced Topics
  22. 22. Advanced Topics • gRPC Streaming • Custom Error Propagation • Distributed Tracing • gogoproto • Authentication • Timeouts • Istio
  23. 23. Thanks! Questions?

×