SlideShare uma empresa Scribd logo
1 de 40
Baixar para ler offline
Running gRPC Services
for Serving Legacy RESTful API on
Kubernetes
Who We Are
Sungwon Lee / Whale
Buzzvil Chief Architect
Hoseong Hwang / Liam
Buzzvil DevOps Lead
Why?
Why did we choose gRPC?
Why do we still need to support REST API?
Why microservices architecture?
There are so many
domains and stakeholders
in ad-tech industry.
Why gRPC?
Performance matters
Multiple services increases network latency
Ad request should be done within 100ms
API-first Approach
Need to support polyglot
IDL(Interface Definition Language) required
gRPC is great, but..
We still need to support legacy RESTful JSON API
There are partners
using the legacy APIs
REST APIs:
mostly beloved
API protocol
B2B business
Support both gRPC/REST protocols
Build a server for transcoding?
gRPC ServerREST JSON
Transcoding
server
Client
Expensive maintenance cost
1. Parse JSON request
2. Transform JSON to gRPC
Request
3. Send request to gRPC Server
4. Transcode gRPC response to
JSON format
5. Send a response to the client
It seems familiar!
Istio Service Mesh
Moving to Microservices
Micoservices grow in size and complexity
Difficult to understand and manage
Service Mesh
Detach network logic from business logic
Monolythic Microservice
Microservice Proxy
Microservice Proxy
Istio Service Mesh
Let’s Try It !
Setup Protobuf for Custom Routes
Setup Istio/EnvoyFilter for gRPC JSON transcoder
Setup Protocol Buffers
service CalendarApi {
rpc ListEvents(ListEventsRequest) returns (ListEventsResponse);
// ...
}
The easiest way: Do nothing.
Transcoder will handle it automatically.
Setup Protocol Buffers (Cont.)
package buzzvil.calendar.v1;
service CalendarApi {
rpc ListEvents(ListEventsRequest) returns (ListEventsResponse);
}
$ curl -X POST https://host.here/buzzvil.calendar.v1.CalendarApi/ListEvents
=
POST /<package>.<service>/<method>
Setup Protocol Buffers (Cont.)
package buzzvil.calendar.v1;
service CalendarApi {
rpc ListEvents(ListEventsRequest) returns (ListEventsResponse) {
option (google.api.http) = { get: "/v1/events" };
}
}
Custom routes: google.api.http annotation
$ curl -X GET https://host.here/v1/events
Setup Protocol Buffers (Cont.)
Parameters
service CalendarApi {
rpc UpdateEvent(UpdateEventRequest)
returns (Event) {
option (google.api.http) = {
put: "/v1/events/{event.id}",
body: "event"
};
}
}
message Event {
int64 id = 1;
string name = 2;
}
message UpdateEventRequest {
Event event = 1;
}
Setup Envoy Proxy
Let’s try Istio /
EnvoyFilter to setup
envoy sidecar proxy
Setup Envoy Proxy (Cont.)
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: example-transcoder
namespace: example-namespace
spec:
workloadLabels:
...
filters:
- listenerMatch:
listenerType: SIDECAR_INBOUND
filterName: envoy.grpc_json_transcoder
filterType: HTTP
filterConfig:
proto_descriptor: “path/to/bin”
match_incoming_request_route: True
auto_mapping: False
services:
- buzzvil.calendar.v1.CalendarApi
filterName: envoy.grpc_json_transcoder
match_incoming_request_route: True
Services:
- buzzvil.calendar.v1.CalendarApi
Apply grpc_json_transcoder
filter to the services
Use the specified route
Setup Envoy Proxy (Cont.)
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: example-transcoder
namespace: example-namespace
spec:
workloadLabels:
...
filters:
- listenerMatch:
listenerType: SIDECAR_INBOUND
filterName: envoy.grpc_json_transcoder
filterType: HTTP
filterConfig:
proto_descriptor: “path/to/bin”
match_incoming_request_route: True
auto_mapping: False
services:
- buzzvil.calendar.v1.CalendarApi
Proto Descriptor
Envoy has to know the proto descriptor of
your gRPC service in order to the
transcoding.
$ protoc -I$(GOOGLEAPIS_DIR) -I. 
--include_imports 
--include_source_info 
--descriptor_set_out=proto.pb 
test/proto/bookstore.proto
proto_descriptor: “path/to/bin”
Setup Envoy Proxy (Cont.)
Proto Descriptor Path
proto_descriptor: “generated/file/path/proto.pb”
proto_descriptor_bin: Cr15ChVnb29nbGUvYXBpL2h0dHAucHJvdG8SCm...
Proto Descriptor Bin
$ cat proto.pb | openssl base64 -A
Encode proto descriptor using base64 encoding,
and set the value in yaml file
Start the Service
$ kubectl apply -f 
blog.yaml
Setup Gateway
$ kubectl apply -f 
blog-gateway.yaml
Setup Transcoder
$ kubectl apply -f 
blog-transcoder.yaml
Handle gRPC Request
Handle JSON Request
Deploying service using transcoding
Protocol Buffer Artifact Pipeline
Releasing new API version using Helm
API Changes Over Time
message Post {
int32 id = 1;
string title = 2;
string body = 3;
repeated string tags = 4;
google.protobuf.Timestamp created_at = 5;
}
Service spec changes over time
● Additional field to message, new RPC
● New package version
● Beware of backward incompatible changes!(renaming, changing type, removing field, …)
message Post {
int32 id = 1;
string title = 2;
string body = 3;
repeated string tags = 4;
google.protobuf.Timestamp created_at = 5;
string featured_image_url = 6;
}
Deploying EnvoyFilter
proto_descriptor should be updated whenever
protocol buffer is changed.
● proto_descriptor: expect *.pb descriptor
to exist on file system → volumeMount to
istio-proxy(sidecar) container
● proto_descriptor_bin: embed
base64-encoded *.pb descriptor content
directly into EnvoyFilter
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: blog-transcoder
namespace: blog
spec:
workloadLabels:
...
filters:
- listenerMatch:
listenerType: SIDECAR_INBOUND
filterName: envoy.grpc_json_transcoder
filterType: HTTP
filterConfig:
proto_descriptor: “blog.pb”
match_incoming_request_route: True
auto_mapping: False
services:
- blog.BlogService
Deploying EnvoyFilter (Cont.)
● proto_descriptor
○ Ensuring *.pb descriptor file is mounted to istio-proxy container is not easy
○ Automatic sidecar injection from istio-sidecar-injector is not dynamic
enough(mounted volume contains all pb descriptors)
○ Hard to control deployment timing
● proto_descriptor_bin
○ Lack of readability
○ No volume dependency
○ New transcoding configuration is applied as soon as EnvoyFilter is updated
Protocol Buffer Artifact Pipeline
Language-specific gRPC Artifacts should be created whenever API is updated
$ protoc -I (GOOGLE_APIS_DIR)
--python_out=..
--go_out=..
--js_out=..
./blog.proto
blog.proto
Private repository
Private pypi server
Private npm registry
+ rubygems, maven, ...Lint, Breaking Changes warning, ...
comment.
proto
user.proto
├── Jenkinsfile
├── Makefile
└── packages
├── blog
│ ├── blog.proto
│ └── package.json
└── user
├── user.proto
└── package.json
Mono Repository Approach
● Create CI pipeline that generates & publishes language-specific artifacts
● Common CI checks(lint, breaking changes warning) run for changed proto files
● Reduced boilerplate!
● Use lerna(node package) to bump versions of each API
Generating protobuf descriptor artifact:
protoc --include_imports
--include_source_info
--descriptor_set_out=blog.pb
Helm as Configuration Management Tool
Helm
● Already using helm for managing cluster-level services
(ingress controller, EFK, prometheus, grafana, …)
● Hosting private registry is easy(chartmuseum, object storage, ..)
● Easy CI pipeline setup
● CRDs can also be handled(VirtualService, EnvoyFilter, ...)
Helm Chart for gRPC Transcoding
apiVersion: apps/v1
kind: Deployment
metadata:
...
spec:
...
containers:
- name: {{ .Chart.Name }}
...
ports:
- name: grpc
containerPort: 9000
protocol: TCP
apiVersion: v1
kind: Service
metadata:
...
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: grpc
protocol: TCP
name: grpc
selector:
{{- include "blog.matchLabels" . | nindent 4 }}
Istio looks for port named grpc or any name prefixed with grpc-
Helm Chart for gRPC Transcoding
New Helm release will update
proto_descriptor_bin
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: {{ include "blog.fullname" . }}-transcoder
namespace: {{ .Release.Namespace }}
spec:
workloadLabels:
{{- include "blog.matchLabels" . | nindent 4 }}
filters:
- listenerMatch:
listenerType: SIDECAR_INBOUND
filterName: envoy.grpc_json_transcoder
filterType: HTTP
filterConfig:
proto_descriptor_bin: {{ .Values.protoDescriptorBin }}
match_incoming_request_route: True
auto_mapping: False
services:
- blog.v1.Blog
print_options:
always_print_primitive_fields: True
preserve_proto_field_names: True
Releasing New API Version
Using Helm CLI:
$ helm upgrade RELEASE -f values.prod.yaml -f
proto_descriptor.yaml --set image.tag=IMAGE_TAG repo/blog
Helm Chart
values.prod.yaml proto_descriptor.yaml
image:
tag: dkr.registry/blog:954ade7
secret:
DATABASE_URL: mysql://xx:yy@db:3306
WEB_CONCURRENCY: 5
proto_descriptor_bin: Cr15ChVnb29n
bGUvYXBpL2h0dHAucHJvdG...
*We internally use Spinnaker to deploy helm chart based services
● 503 status code is returned when requested to non-mapped path
● kubectl port-forward didn’t work for testing out REST APIs
● Arbitrary(non-JSON) message can be also supported by using
google.api.HttpBody
● grpc-status, grpc-message headers in response are useful when
debugging
Pitfalls & Tips
Conclusion
● It takes initial effort to build pipeline, but after then it becomes easy to
develop any gRPC service that supports JSON transcoding
● You can develop gRPC services while allowing other teams time to transition
● API-First approach becomes standard throughout the organization
● Over time, initial setup cost pays off
Resources
Sample Repo - https://github.com/Buzzvil/grpc-json-transcoding-example/
● https://medium.com/@ssowonny/grpc를-쓰면-rest가-공짜-19e3a6bed4a9
● https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/
grpc_json_transcoder_filter
● https://blog.envoyproxy.io/envoy-and-grpc-web-a-fresh-new-alternative-to-res
t-6504ce7eb880
● https://medium.com/google-cloud/grpc-transcoding-e101cc53d51d
● https://blog.jdriven.com/2018/11/transcoding-grpc-to-http-json-using-envoy/
● https://medium.com/building-ibotta/building-a-scaleable-protocol-buffers-grp
c-artifact-pipeline-5265c5118c9d
Thank You!
Sungwon Lee (Whale)
whale.lee@buzzvil.com
GitHub & Twitter @ssowonny
Hoseong Hwang (Liam)
liam.hwang@buzzvil.com
GitHub & Twitter @thefron
Running gRPC Services for Serving Legacy API on Kubernetes

