By default, Cloud Run downgrades HTTP/2 requests to HTTP/1 when those requests are sent to the container. If you want to explicitly set your service to use HTTP/2 end-to-end, with no such downgrading, you can configure it for HTTP/2. This page shows how to do the configuration.
For more information on invoking services using HTTP, refer to Invoking with an HTTPS Request.
Before you configure
Your Cloud Run service must handle requests in
HTTP/2 cleartext
(h2c
) format, because TLS is still terminated automatically by Cloud Run.
To confirm that your service supports h2c
requests,
test the service locally using this cURL command:
curl -i --http2-prior-knowledge http://localhost:PORT
Setting and updating HTTP/2 end-to-end
Any configuration change leads to the creation of a new revision. Subsequent revisions will also automatically get this configuration setting unless you make explicit updates to change it.
You can specify the use of HTTP/2 end-to-end using the Cloud Console, the gcloud command line, or a YAML file when you create a new service or deploy a new revision:
Console
Click Create Service if you are configuring a new service you are deploying to. If you are configuring an existing service, click on the service, then click Edit and Deploy New Revision.
Under Advanced Settings, click Connections.
Select the checkbox Enable http/2 connections
Click Create or Deploy.
Command line
You can update a given service to use HTTP/2 by using the following command:
gcloud beta run services update SERVICE --use-http2
Replace SERVICE
with the name of your service.
You can also set your service to use HTTP/2 during deployment using the command:
gcloud beta run deploy --image IMAGE_URL --use-http2
Replace IMAGE_URL
with a reference to the container image, for
example, gcr.io/myproject/my-image:latest
YAML
You can download and view existing service configuration using the
gcloud run services describe --format export
command, which yields
cleaned results in YAML format. You can then modify the fields described below and
upload the modified YAML using the gcloud beta run services replace
command.
Make sure you only modify fields as documented.
To view and download the configuration:
gcloud run services describe SERVICE --format export > service.yaml
Update
ports
with the nameh2c
andcontainerPort
with the port of your choice, as shown belows:apiVersion: serving.knative.dev/v1 kind: Service [...] spec: template: spec: containers: - image: IMAGE_URL ports: - name: h2c containerPort: 8080
Replace
IMAGE_URL
with a reference to the container image, for example,gcr.io/myproject/my-image:latest
Replace the service with its new configuration using the following command:
gcloud beta run services replace service.yaml