gRPC routing
Route traffic to gRPC services by using the GRPCRoute resource for protocol-aware routing.
About gRPC routing
The GRPCRoute resource provides protocol-aware routing for gRPC traffic within the Kubernetes Gateway API. Unlike the HTTPRoute, which requires matching on HTTP paths and methods, the GRPCRoute allows you to define routing rules by using gRPC-native concepts, such as service and method names.
Consider the difference:
- HTTPRoute Match:
path:/com.example.User/Login,method: POST - GRPCRoute Match:
service: yages.Echo,method: Ping
The GRPCRoute approach is more readable, less error-prone, and aligns with the Gateway API’s role-oriented philosophy.
Before you begin
- Set up an agentgateway proxy.
- Install the httpbin sample app.
grpcurl for testing on your computer.Deploy a sample gRPC service
Deploy a sample gRPC service for testing purposes. The sample service has two APIs:
yages.Echo.Ping: Takes no input (empty message) and returns apongmessage.yages.Echo.Reverse: Takes input content and returns the content in reverse order, such ashello worldbecomesdlrow olleh.
Steps to set up the sample gRPC service:
Deploy the gRPC echo server and client.
kubectl apply -f- <<EOF apiVersion: apps/v1 kind: Deployment metadata: name: grpc-echo namespace: agentgateway-system labels: app.kubernetes.io/name: grpc-echo spec: selector: matchLabels: app.kubernetes.io/name: grpc-echo replicas: 1 template: metadata: labels: app.kubernetes.io/name: grpc-echo spec: containers: - name: grpc-echo image: ghcr.io/projectcontour/yages:v0.1.0 ports: - containerPort: 9000 protocol: TCP env: - name: POD_NAME valueFrom: fieldRef: fieldPath: metadata.name - name: NAMESPACE valueFrom: fieldRef: fieldPath: metadata.namespace - name: GRPC_ECHO_SERVER value: "true" - name: SERVICE_NAME value: grpc-echo --- apiVersion: v1 kind: Service metadata: name: grpc-echo-svc namespace: agentgateway-system labels: app.kubernetes.io/name: grpc-echo spec: type: ClusterIP ports: - port: 3000 protocol: TCP targetPort: 9000 appProtocol: kubernetes.io/h2c selector: app.kubernetes.io/name: grpc-echo --- apiVersion: v1 kind: Pod metadata: name: grpcurl-client namespace: agentgateway-system labels: app.kubernetes.io/name: grpcurl-client spec: containers: - name: grpcurl image: docker.io/fullstorydev/grpcurl:v1.8.7-alpine command: - sleep - "infinity" EOFVerify that the sample app is up and running.
kubectl get pods -n agentgateway-system | grep grpcExample output:
grpc-echo-5fc549b5fc-tdlzw 1/1 Running 0 39s grpcurl-client 1/1 Running 0 6s
Set up gRPC routing
Create the GRPC Gateway. The following Gateway accepts routes from all namespaces.
kubectl apply -f- <<EOF apiVersion: gateway.networking.k8s.io/v1 kind: Gateway metadata: name: grpc namespace: agentgateway-system spec: gatewayClassName: agentgateway listeners: - protocol: HTTP port: 80 name: http allowedRoutes: namespaces: from: All EOFCreate the GRPCRoute. The GRPCRoute includes a match for
grpc.reflection.v1alpha.ServerReflectionto enable dynamic API exploration and a match for thePingmethod. For detailed information about GRPCRoute fields and configuration options, see the Gateway API GRPCRoute documentation.kubectl apply -f - <<EOF apiVersion: gateway.networking.k8s.io/v1 kind: GRPCRoute metadata: name: example-route namespace: agentgateway-system spec: parentRefs: - name: grpc hostnames: - "grpc.com" rules: - matches: - method: method: ServerReflectionInfo service: grpc.reflection.v1alpha.ServerReflection - method: method: Ping backendRefs: - name: grpc-echo-svc port: 3000 EOFVerify that the GRPCRoute is applied successfully.
kubectl get grpcroute example-route -n agentgateway-system -o yamlExample output:
status: parents: - conditions: - lastTransitionTime: "2026-01-21T16:22:52Z" message: "" observedGeneration: 1 reason: Accepted status: "True" type: Accepted - lastTransitionTime: "2026-01-21T16:22:52Z" message: "" observedGeneration: 1 reason: ResolvedRefs status: "True" type: ResolvedRefs controllerName: agentgateway.dev/agentgateway parentRef: group: gateway.networking.k8s.io kind: Gateway name: grpc namespace: agentgateway-system
Verify the gRPC route
Verify that the gRPC route to the echo service is working. The steps vary whether your Gateway is exposed with a LoadBalancer service or set up for local testing only.
Send a request to the gRPC echo service by using the gRPC client app. Verify that you see the the
Pongmessage in your response.kubectl exec -n agentgateway-system grpcurl-client -c grpcurl -- \ grpcurl -plaintext -authority grpc.com -vv grpc:80 yages.Echo/PingExample output:
{ "text": "pong" }Optional: Explore other gRPC endpoints.
kubectl exec -n agentgateway-system grpcurl-client -c grpcurl -- \ grpcurl -plaintext -authority grpc.com -vv grpc:80 list kubectl exec -n agentgateway-system grpcurl-client -c grpcurl -- \ grpcurl -plaintext -authority grpc.com -vv grpc:80 describe yages.EchoExample output:
grpc.health.v1.Health grpc.reflection.v1alpha.ServerReflection yages.Echo yages.Echo is a service: service Echo { rpc Ping ( .yages.Empty ) returns ( .yages.Content ); rpc Reverse ( .yages.Content ) returns ( .yages.Content ); }
Port-forward the gateway proxy pod on port 8080.
kubectl port-forward svc/grpc -n agentgateway-system 8080:80Send a request to the gRPC echo service. Verify that you see the the
Pongmessage in your response.grpcurl -plaintext -authority grpc.com -vv localhost:8080 yages.Echo/PingExample output:
{ "text": "pong" }Optional: Explore other gRPC endpoints.
grpcurl -plaintext -authority grpc.com localhost:8080 list grpcurl -plaintext -authority grpc.com localhost:8080 describe yages.EchoExample output:
grpc.health.v1.Health grpc.reflection.v1alpha.ServerReflection yages.Echo yages.Echo is a service: service Echo { rpc Ping ( .yages.Empty ) returns ( .yages.Content ); rpc Reverse ( .yages.Content ) returns ( .yages.Content ); }
Cleanup
You can remove the resources that you created in this guide.kubectl delete grpcroute example-route -n agentgateway-system
kubectl delete deployment grpc-echo -n agentgateway-system
kubectl delete service grpc-echo-svc -n agentgateway-system
kubectl delete pod grpcurl-client -n agentgateway-system
kubectl delete gateway grpc -n agentgateway-system