All Products
Search
Document Center

Container Service for Kubernetes:Deploy a gRPC service in Knative

Last Updated:Mar 26, 2026

ACK Knative supports HTTP and HTTP/2, including gRPC. To deploy a gRPC service, set the port name to h2c (HTTP/2 cleartext) in the Knative Service spec. This tells the Knative gateway to use HTTP/2 routing for gRPC traffic.

Prerequisites

Before you begin, ensure that you have:

Step 1: Deploy a gRPC service

  1. Log on to the ACK console. In the left-side navigation pane, click ACK consoleClusters.

  2. On the Clusters page, click the name of your cluster, then choose Applications > Knative in the left-side navigation pane.

  3. On the Knative page, click the Services tab. Set Namespace to default, click Create from Template, and select Custom from the Sample Template drop-down list. Copy the following YAML to the template editor and click Create.

    apiVersion: serving.knative.dev/v1
    kind: Service
    metadata:
      name: helloworld-grpc
    spec:
      template:
        metadata:
          annotations:
            autoscaling.knative.dev/class: mpa.autoscaling.knative.dev
        spec:
          containers:
          - image: docker.io/moul/grpcbin
            env:
            - name: TARGET
              value: "Knative"
            ports:
            - containerPort: 9000
              name: h2c  # Required: tells the Knative gateway to use HTTP/2 routing for gRPC
              protocol: TCP
  4. Map the service domain name to the gateway address. On the Services tab, find the Default Domain and Gateway columns for the helloworld-grpc service. Add the following entry to your local machine's hosts file, replacing the values with those shown in the console:

    121.xx.xxx.xx helloworld-grpc.default.example.com

    The format is: gateway address, a space, then the default domain name.

Step 2: Verify the gRPC service

The gRPC service uses HTTP/2. The request path format is {package name}.{service name}/{method name} — for example, grpcbin.GRPCBin/Index routes an HTTP/2 request to the Index method of GRPCBin.

To verify the service, use BloomRPC with the .proto file that defines the service interface.

  1. Visit grpcbin and install BloomRPC for your operating system.

  2. Save the following content to a file named gRPC.proto on your local machine:

    syntax = "proto3";
    
    package grpcbin;
    
    service GRPCBin {
      rpc Index(EmptyMessage) returns (IndexReply) {}
      // Takes an empty message as input and returns an empty message as output.
      rpc Empty(EmptyMessage) returns (EmptyMessage) {}
      // Takes a dummy message as input and returns a dummy message as output.
      rpc DummyUnary(DummyMessage) returns (DummyMessage) {}
      // Takes a dummy message as input and returns a stream of 10 dummy messages as output.
      rpc DummyServerStream(DummyMessage) returns (stream DummyMessage) {}
      // Takes a stream of 10 dummy messages as input and returns a dummy message as output.
      rpc DummyClientStream(stream DummyMessage) returns (DummyMessage) {}
      // Takes a stream of dummy messages as input and returns a stream of dummy messages as output.
      rpc DummyBidirectionalStreamStream(stream DummyMessage) returns (stream DummyMessage) {}
      // Returns a message for the specified gRPC error.
      rpc SpecificError(SpecificErrorRequest) returns (EmptyMessage) {}
      // Returns a message for a random gRPC error.
      rpc RandomError(EmptyMessage) returns (EmptyMessage) {}
      // Returns a header.
      rpc HeadersUnary(EmptyMessage) returns (HeadersMessage) {}
      // Does not return any messages.
      rpc NoResponseUnary(EmptyMessage) returns (EmptyMessage) {}
    }
    
    message HeadersMessage {
      message Values {
        repeated string values = 1;
      }
      map<string, Values> Metadata = 1;
    }
    
    message SpecificErrorRequest {
      uint32 code = 1;
      string reason = 2;
    }
    
    message EmptyMessage {}
    
    message DummyMessage {
      message Sub {
        string f_string = 1;
      }
      enum Enum {
        ENUM_0 = 0;
        ENUM_1 = 1;
        ENUM_2 = 2;
      }
      string f_string = 1;
      repeated string f_strings = 2;
      int32 f_int32 = 3;
      repeated int32 f_int32s = 4;
      Enum f_enum = 5;
      repeated Enum f_enums = 6;
      Sub f_sub = 7;
      repeated Sub f_subs = 8;
      bool f_bool = 9;
      repeated bool f_bools = 10;
      int64 f_int64 = 11;
      repeated int64 f_int64s= 12;
      bytes f_bytes = 13;
      repeated bytes f_bytess = 14;
      float f_float = 15;
      repeated float f_floats = 16;
    }
    
    message IndexReply {
      message Endpoint {
        string path = 1;
        string description = 2;
      }
      string description = 1;
      repeated Endpoint endpoints = 2;
    }
  3. In BloomRPC, import the gRPC.proto file.

  4. In the left-side navigation pane, click DummyUnary. In the address field at the top, enter helloworld-grpc.default.example.com:80.

  5. Click the green run button. The service is working if the server returns a response without errors.

What's next