3
votes

How do you make Cloud Run for Anthos forward incoming HTTP2 requests to a Cloud Run service as HTTP2 instead of HTTP/1.1?

I'm using GCP with Cloud Run for Anthos to deploy a Java application that runs a GRPC server. The Cloud Run app is exposed publicly. I have also configured Cloud Run for Anthos with an SSL cert. When I try to use a GRPC client to call my service, client sends request over HTTP2 which the load balancer accepts but then when the request is forwarded to my Cloud Run service (a Java application running GRPC server), it comes in as HTTP/1.1 and gets rejected by the GRPC server. I assume somewhere between the k8 load balancer and my k8 pod, the request is being forwarded as HTTP/1.1 but I don't see how to fix this.

2

2 Answers

1
votes

Bringing to together @whlee's answer and his very important followup comment, here's exactly what I had to do to get it to work.

You must deploy using gcloud cli in order to change the named port. The UI does not allow you to configure the port name. Deploying from service yaml is currently a beta feature. To deploy, run: gcloud beta run services replace /path/to/service.yaml

In my case, my service was initially deployed using the GCP cloud console UI, so here are the steps I ran to export and replace.

  1. Export my existing service (named hermes-grpc) to yaml file:
gcloud beta run services describe hermes-grpc --format yaml > hermes-grpc.yaml
  1. Edit my export yaml and make the following edits:

replaced:

        ports:
        - containerPort: 6565

with:

        ports:
          - name: h2c
            containerPort: 6565

deleted the following lines:

          tcpSocket:
            port: 0

Deleted the name: line from the section

spec:
  template:
    metadata:
...
      name:
  1. Finally, redeploy service from edited yaml:
gcloud beta run services replace hermes-grpc.yaml

In the end my edited service yaml looked like this:

apiVersion: serving.knative.dev/v1alpha1
kind: Service
metadata:
  annotations:
    client.knative.dev/user-image: interledger4j/hermes-server:latest
    run.googleapis.com/client-name: cloud-console
  creationTimestamp: '2020-01-09T00:02:29Z'
  generation: 3
  name: hermes-grpc
  namespace: default
  selfLink: /apis/serving.knative.dev/v1alpha1/namespaces/default/services/hermes-grpc
spec:
  template:
    metadata:
      annotations:
        autoscaling.knative.dev/maxScale: '2'
        autoscaling.knative.dev/minScale: '1'
        run.googleapis.com/client-name: cloud-console
    spec:
      containerConcurrency: 80
      containers:
        image: interledger4j/hermes-server:latest
        name: user-container
        ports:
          - name: h2c
            containerPort: 6565
        readinessProbe:
          successThreshold: 1
        resources:
          limits:
            cpu: 500m
            memory: 384Mi
      timeoutSeconds: 300
  traffic:
  - latestRevision: true
    percent: 100