helm upgrade --install kong-operator kong/kong-operator -n kong-system \
--create-namespace \
--set image.tag=2.3 \Proxy gRPC traffic using GRPCRoute
Prerequisites
Kong Operator running (with an Enterprise license)
-
Add the Kong Helm charts:
helm repo add kong https://charts.konghq.com helm repo update -
Install Kong Operator using Helm:
If you want cert-manager to issue and rotate the admission and conversion webhook certificates, install cert-manager to your cluster and enable cert-manager integration by passing the following argument while installing, in the next step:
--set global.webhooks.options.certManager.enabled=trueIf you do not enable this, the chart will generate and inject self-signed certificates automatically. We recommend enabling cert-manager to manage the lifecycle of these certificates. Kong Operator needs a certificate authority to sign the certificate for mTLS communication between the control plane and the data plane. This is handled automatically by the Helm chart. If you need to provide a custom CA certificate, refer to the
certificateAuthoritysection in thevalues.yamlof the Helm chart to learn how to create and reference your own CA certificate.
Apply a KongLicense. This assumes that your license is available in ./license.json
echo "
apiVersion: configuration.konghq.com/v1alpha1
kind: KongLicense
metadata:
name: kong-license
rawLicenseString: '$(cat ./license.json)'
" | kubectl apply -f -gRPCurl installed
Install gRPCurl, which is a CLI that lets you interact with gRPC servers. This tutorial requires gRPCurl for validation.
GRPCRoute is a Kubernetes Gateway API resource for routing gRPC traffic. This guide shows how to configure Kong Operator to proxy gRPC traffic secured with TLS to a backend Service.
Create the kong namespace
Create the kong namespace in your Kubernetes cluster, which is where the demo will run:
kubectl create namespace kongConfigure the Gateway
Create a GatewayConfiguration, GatewayClass, and Gateway with an HTTP listener:
echo '
apiVersion: gateway-operator.konghq.com/v2beta1
kind: GatewayConfiguration
metadata:
name: kong-gateway-configuration
namespace: kong
spec:
dataPlaneOptions:
deployment:
podTemplateSpec:
spec:
containers:
- image: kong/kong-gateway:3.15
name: proxy
---
apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
name: kong-grpc
spec:
controllerName: konghq.com/gateway-operator
parametersRef:
group: gateway-operator.konghq.com
kind: GatewayConfiguration
name: kong-gateway-configuration
namespace: kong
---
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: kong-grpc-gateway
namespace: kong
spec:
gatewayClassName: kong-grpc
listeners:
- name: http
port: 80
protocol: HTTP' | kubectl apply -f -Deploy a gRPC backend
Install the grpcbin Service, which implements a simple gRPC test API:
kubectl apply -f https://developer.konghq.com/manifests/kic/grpcbin-service.yaml -n kongAnnotate the Kubernetes Service
Kong Gateway assumes Services are HTTP or HTTPS by default. Add the konghq.com/protocol annotation so Kong Operator configures the backend Service as gRPC over TLS instead:
kubectl annotate service -n kong grpcbin 'konghq.com/protocol=grpcs'Generate a TLS certificate
-
Create a test certificate for the
example.comhostname. This will be used to secure TLS traffic.Older OpenSSL versions, including the version provided with macOS Monterey, require using the alternative version of this command.
- Create a Secret containing the certificate:
kubectl create secret -n kong tls example.com --cert=./server.crt --key=./server.key -
Kong Operator only watches certificate Secrets that carry the
konghq.com/secret="true"label. Add the label so Kong Operator picks up the Secret you just created:kubectl label secret example.com -n kong konghq.com/secret="true"
Route gRPC traffic
-
Re-apply the
kong-grpc-gatewayGateway with an additionalHTTPSlistener for gRPC traffic:Warning: Applying this Gateway replaces the listener list. Include every listener you want to keep.
echo 'apiVersion: gateway.networking.k8s.io/v1 kind: Gateway metadata: name: kong-grpc-gateway namespace: kong spec: gatewayClassName: kong-grpc listeners: - name: http port: 80 protocol: HTTP - name: grpc port: 443 protocol: HTTPS hostname: example.com tls: certificateRefs: - group: "" kind: Secret name: example.com' | kubectl apply -f - -
Create a
GRPCRoute:echo 'apiVersion: gateway.networking.k8s.io/v1 kind: GRPCRoute metadata: name: grpcbin namespace: kong spec: parentRefs: - name: kong-grpc-gateway sectionName: grpc hostnames: - "example.com" rules: - backendRefs: - name: grpcbin port: 9001 ' | kubectl apply -f -
This configuration instructs Kong Gateway to forward gRPC requests for example.com on port 443 to the grpcbin Service on port 9001.
Validate
-
Wait for the Gateway to be programmed:
kubectl wait gateway/kong-grpc-gateway -n kong \ --for=condition=Programmed=True \ --timeout=5m -
Get the Gateway’s external IP:
export PROXY_IP=$(kubectl get gateway kong-grpc-gateway -n kong -o jsonpath='{.status.addresses[0].value}') echo $PROXY_IP -
Call the
grpcbintest service through the proxy:grpcurl -insecure -authority example.com \ -d '{"greeting": "Kong"}' \ $PROXY_IP:443 hello.HelloService.SayHelloThe results should look like this:
{ "reply": "hello Kong" }