|
3 | 3 | // serverless/knative-serving/external-ingress-routing/using-http2-gRPC.adoc
|
4 | 4 |
|
5 | 5 | :_content-type: PROCEDURE
|
6 |
| -[id="interacting-serverless-apps-http2-gRPC_{context}"] |
| 6 | +[id="interacting-serverless-apps-http2-grpc_{context}"] |
7 | 7 | = Interacting with a serverless application using HTTP2 and gRPC
|
8 | 8 |
|
9 | 9 | [IMPORTANT]
|
10 | 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 |
| ----- |
| 11 | +This method applies to {product-title} 4.10 and later. For older versions, see the following section. |
22 | 12 | ====
|
23 | 13 |
|
24 | 14 | .Prerequisites
|
25 | 15 |
|
26 |
| -* {ServerlessOperatorName} and Knative Serving are installed on your cluster. |
| 16 | +* Install {ServerlessOperatorName} and Knative Serving on your cluster. |
27 | 17 | * 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. |
29 | 21 |
|
30 | 22 | .Procedure
|
31 | 23 |
|
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: |
42 | 25 | +
|
43 | 26 | [source,terminal]
|
44 | 27 | ----
|
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 |
47 | 29 | ----
|
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 | 30 |
|
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`: |
52 | 32 | +
|
53 | 33 | [source,terminal]
|
54 | 34 | ----
|
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}" |
56 | 36 | ----
|
57 | 37 | +
|
58 | 38 | .Example output
|
| 39 | ++ |
59 | 40 | [source,terminal]
|
60 | 41 | ----
|
61 |
| -Hello Serverless! |
| 42 | +h2c |
62 | 43 | ----
|
| 44 | + |
| 45 | +. Now you can use the gRPC framework over the HTTP/2 protocol for external traffic, for example: |
63 | 46 | +
|
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] |
67 | 48 | ----
|
| 49 | +import "google.golang.org/grpc" |
| 50 | + |
68 | 51 | 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> |
72 | 54 | )
|
73 | 55 | ----
|
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. |
0 commit comments