Skip to content

Commit 5910869

Browse files
committed
grpc poc working on k8s, using envoy as a sidecar in catalog api
1 parent db00159 commit 5910869

13 files changed

Lines changed: 147 additions & 48 deletions

File tree

docker-compose.override.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ services:
8989
- AzureStorageEnabled=False
9090
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
9191
- OrchestratorType=${ORCHESTRATOR_TYPE}
92+
- GRPC_PORT=81
93+
- PORT=80
9294
ports:
9395
- "5101:80"
9496
- "9101:81"

docker-compose.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,4 @@ services:
240240
- webhooks.api
241241

242242
envoy:
243-
image: envoy:v1
244-
build:
245-
context: src/ApiGateways/Envoy
246-
dockerfile: Dockerfile
243+
image: envoyproxy/envoy

k8s/helm/apigwws/configuration-web-shopping.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,24 @@
66
"DownstreamHostAndPorts": [
77
{
88
"Host": "catalog",
9-
"Port": 80
9+
"Port": 5000
1010
}
1111
],
1212
"UpstreamPathTemplate": "/api/{version}/c/{everything}",
1313
"UpstreamHttpMethod": [ "GET" ]
1414
},
15+
{
16+
"DownstreamPathTemplate": "/api/{version}/{everything}",
17+
"DownstreamScheme": "http",
18+
"DownstreamHostAndPorts": [
19+
{
20+
"Host": "catalog",
21+
"Port": 80
22+
}
23+
],
24+
"UpstreamPathTemplate": "/grpc/{version}/c/{everything}",
25+
"UpstreamHttpMethod": [ "GET" ]
26+
},
1527
{
1628
"DownstreamPathTemplate": "/api/{version}/{everything}",
1729
"DownstreamScheme": "http",
@@ -102,7 +114,7 @@
102114
"DownstreamHostAndPorts": [
103115
{
104116
"Host": "catalog",
105-
"Port": 80
117+
"Port": 5000
106118
}
107119
],
108120
"UpstreamPathTemplate": "/catalog-api/{everything}",
9.13 KB
Binary file not shown.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
admin:
2+
access_log_path: /tmp/admin_access.log
3+
address:
4+
socket_address: { address: 0.0.0.0, port_value: 9901 }
5+
6+
static_resources:
7+
listeners:
8+
- name: listener1
9+
address:
10+
socket_address: { address: 0.0.0.0, port_value: 51051 }
11+
filter_chains:
12+
- filters:
13+
- name: envoy.http_connection_manager
14+
typed_config:
15+
"@type": type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager
16+
stat_prefix: grpc_json
17+
codec_type: AUTO
18+
route_config:
19+
name: local_route
20+
virtual_hosts:
21+
- name: local_service
22+
domains: ["*"]
23+
routes:
24+
- match: { prefix: "/" }
25+
route: { cluster: grpc, timeout: { seconds: 60 } }
26+
http_filters:
27+
- name: envoy.grpc_json_transcoder
28+
config:
29+
proto_descriptor: "/etc/envoy/catalog.proto-descriptor.pb"
30+
services: ["CatalogApi.Catalog"]
31+
print_options:
32+
add_whitespace: true
33+
always_print_primitive_fields: true
34+
always_print_enums_as_ints: false
35+
preserve_proto_field_names: false
36+
- name: envoy.router
37+
38+
clusters:
39+
- name: grpc
40+
connect_timeout: 1.25s
41+
type: logical_dns
42+
lb_policy: round_robin
43+
dns_lookup_family: V4_ONLY
44+
http2_protocol_options: {}
45+
load_assignment:
46+
cluster_name: grpc
47+
endpoints:
48+
- lb_endpoints:
49+
- endpoint:
50+
address:
51+
socket_address:
52+
# WARNING: "docker.for.mac.localhost" has been deprecated from Docker v18.03.0.
53+
# If you're running an older version of Docker, please use "docker.for.mac.localhost" instead.
54+
# Reference: https://docs.docker.com/docker-for-mac/release-notes/#docker-community-edition-18030-ce-mac59-2018-03-26
55+
address: localhost
56+
port_value: 5001

k8s/helm/catalog-api/templates/deployment.yaml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,23 @@ spec:
7373
{{- end }}
7474
ports:
7575
- name: http
76-
containerPort: 80
76+
containerPort: 5000
7777
protocol: TCP
78+
- name: grpc
79+
containerPort: 5001
80+
protocol: TCP
7881
resources:
7982
{{ toYaml .Values.resources | indent 12 }}
83+
- name: envoy-proxy
84+
image: envoyproxy/envoy
85+
imagePullPolicy: IfNotPresent
86+
ports:
87+
- name: envoy
88+
containerPort: 51051
89+
protocol: TCP
90+
volumeMounts:
91+
- name: envoy-config
92+
mountPath: /etc/envoy
8093
{{- with .Values.nodeSelector }}
8194
nodeSelector:
8295
{{ toYaml . | indent 8 }}
@@ -89,4 +102,13 @@ spec:
89102
tolerations:
90103
{{ toYaml . | indent 8 }}
91104
{{- end }}
105+
volumes:
106+
- name: envoy-config
107+
configMap:
108+
name: envoy-{{ $name }}
109+
items:
110+
- key: _envoy.yaml
111+
path: envoy.yaml
112+
- key: _catalog.proto-descriptor.pb
113+
path: catalog.proto-descriptor.pb
92114

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{{- $name := include "catalog-api.fullname" . -}}
2+
3+
apiVersion: v1
4+
kind: ConfigMap
5+
metadata:
6+
name: "envoy-{{ $name }}"
7+
labels:
8+
app: {{ template "catalog-api.name" . }}
9+
chart: {{ template "catalog-api.chart" .}}
10+
release: {{ .Release.Name }}
11+
heritage: {{ .Release.Service }}
12+
data:
13+
{{ (.Files.Glob "envoycfg/*.yaml").AsConfig | indent 2 }}
14+
binaryData:
15+
_catalog.proto-descriptor.pb: |-
16+
{{ .Files.Get "envoycfg/_catalog.proto-descriptor.pb" | b64enc -}}

k8s/helm/catalog-api/templates/service.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ spec:
1414
targetPort: http
1515
protocol: TCP
1616
name: http
17+
- port: {{ .Values.service.grpc }}
18+
targetPort: grpc
19+
protocol: TCP
20+
name: grpc
21+
- port: {{ .Values.service.envoy }}
22+
targetPort: envoy
23+
protocol: TCP
24+
name: envoy
1725
selector:
1826
app: {{ template "catalog-api.name" . }}
1927
release: {{ .Release.Name }}

k8s/helm/catalog-api/values.yaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ image:
99

1010
service:
1111
type: ClusterIP
12-
port: 80
12+
port: 5000
13+
grpc: 5001
14+
envoy: 80
1315

1416

1517
resources: {}
@@ -44,16 +46,20 @@ env:
4446
value: Development
4547
- name: OrchestratorType
4648
value: 'K8S'
49+
- name: PORT
50+
value: "5000"
51+
- name: GRPC_PORT
52+
value: "5001"
4753
probes:
4854
liveness:
4955
path: /liveness
5056
initialDelaySeconds: 10
5157
periodSeconds: 15
52-
port: 80
58+
port: 5000
5359
readiness:
5460
path: /hc
5561
timeoutSeconds: 5
5662
initialDelaySeconds: 90
5763
periodSeconds: 60
58-
port: 80
64+
port: 5000
5965

src/ApiGateways/Web.Bff.Shopping/aggregator/Config/UrlsConfig.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ public class UrlsConfig
99
{
1010
public class CatalogOperations
1111
{
12+
// grpc call under REST must go trough port 80
1213
public static string GetItemById(int id) => $"/api/v1/catalog/items/{id}";
13-
public static string GetItemsById(IEnumerable<int> ids) => $"/api/v1/catalog/items?ids={string.Join(',', ids)}";
14+
// REST call standard must go through port 5000
15+
public static string GetItemsById(IEnumerable<int> ids) => $":5000/api/v1/catalog/items?ids={string.Join(',', ids)}";
1416
}
1517

1618
public class BasketOperations

0 commit comments

Comments
 (0)