Mais conteúdo relacionado

Mais procurados

RedisConf18 - Redis at LINE - 25 Billion Messages Per Day
RedisConf18 - Redis at LINE - 25 Billion Messages Per DayRedisConf18 - Redis at LINE - 25 Billion Messages Per Day
RedisConf18 - Redis at LINE - 25 Billion Messages Per Day
Redis Labs
 

Mais procurados (20)

Netflix Data Pipeline With Kafka
Netflix Data Pipeline With KafkaNetflix Data Pipeline With Kafka
Netflix Data Pipeline With Kafka
 
Rest api standards and best practices
Rest api standards and best practicesRest api standards and best practices
Rest api standards and best practices
 
The automation challenge: Kubernetes Operators vs Helm Charts
The automation challenge: Kubernetes Operators vs Helm ChartsThe automation challenge: Kubernetes Operators vs Helm Charts
The automation challenge: Kubernetes Operators vs Helm Charts
 
NiFi Best Practices for the Enterprise
NiFi Best Practices for the EnterpriseNiFi Best Practices for the Enterprise
NiFi Best Practices for the Enterprise
 
Cryptography for Java Developers: Nakov jProfessionals (Jan 2019)
Cryptography for Java Developers: Nakov jProfessionals (Jan 2019)Cryptography for Java Developers: Nakov jProfessionals (Jan 2019)
Cryptography for Java Developers: Nakov jProfessionals (Jan 2019)
 
