@@ -8,46 +8,46 @@ to route traffic to that application using GRPCRoute resources.
8
8
## 1. Deploy NGINX Gateway Fabric
9
9
10
10
1 . Follow the [ installation instructions] ( https://docs.nginx.com/nginx-gateway-fabric/installation/ ) to deploy NGINX Gateway Fabric.
11
- NB : Ensure the Gateway APIs from the experimental channel are installed and that NGF is deployed with the Gateway experimental features enabled.
11
+ > ** Important ** : Ensure the Gateway APIs from the experimental channel are installed and that NGF is deployed with the Gateway experimental features enabled.
12
12
13
13
1 . Save the public IP address of NGINX Gateway Fabric into a shell variable:
14
14
15
- ``` text
16
- GW_IP=XXX.YYY.ZZZ.III
17
- ```
15
+ ``` text
16
+ GW_IP=XXX.YYY.ZZZ.III
17
+ ```
18
18
19
19
1. Save the port of NGINX Gateway Fabric:
20
20
21
- ``` text
22
- GW_PORT=<port number>
23
- ```
21
+ ```text
22
+ GW_PORT=<port number>
23
+ ```
24
24
25
25
## 2. Deploy the Helloworld Application
26
26
27
27
1. Create the two helloworld Deployments and Services:
28
28
29
- ``` shell
30
- kubectl apply -f helloworld.yaml
31
- ```
29
+ ```shell
30
+ kubectl apply -f helloworld.yaml
31
+ ```
32
32
33
33
1. Check that the Pods are running in the `default` Namespace:
34
34
35
- ``` shell
36
- kubectl -n default get pods
37
- ```
35
+ ```shell
36
+ kubectl -n default get pods
37
+ ```
38
38
39
- ``` text
40
- NAME READY STATUS RESTARTS AGE
41
- grpc-infra-backend-v1-766c7d6788-rg92p 1/1 Running 0 12s
42
- grpc-infra-backend-v2-546f7c8d48-mjkkx 1/1 Running 0 12s
43
- ```
39
+ ```text
40
+ NAME READY STATUS RESTARTS AGE
41
+ grpc-infra-backend-v1-766c7d6788-rg92p 1/1 Running 0 12s
42
+ grpc-infra-backend-v2-546f7c8d48-mjkkx 1/1 Running 0 12s
43
+ ```
44
44
45
45
Save these pod names into variables:
46
46
47
- ``` text
48
- POD_V1=<grpc-infra-backend-v1-xxxxxxxxxx-xxxxx>
49
- POD_V2=<grpc-infra-backend-v2-xxxxxxxxxx-xxxxx>
50
- ```
47
+ ```text
48
+ POD_V1=<grpc-infra-backend-v1-xxxxxxxxxx-xxxxx>
49
+ POD_V2=<grpc-infra-backend-v2-xxxxxxxxxx-xxxxx>
50
+ ```
51
51
52
52
## 3. Configure Routing
53
53
@@ -57,147 +57,147 @@ There are 3 options to configure gRPC routing. To access the application and tes
57
57
58
58
1. Create the Gateway and GRPCRoute resources:
59
59
60
- ``` shell
61
- kubectl apply -f exact-method.yaml
62
- ```
60
+ ```shell
61
+ kubectl apply -f exact-method.yaml
62
+ ```
63
63
64
64
2. Test the Application:
65
65
66
- ``` shell
67
- grpcurl -plaintext -proto grpc.proto -authority bar.com -d ' {"name": "exact"}' ${GW_IP} :${GW_PORT} helloworld.Greeter/SayHello
68
- ```
66
+ ```shell
67
+ grpcurl -plaintext -proto grpc.proto -authority bar.com -d '{"name": "exact"}' ${GW_IP}:${GW_PORT} helloworld.Greeter/SayHello
68
+ ```
69
69
70
- ``` text
71
- {
72
- "message": "Hello exact"
73
- }
74
- ```
70
+ ```text
71
+ {
72
+ "message": "Hello exact"
73
+ }
74
+ ```
75
75
76
76
3. Clean up the Gateway and GRPCRoute resources:
77
77
78
- ``` shell
79
- kubectl delete -f exact-method.yaml
80
- ```
78
+ ```shell
79
+ kubectl delete -f exact-method.yaml
80
+ ```
81
81
82
82
### 3b. Configure hostname based routing
83
83
84
84
1. Create the Gateway and GRPCRoute resources:
85
85
86
- ``` shell
87
- kubectl apply -f hostname.yaml
88
- ```
86
+ ```shell
87
+ kubectl apply -f hostname.yaml
88
+ ```
89
89
90
90
2. Test the Application:
91
91
92
- ``` shell
93
- grpcurl -plaintext -proto grpc.proto -authority bar.com -d ' {"name": "bar server"}' ${GW_IP} :${GW_PORT} helloworld.Greeter/SayHello
94
- ```
92
+ ```shell
93
+ grpcurl -plaintext -proto grpc.proto -authority bar.com -d '{"name": "bar server"}' ${GW_IP}:${GW_PORT} helloworld.Greeter/SayHello
94
+ ```
95
95
96
- ``` text
97
- {
98
- "message": "Hello bar server"
99
- }
100
- ```
96
+ ```text
97
+ {
98
+ "message": "Hello bar server"
99
+ }
100
+ ```
101
101
102
102
To make sure this came from the correct server, we can check the application server logs:
103
103
104
- ``` shell
105
- kubectl logs ${POD_V1}
106
- ```
104
+ ```shell
105
+ kubectl logs ${POD_V1}
106
+ ```
107
107
108
- ``` text
109
- 2024/04/29 09:26:54 server listening at [::]:50051
110
- 2024/04/29 09:28:54 Received: bar server
111
- ```
108
+ ```text
109
+ 2024/04/29 09:26:54 server listening at [::]:50051
110
+ 2024/04/29 09:28:54 Received: bar server
111
+ ```
112
112
113
113
Now we'll send a request to `foo.bar.com`
114
114
115
- ``` shell
116
- grpcurl -plaintext -proto grpc.proto -authority foo.bar.com -d ' {"name": "foo bar server"}' ${GW_IP} :${GW_PORT} helloworld.Greeter/SayHello
117
- ```
115
+ ```shell
116
+ grpcurl -plaintext -proto grpc.proto -authority foo.bar.com -d '{"name": "foo bar server"}' ${GW_IP}:${GW_PORT} helloworld.Greeter/SayHello
117
+ ```
118
118
119
- ``` text
120
- {
121
- "message": "Hello foo bar server"
122
- }
123
- ```
119
+ ```text
120
+ {
121
+ "message": "Hello foo bar server"
122
+ }
123
+ ```
124
124
125
125
This time, we'll check the POD_V2 logs:
126
126
127
- ``` shell
128
- kubectl logs ${POD_V2}
129
- ```
127
+ ```shell
128
+ kubectl logs ${POD_V2}
129
+ ```
130
130
131
- ``` text
132
- 2024/04/29 09:26:55 server listening at [::]:50051
133
- 2024/04/29 09:29:46 Received: foo bar server
134
- ```
131
+ ```text
132
+ 2024/04/29 09:26:55 server listening at [::]:50051
133
+ 2024/04/29 09:29:46 Received: foo bar server
134
+ ```
135
135
136
136
3. Clean up the Gateway and GRPCRoute resources:
137
137
138
- ``` shell
139
- kubectl delete -f hostname.yaml
140
- ```
138
+ ```shell
139
+ kubectl delete -f hostname.yaml
140
+ ```
141
141
142
142
### 3c. Configure headers based routing
143
143
144
144
1. Create the Gateway and GRPCRoute resources:
145
145
146
- ``` shell
147
- kubectl apply -f headers.yaml
148
- ```
146
+ ```shell
147
+ kubectl apply -f headers.yaml
148
+ ```
149
149
150
150
2. Test the Application:
151
151
152
- ``` shell
153
- grpcurl -plaintext -proto grpc.proto -authority bar.com -d ' {"name": "version one"}' -H ' version: one' ${GW_IP} :${GW_PORT} helloworld.Greeter/SayHello
154
- ```
152
+ ```shell
153
+ grpcurl -plaintext -proto grpc.proto -authority bar.com -d '{"name": "version one"}' -H 'version: one' ${GW_IP}:${GW_PORT} helloworld.Greeter/SayHello
154
+ ```
155
155
156
- ``` text
157
- {
158
- "message": "Hello version one"
159
- }
160
- ```
156
+ ```text
157
+ {
158
+ "message": "Hello version one"
159
+ }
160
+ ```
161
161
162
162
To make sure this came from the correct server, we can check the application server logs:
163
163
164
- ``` shell
165
- kubectl logs ${POD_V1}
166
- ```
164
+ ```shell
165
+ kubectl logs ${POD_V1}
166
+ ```
167
167
168
- ``` text
169
- <...>
170
- 2024/04/29 09:30:27 Received: version one
171
- ```
168
+ ```text
169
+ <...>
170
+ 2024/04/29 09:30:27 Received: version one
171
+ ```
172
172
173
173
Now we'll send a request with the header `version: two`
174
174
175
- ``` shell
176
- grpcurl -plaintext -proto grpc.proto -authority bar.com -d ' {"name": "version two"}' -H ' version: two' ${GW_IP} :${GW_PORT} helloworld.Greeter/SayHello
177
- ```
175
+ ```shell
176
+ grpcurl -plaintext -proto grpc.proto -authority bar.com -d '{"name": "version two"}' -H 'version: two' ${GW_IP}:${GW_PORT} helloworld.Greeter/SayHello
177
+ ```
178
178
179
- ``` text
180
- {
181
- "message": "Hello version two"
182
- }
183
- ```
179
+ ```text
180
+ {
181
+ "message": "Hello version two"
182
+ }
183
+ ```
184
184
185
185
This time, we'll check the POD_V2 logs:
186
186
187
- ``` shell
188
- kubectl logs ${POD_V2}
189
- ```
187
+ ```shell
188
+ kubectl logs ${POD_V2}
189
+ ```
190
190
191
- ``` text
192
- <...>
193
- 2024/04/29 09:32:46 Received: version two
194
- ```
191
+ ```text
192
+ <...>
193
+ 2024/04/29 09:32:46 Received: version two
194
+ ```
195
195
196
196
Finally, we'll send a request with the headers `version: two` and `color: orange`
197
197
198
- ``` shell
199
- grpcurl -plaintext -proto grpc.proto -authority bar.com -d ' {"name": "version two orange"}' -H ' version: two' -H ' color: orange' ${GW_IP} :${GW_PORT} helloworld.Greeter/SayHello
200
- ```
198
+ ```shell
199
+ grpcurl -plaintext -proto grpc.proto -authority bar.com -d '{"name": "version two orange"}' -H 'version: two' -H 'color: orange' ${GW_IP}:${GW_PORT} helloworld.Greeter/SayHello
200
+ ```
201
201
202
202
```text
203
203
{
@@ -219,6 +219,6 @@ There are 3 options to configure gRPC routing. To access the application and tes
219
219
220
220
3 . Clean up the Gateway and GRPCRoute resources:
221
221
222
- ``` shell
223
- kubectl delete -f headers.yaml
224
- ```
222
+ ``` shell
223
+ kubectl delete -f headers.yaml
224
+ ```
0 commit comments