Skip to content

Commit 7b800fd

Browse files
committed
Document gRPC over HTTP2 for 4.10+
Rename section for OpenShift up to 4.9 Separate gRPC over HTTP2 for 4.10+ and under 4.10 into two sections Add grpc library import Co-authored-by: Kenjiro Nakayama <[email protected]> Add code for a test request Co-authored-by: Kenjiro Nakayama <[email protected]> A fix and an addition s/yaml/golang in snippet markup Co-authored-by: Kenjiro Nakayama <[email protected]> s/yaml/golang in another snippet's markup Minor fix
1 parent cb34699 commit 7b800fd

File tree

3 files changed

+107
-42
lines changed

3 files changed

+107
-42
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Module included in the following assemblies:
2+
//
3+
// serverless/knative-serving/external-ingress-routing/using-http2-gRPC.adoc
4+
5+
:_content-type: PROCEDURE
6+
[id="interacting-serverless-apps-http2-grpc-up-to-4-9_{context}"]
7+
= Interacting with a serverless application using HTTP2 and gRPC in {product-title} 4.9 and older
8+
9+
[IMPORTANT]
10+
====
11+
This method needs to expose Kourier Gateway using the `LoadBalancer` service type. You can configure this by adding the following YAML to your `KnativeServing` custom resource definition (CRD):
12+
13+
[source,yaml]
14+
----
15+
...
16+
spec:
17+
ingress:
18+
kourier:
19+
service-type: LoadBalancer
20+
...
21+
----
22+
====
23+
24+
.Prerequisites
25+
26+
* Install {ServerlessOperatorName} and Knative Serving on your cluster.
27+
* Install the OpenShift CLI (`oc`).
28+
* Create a Knative service.
29+
30+
.Procedure
31+
32+
. Find the application host. See the instructions in _Verifying your serverless application deployment_.
33+
34+
. Find the ingress gateway's public address:
35+
+
36+
[source,terminal]
37+
----
38+
$ oc -n knative-serving-ingress get svc kourier
39+
----
40+
+
41+
.Example output
42+
+
43+
[source,terminal]
44+
----
45+
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
46+
kourier LoadBalancer 172.30.51.103 a83e86291bcdd11e993af02b7a65e514-33544245.us-east-1.elb.amazonaws.com 80:31380/TCP,443:31390/TCP 67m
47+
----
48+
+
49+
The public address is surfaced in the `EXTERNAL-IP` field, and in this case is `a83e86291bcdd11e993af02b7a65e514-33544245.us-east-1.elb.amazonaws.com`.
50+
51+
. Manually set the host header of your HTTP request to the application's host, but direct the request itself against the public address of the ingress gateway.
52+
+
53+
[source,terminal]
54+
----
55+
$ curl -H "Host: hello-default.example.com" a83e86291bcdd11e993af02b7a65e514-33544245.us-east-1.elb.amazonaws.com
56+
----
57+
+
58+
.Example output
59+
[source,terminal]
60+
----
61+
Hello Serverless!
62+
----
63+
+
64+
You can also make a direct gRPC request against the ingress gateway:
65+
+
66+
[source,golang]
67+
----
68+
import "google.golang.org/grpc"
69+
70+
grpc.Dial(
71+
"a83e86291bcdd11e993af02b7a65e514-33544245.us-east-1.elb.amazonaws.com:80",
72+
grpc.WithAuthority("hello-default.example.com:80"),
73+
grpc.WithInsecure(),
74+
)
75+
----
76+
+
77+
[NOTE]
78+
====
79+
Ensure that you append the respective port, 80 by default, to both hosts as shown in the previous example.
80+
====

modules/interacting-serverless-apps-http2-gRPC.adoc

Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,76 +3,55 @@
33
// serverless/knative-serving/external-ingress-routing/using-http2-gRPC.adoc
44

55
:_content-type: PROCEDURE
6-
[id="interacting-serverless-apps-http2-gRPC_{context}"]
6+
[id="interacting-serverless-apps-http2-grpc_{context}"]
77
= Interacting with a serverless application using HTTP2 and gRPC
88

99
[IMPORTANT]
1010
====
11-
This method needs to expose Kourier Gateway using the `LoadBalancer` service type. You can configure this by adding the following YAML to your `KnativeServing` custom resource definition (CRD):
12-
13-
[source,yaml]
14-
----
15-
...
16-
spec:
17-
ingress:
18-
kourier:
19-
service-type: LoadBalancer
20-
...
21-
----
11+
This method applies to {product-title} 4.10 and later. For older versions, see the following section.
2212
====
2313