RedisConf18 - Redis at LINE - 25 Billion Messages Per Day
RedisConf18 - Redis at LINE - 25 Billion Messages Per DayRedisConf18 - Redis at LINE - 25 Billion Messages Per Day
RedisConf18 - Redis at LINE - 25 Billion Messages Per Day
 
How Netflix Tunes EC2 Instances for Performance
How Netflix Tunes EC2 Instances for PerformanceHow Netflix Tunes EC2 Instances for Performance
How Netflix Tunes EC2 Instances for Performance
 
Web API Basics
Web API BasicsWeb API Basics
Web API Basics
 
Black and Blue APIs: Attacker's and Defender's View of API Vulnerabilities
Black and Blue APIs: Attacker's and Defender's View of API VulnerabilitiesBlack and Blue APIs: Attacker's and Defender's View of API Vulnerabilities
Black and Blue APIs: Attacker's and Defender's View of API Vulnerabilities
 
File Format Benchmark - Avro, JSON, ORC and Parquet
File Format Benchmark - Avro, JSON, ORC and ParquetFile Format Benchmark - Avro, JSON, ORC and Parquet
File Format Benchmark - Avro, JSON, ORC and Parquet
 
Open source computer vision with TensorFlow, Apache MiniFi, Apache NiFi, Open...
Open source computer vision with TensorFlow, Apache MiniFi, Apache NiFi, Open...Open source computer vision with TensorFlow, Apache MiniFi, Apache NiFi, Open...
Open source computer vision with TensorFlow, Apache MiniFi, Apache NiFi, Open...
 