2414
.Prerequisites
2515

26-
* {ServerlessOperatorName} and Knative Serving are installed on your cluster.
16+
* Install {ServerlessOperatorName} and Knative Serving on your cluster.
2717
* Install the OpenShift CLI (`oc`).
28-
* You have created a Knative service.
18+
* Create a Knative service.
19+
* Upgrade {product-title} 4.10 or later.
20+
* Enable HTTP/2 on OpenShift Ingress controller.
2921
3022
.Procedure
3123

32-
. Find the application host. See the instructions in _Verifying your serverless application deployment_.
33-
34-
. Find the ingress gateway's public address:
35-
+
36-
[source,terminal]
37-
----
38-
$ oc -n knative-serving-ingress get svc kourier
39-
----
40-
+
41-
.Example output
24+
. Add the `serverless.openshift.io/default-enable-http2=true` annotation to the `KnativeServing` Custom Resource:
4225
+
4326
[source,terminal]
4427
----
45-
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
46-
kourier LoadBalancer 172.30.51.103 a83e86291bcdd11e993af02b7a65e514-33544245.us-east-1.elb.amazonaws.com 80:31380/TCP,443:31390/TCP 67m
28+
$ oc annotate knativeserving <your_knative_CR> -n knative-serving serverless.openshift.io/default-enable-http2=true
4729
----
48-
+
49-
The public address is surfaced in the `EXTERNAL-IP` field, and in this case is `a83e86291bcdd11e993af02b7a65e514-33544245.us-east-1.elb.amazonaws.com`.
5030

51-
. Manually set the host header of your HTTP request to the application's host, but direct the request itself against the public address of the ingress gateway.
31+
. After the annotation is added, you can verify that the `appProtocol` value of the Kourier service is `h2c`:
5232
+
5333
[source,terminal]
5434
----
55-
$ curl -H "Host: hello-default.example.com" a83e86291bcdd11e993af02b7a65e514-33544245.us-east-1.elb.amazonaws.com
35+
$ oc get svc -n knative-serving-ingress kourier -o jsonpath="{.spec.ports[0].appProtocol}"
5636
----
5737
+
5838
.Example output
39+
+
5940
[source,terminal]
6041
----
61-
Hello Serverless!
42+
h2c
6243
----
44+
45+
. Now you can use the gRPC framework over the HTTP/2 protocol for external traffic, for example:
6346
+
64-
You can also make a gRPC request by setting the authority to the application's host, while directing the request against the ingress gateway directly:
65-
+
66-
[source,yaml]
47+
[source,golang]
6748
----
49+
import "google.golang.org/grpc"
50+
6851
grpc.Dial(
69-
"a83e86291bcdd11e993af02b7a65e514-33544245.us-east-1.elb.amazonaws.com:80",
70-
grpc.WithAuthority("hello-default.example.com:80"),
71-
grpc.WithInsecure(),
52+
YOUR_URL, <1>
53+
grpc.WithTransportCredentials(insecure.NewCredentials())), <2>
7254
)
7355
----
74-
+
75-
[NOTE]
76-
====
77-
Ensure that you append the respective port, 80 by default, to both hosts as shown in the previous example.
78-
====
56+
<1> Your `ksvc` URL.
57+
<2> Your certificate.

serverless/knative-serving/external-ingress-routing/using-http2-gRPC.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@ include::_attributes/common-attributes.adoc[]
77
{ServerlessProductName} supports only insecure or edge-terminated routes. Insecure or edge-terminated routes do not support HTTP2 on {product-title}. These routes also do not support gRPC because gRPC is transported by HTTP2. If you use these protocols in your application, you must call the application using the ingress gateway directly. To do this you must find the ingress gateway's public address and the application's specific host.
88

99
include::modules/interacting-serverless-apps-http2-gRPC.adoc[leveloffset=+1]
10+
11+
[role="_additional-resources"]
12+
.Additional resources
13+
* xref:../../../networking/ingress-operator.adoc#nw-http2-haproxy_configuring-ingress[Enabling HTTP/2 Ingress connectivity]
14+
15+
include::modules/interacting-serverless-apps-http2-gRPC-up-to-4-9.adoc[leveloffset=+1]

0 commit comments

Comments
 (0)