Data Federation with Apache Spark
Data Federation with Apache SparkData Federation with Apache Spark
Data Federation with Apache Spark
 
CMIS and Apache Chemistry (ApacheCon 2010)
CMIS and Apache Chemistry (ApacheCon 2010) CMIS and Apache Chemistry (ApacheCon 2010)
CMIS and Apache Chemistry (ApacheCon 2010)
 
Ozone- Object store for Apache Hadoop
Ozone- Object store for Apache HadoopOzone- Object store for Apache Hadoop
Ozone- Object store for Apache Hadoop
 
ELK introduction
ELK introductionELK introduction
ELK introduction
 
EVOLVE'13 | Keynote | Roy Fielding
EVOLVE'13 | Keynote | Roy FieldingEVOLVE'13 | Keynote | Roy Fielding
EVOLVE'13 | Keynote | Roy Fielding
 
Elk
Elk Elk
Elk
 
AWSKRUG DS - 데이터 엔지니어가 실무에서 맞닥뜨리는 문제들
AWSKRUG DS - 데이터 엔지니어가 실무에서 맞닥뜨리는 문제들AWSKRUG DS - 데이터 엔지니어가 실무에서 맞닥뜨리는 문제들
AWSKRUG DS - 데이터 엔지니어가 실무에서 맞닥뜨리는 문제들
 
Bulk Export Tool for Alfresco
Bulk Export Tool for AlfrescoBulk Export Tool for Alfresco
Bulk Export Tool for Alfresco
 
Building Your Data Streams for all the IoT
Building Your Data Streams for all the IoTBuilding Your Data Streams for all the IoT
Building Your Data Streams for all the IoT
 

Semelhante a Running gRPC Services for Serving Legacy API on Kubernetes

Semelhante a Running gRPC Services for Serving Legacy API on Kubernetes (20)

Driving containerd operations with gRPC
Driving containerd operations with gRPCDriving containerd operations with gRPC
Driving containerd operations with gRPC
 
Deep Dive into SpaceONE
Deep Dive into SpaceONEDeep Dive into SpaceONE
Deep Dive into SpaceONE
 
Ingress overview
Ingress overviewIngress overview
Ingress overview
 
High quality ap is with api platform
High quality ap is with api platformHigh quality ap is with api platform
High quality ap is with api platform
 
Introduction to Kubernetes
Introduction to KubernetesIntroduction to Kubernetes
Introduction to Kubernetes
 
Kubernetes API code-base tour
Kubernetes API code-base tourKubernetes API code-base tour
Kubernetes API code-base tour
 
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
 
CocoaConf: The Language of Mobile Software is APIs
CocoaConf: The Language of Mobile Software is APIsCocoaConf: The Language of Mobile Software is APIs
CocoaConf: The Language of Mobile Software is APIs
 
OpenShift Meetup - Tokyo - Service Mesh and Serverless Overview
OpenShift Meetup - Tokyo - Service Mesh and Serverless OverviewOpenShift Meetup - Tokyo - Service Mesh and Serverless Overview
OpenShift Meetup - Tokyo - Service Mesh and Serverless Overview
 
Fast and Reliable Swift APIs with gRPC
Fast and Reliable Swift APIs with gRPCFast and Reliable Swift APIs with gRPC
Fast and Reliable Swift APIs with gRPC
 
Creating Great REST and gRPC API Experiences (in Swift)
Creating Great REST and gRPC API Experiences (in Swift)Creating Great REST and gRPC API Experiences (in Swift)
Creating Great REST and gRPC API Experiences (in Swift)
 
KubeCon EU 2016: Creating an Advanced Load Balancing Solution for Kubernetes ...
KubeCon EU 2016: Creating an Advanced Load Balancing Solution for Kubernetes ...KubeCon EU 2016: Creating an Advanced Load Balancing Solution for Kubernetes ...
KubeCon EU 2016: Creating an Advanced Load Balancing Solution for Kubernetes ...
 
What I learned about APIs in my first year at Google
What I learned about APIs in my first year at GoogleWhat I learned about APIs in my first year at Google
What I learned about APIs in my first year at Google
 
SVQdotNET: Building APIs with OpenApi
SVQdotNET: Building APIs with OpenApiSVQdotNET: Building APIs with OpenApi
SVQdotNET: Building APIs with OpenApi
 
Mastering Microservices with Kong (DevoxxUK 2019)
Mastering Microservices with Kong (DevoxxUK 2019)Mastering Microservices with Kong (DevoxxUK 2019)
Mastering Microservices with Kong (DevoxxUK 2019)
 
From System Engineer to Gopher
From System Engineer to GopherFrom System Engineer to Gopher
From System Engineer to Gopher
 
Creating microservices architectures using node.js and Kubernetes
Creating microservices architectures using node.js and KubernetesCreating microservices architectures using node.js and Kubernetes
Creating microservices architectures using node.js and Kubernetes
 
Itb 2021 - Bulding Quick APIs by Gavin Pickin
Itb 2021 - Bulding Quick APIs by Gavin PickinItb 2021 - Bulding Quick APIs by Gavin Pickin
Itb 2021 - Bulding Quick APIs by Gavin Pickin
 
Going FaaSter, Functions as a Service at Netflix
Going FaaSter, Functions as a Service at NetflixGoing FaaSter, Functions as a Service at Netflix
Going FaaSter, Functions as a Service at Netflix
 
KNATIVE - DEPLOY, AND MANAGE MODERN CONTAINER-BASED SERVERLESS WORKLOADS
KNATIVE - DEPLOY, AND MANAGE MODERN CONTAINER-BASED SERVERLESS WORKLOADSKNATIVE - DEPLOY, AND MANAGE MODERN CONTAINER-BASED SERVERLESS WORKLOADS
KNATIVE - DEPLOY, AND MANAGE MODERN CONTAINER-BASED SERVERLESS WORKLOADS
 

Último

Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
dharasingh5698
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 

Último (20)

Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 

Running gRPC Services for Serving Legacy API on Kubernetes

  • 1.
  • 2. Running gRPC Services for Serving Legacy RESTful API on Kubernetes
  • 3. Who We Are Sungwon Lee / Whale Buzzvil Chief Architect Hoseong Hwang / Liam Buzzvil DevOps Lead
  • 4. Why? Why did we choose gRPC? Why do we still need to support REST API?
  • 5. Why microservices architecture? There are so many domains and stakeholders in ad-tech industry.
  • 6. Why gRPC? Performance matters Multiple services increases network latency Ad request should be done within 100ms API-first Approach Need to support polyglot IDL(Interface Definition Language) required
  • 7. gRPC is great, but.. We still need to support legacy RESTful JSON API There are partners using the legacy APIs REST APIs: mostly beloved API protocol B2B business
  • 8. Support both gRPC/REST protocols Build a server for transcoding? gRPC ServerREST JSON Transcoding server Client Expensive maintenance cost 1. Parse JSON request 2. Transform JSON to gRPC Request 3. Send request to gRPC Server 4. Transcode gRPC response to JSON format 5. Send a response to the client It seems familiar!
  • 9. Istio Service Mesh Moving to Microservices Micoservices grow in size and complexity Difficult to understand and manage Service Mesh Detach network logic from business logic Monolythic Microservice Microservice Proxy Microservice Proxy
  • 11.
  • 12. Let’s Try It ! Setup Protobuf for Custom Routes Setup Istio/EnvoyFilter for gRPC JSON transcoder
  • 13. Setup Protocol Buffers service CalendarApi { rpc ListEvents(ListEventsRequest) returns (ListEventsResponse); // ... } The easiest way: Do nothing. Transcoder will handle it automatically.
  • 14. Setup Protocol Buffers (Cont.) package buzzvil.calendar.v1; service CalendarApi { rpc ListEvents(ListEventsRequest) returns (ListEventsResponse); } $ curl -X POST https://host.here/buzzvil.calendar.v1.CalendarApi/ListEvents = POST /<package>.<service>/<method>
  • 15. Setup Protocol Buffers (Cont.) package buzzvil.calendar.v1; service CalendarApi { rpc ListEvents(ListEventsRequest) returns (ListEventsResponse) { option (google.api.http) = { get: "/v1/events" }; } } Custom routes: google.api.http annotation $ curl -X GET https://host.here/v1/events
  • 16. Setup Protocol Buffers (Cont.) Parameters service CalendarApi { rpc UpdateEvent(UpdateEventRequest) returns (Event) { option (google.api.http) = { put: "/v1/events/{event.id}", body: "event" }; } } message Event { int64 id = 1; string name = 2; } message UpdateEventRequest { Event event = 1; }
  • 17. Setup Envoy Proxy Let’s try Istio / EnvoyFilter to setup envoy sidecar proxy
  • 18. Setup Envoy Proxy (Cont.) apiVersion: networking.istio.io/v1alpha3 kind: EnvoyFilter metadata: name: example-transcoder namespace: example-namespace spec: workloadLabels: ... filters: - listenerMatch: listenerType: SIDECAR_INBOUND filterName: envoy.grpc_json_transcoder filterType: HTTP filterConfig: proto_descriptor: “path/to/bin” match_incoming_request_route: True auto_mapping: False services: - buzzvil.calendar.v1.CalendarApi filterName: envoy.grpc_json_transcoder match_incoming_request_route: True Services: - buzzvil.calendar.v1.CalendarApi Apply grpc_json_transcoder filter to the services Use the specified route
  • 19. Setup Envoy Proxy (Cont.) apiVersion: networking.istio.io/v1alpha3 kind: EnvoyFilter metadata: name: example-transcoder namespace: example-namespace spec: workloadLabels: ... filters: - listenerMatch: listenerType: SIDECAR_INBOUND filterName: envoy.grpc_json_transcoder filterType: HTTP filterConfig: proto_descriptor: “path/to/bin” match_incoming_request_route: True auto_mapping: False services: - buzzvil.calendar.v1.CalendarApi Proto Descriptor Envoy has to know the proto descriptor of your gRPC service in order to the transcoding. $ protoc -I$(GOOGLEAPIS_DIR) -I. --include_imports --include_source_info --descriptor_set_out=proto.pb test/proto/bookstore.proto proto_descriptor: “path/to/bin”
  • 20. Setup Envoy Proxy (Cont.) Proto Descriptor Path proto_descriptor: “generated/file/path/proto.pb” proto_descriptor_bin: Cr15ChVnb29nbGUvYXBpL2h0dHAucHJvdG8SCm... Proto Descriptor Bin $ cat proto.pb | openssl base64 -A Encode proto descriptor using base64 encoding, and set the value in yaml file
  • 21. Start the Service $ kubectl apply -f blog.yaml
  • 22. Setup Gateway $ kubectl apply -f blog-gateway.yaml
  • 23. Setup Transcoder $ kubectl apply -f blog-transcoder.yaml
  • 26. Deploying service using transcoding Protocol Buffer Artifact Pipeline Releasing new API version using Helm
  • 27. API Changes Over Time message Post { int32 id = 1; string title = 2; string body = 3; repeated string tags = 4; google.protobuf.Timestamp created_at = 5; } Service spec changes over time ● Additional field to message, new RPC ● New package version ● Beware of backward incompatible changes!(renaming, changing type, removing field, …) message Post { int32 id = 1; string title = 2; string body = 3; repeated string tags = 4; google.protobuf.Timestamp created_at = 5; string featured_image_url = 6; }
  • 28. Deploying EnvoyFilter proto_descriptor should be updated whenever protocol buffer is changed. ● proto_descriptor: expect *.pb descriptor to exist on file system → volumeMount to istio-proxy(sidecar) container ● proto_descriptor_bin: embed base64-encoded *.pb descriptor content directly into EnvoyFilter apiVersion: networking.istio.io/v1alpha3 kind: EnvoyFilter metadata: name: blog-transcoder namespace: blog spec: workloadLabels: ... filters: - listenerMatch: listenerType: SIDECAR_INBOUND filterName: envoy.grpc_json_transcoder filterType: HTTP filterConfig: proto_descriptor: “blog.pb” match_incoming_request_route: True auto_mapping: False services: - blog.BlogService
  • 29. Deploying EnvoyFilter (Cont.) ● proto_descriptor ○ Ensuring *.pb descriptor file is mounted to istio-proxy container is not easy ○ Automatic sidecar injection from istio-sidecar-injector is not dynamic enough(mounted volume contains all pb descriptors) ○ Hard to control deployment timing ● proto_descriptor_bin ○ Lack of readability ○ No volume dependency ○ New transcoding configuration is applied as soon as EnvoyFilter is updated
  • 30. Protocol Buffer Artifact Pipeline Language-specific gRPC Artifacts should be created whenever API is updated $ protoc -I (GOOGLE_APIS_DIR) --python_out=.. --go_out=.. --js_out=.. ./blog.proto blog.proto Private repository Private pypi server Private npm registry + rubygems, maven, ...Lint, Breaking Changes warning, ... comment. proto user.proto
  • 31. ├── Jenkinsfile ├── Makefile └── packages ├── blog │ ├── blog.proto │ └── package.json └── user ├── user.proto └── package.json Mono Repository Approach ● Create CI pipeline that generates & publishes language-specific artifacts ● Common CI checks(lint, breaking changes warning) run for changed proto files ● Reduced boilerplate! ● Use lerna(node package) to bump versions of each API Generating protobuf descriptor artifact: protoc --include_imports --include_source_info --descriptor_set_out=blog.pb
  • 32. Helm as Configuration Management Tool Helm ● Already using helm for managing cluster-level services (ingress controller, EFK, prometheus, grafana, …) ● Hosting private registry is easy(chartmuseum, object storage, ..) ● Easy CI pipeline setup ● CRDs can also be handled(VirtualService, EnvoyFilter, ...)
  • 33. Helm Chart for gRPC Transcoding apiVersion: apps/v1 kind: Deployment metadata: ... spec: ... containers: - name: {{ .Chart.Name }} ... ports: - name: grpc containerPort: 9000 protocol: TCP apiVersion: v1 kind: Service metadata: ... spec: type: {{ .Values.service.type }} ports: - port: {{ .Values.service.port }} targetPort: grpc protocol: TCP name: grpc selector: {{- include "blog.matchLabels" . | nindent 4 }} Istio looks for port named grpc or any name prefixed with grpc-
  • 34. Helm Chart for gRPC Transcoding New Helm release will update proto_descriptor_bin apiVersion: networking.istio.io/v1alpha3 kind: EnvoyFilter metadata: name: {{ include "blog.fullname" . }}-transcoder namespace: {{ .Release.Namespace }} spec: workloadLabels: {{- include "blog.matchLabels" . | nindent 4 }} filters: - listenerMatch: listenerType: SIDECAR_INBOUND filterName: envoy.grpc_json_transcoder filterType: HTTP filterConfig: proto_descriptor_bin: {{ .Values.protoDescriptorBin }} match_incoming_request_route: True auto_mapping: False services: - blog.v1.Blog print_options: always_print_primitive_fields: True preserve_proto_field_names: True
  • 35. Releasing New API Version Using Helm CLI: $ helm upgrade RELEASE -f values.prod.yaml -f proto_descriptor.yaml --set image.tag=IMAGE_TAG repo/blog Helm Chart values.prod.yaml proto_descriptor.yaml image: tag: dkr.registry/blog:954ade7 secret: DATABASE_URL: mysql://xx:yy@db:3306 WEB_CONCURRENCY: 5 proto_descriptor_bin: Cr15ChVnb29n bGUvYXBpL2h0dHAucHJvdG... *We internally use Spinnaker to deploy helm chart based services
  • 36. ● 503 status code is returned when requested to non-mapped path ● kubectl port-forward didn’t work for testing out REST APIs ● Arbitrary(non-JSON) message can be also supported by using google.api.HttpBody ● grpc-status, grpc-message headers in response are useful when debugging Pitfalls & Tips
  • 37. Conclusion ● It takes initial effort to build pipeline, but after then it becomes easy to develop any gRPC service that supports JSON transcoding ● You can develop gRPC services while allowing other teams time to transition ● API-First approach becomes standard throughout the organization ● Over time, initial setup cost pays off
  • 38. Resources Sample Repo - https://github.com/Buzzvil/grpc-json-transcoding-example/ ● https://medium.com/@ssowonny/grpc를-쓰면-rest가-공짜-19e3a6bed4a9 ● https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/ grpc_json_transcoder_filter ● https://blog.envoyproxy.io/envoy-and-grpc-web-a-fresh-new-alternative-to-res t-6504ce7eb880 ● https://medium.com/google-cloud/grpc-transcoding-e101cc53d51d ● https://blog.jdriven.com/2018/11/transcoding-grpc-to-http-json-using-envoy/ ● https://medium.com/building-ibotta/building-a-scaleable-protocol-buffers-grp c-artifact-pipeline-5265c5118c9d
  • 39. Thank You! Sungwon Lee (Whale) whale.lee@buzzvil.com GitHub & Twitter @ssowonny Hoseong Hwang (Liam) liam.hwang@buzzvil.com GitHub & Twitter @thefron