Google Cloud Run [NEW] beta
NoteThis feature is currently experimental and subject to change. Not all Skaffold features are supported, for example
debugis currently not supported in Cloud Run (but is on our roadmap).
Cloud Run is a managed compute platform on Google Cloud that allows you to run containers on Google’s infrastructure. With Skaffold, now you are able to configure your dev loop to build, test, sync and use Cloud Run as the deployer for your images.
Deploying applications to Cloud Run
Skaffold can deploy Services and Jobs to Cloud Run. If this deployer is used, all provided manifests must be valid Cloud Run services, using the
serving.knative.dev/v1 schema, or valid Cloud Run jobs.
See the Cloud Run YAML reference for supported fields.
In order to use this deployer you’ll need to configure some tools first.
The deployer uses the
gcloud CLI to perform its tasks, so be sure it is installed in your environment. It will use the application default credentials to deploy. You can configure this to use your user credentials by running:
gcloud auth application-default login
To enable Log streaming and Port forwarding some extra components are needed from
gcloud. To install them run the following comand in your terminal:
gcloud components install --quiet \ alpha \ beta \ log-streaming \ cloud-run-proxy
From the previous command,
log-streaming components are needed for Log streaming,
cloud-run-proxy components are needed for Port forwarding.
Cloud Run Services and Jobs deployment
With Skaffold you can deploy Cloud Run Services and Jobs just referencing them from the
skaffold.yaml file. The following example ilustrates a project using the Cloud Run deployer:
With the following project folder structure:
resources/ cloud-run-service.yaml cloud-run-job.yaml skaffold.yaml
apiVersion: serving.knative.dev/v1 kind: Service metadata: name: cloud-run-service-name # this service will be created in Cloud Run via Skaffold spec: template: spec: containers: - image: gcr.io/cloudrun/hello
apiVersion: run.googleapis.com/v1 kind: Job metadata: name: cloud-run-job-name # this job will be created in Cloud Run via Skaffold annotations: run.googleapis.com/launch-stage: BETA spec: template: spec: template: spec: containers: - image: us-docker.pkg.dev/cloudrun/container/job
apiVersion: skaffold/v4beta2 kind: Config manifests: rawYaml: - resources/* deploy: cloudrun: projectid: YOUR-GCP-PROJECT region: GCP-REGION
skaffold run will deploy one Cloud Run service, and one Cloud Run job in the
YOUR-GCP-PROJECT project, inside the given
NoteThe previous example will deploy a Cloud Run job, however, it will not trigger an execution for that job. To read more about jobs execution you can check the Cloud Run docs.
Skaffold will manage automatically the necessary configuration to open the deployed Cloud Run services URLs locally, even if they are private services, using the Cloud Run proxy and Skaffold’s Port Forwarding. To enable this, you will have to either add the
--port-forward flag running Skaffold, or add a
portForward stanza in your
skaffold.yaml file. From the previous example, running
skaffold dev --port-forward will result in the following output:
... Deploying Cloud Run service: cloud-run-job-name Deploying Cloud Run service: cloud-run-service-name Cloud Run Job cloud-run-job-name finished: Job started. 1/2 deployment(s) still pending cloud-run-service-name: Service starting: Deploying Revision. Waiting on revision cloud-run-service-name-2246v. cloud-run-service-name: Service starting: Deploying Revision. Waiting on revision cloud-run-service-name-2246v. Cloud Run Service cloud-run-service-name finished: Service started. 0/2 deployment(s) still pending Forwarding service projects/<YOUR-GCP-PROJECT>/locations/<GCP-REGION>/services/cloud-run-service-name to local port 8080 ...
Here you’ll see the port to use to access the deployed Cloud Run service, in this case you can access it through
localhost:8080. If you need to change the local port used, you’ll need to add a
Using the previous example, changing
apiVersion: skaffold/v4beta2 kind: Config manifests: rawYaml: - resources/* deploy: cloudrun: projectid: YOUR-GCP-PROJECT region: GCP-REGION # Added to change local port used portForward: - resourceType: service resourceName: cloud-run-service-name localPort: 9001
skaffold dev --port-forward, will result in:
... Forwarding service projects/<YOUR-GCP-PROJECT>/locations/<GCP-REGION>/services/cloud-run-service-name to local port 9001 ...
Now you will be able to access the deployed service through
When doing local development, Skaffold will log stream to your console the output from the Cloud Run services deployed. From the previous example, running
skaffold dev --port-forward or
skaffold run --tail --port-forward in your terminal, you will see the following output:
... Cloud Run Service cloud-run-service-name finished: Service started. 0/2 deployment(s) still pending Forwarding service projects/<YOUR-GCP-PROJECT>/locations/<GCP-REGION>/services/cloud-run-service-name to local port 9001 No artifacts found to watch Press Ctrl+C to exit Watching for changes... [cloud-run-service-name] streaming logs from <YOUR-GCP-PROJECT> ...
Now Skaffold is log streaming the output from the service. If you access it through
localhost:9001, you’ll see the logs:
... [cloud-run-service-name] streaming logs from renzo-friction-log-cloud-run [cloud-run-service-name] 2023-01-27 00:52:22 2023/01/27 00:52:22 Hello from Cloud Run! The container started successfully and is listening for HTTP requests on $PORT [cloud-run-service-name] 2023-01-27 00:52:22 GET 200 https://cloud-run-service-name-6u2evvstna-uc.a.run.app/
Configuring Cloud Run
To deploy to Cloud Run, use the
cloudrun type in the
deploy section, together with
manifests.rawYaml stanza of
cloudrun type offers the following options:
||the GCP Project to use for Cloud Run. If specified, all Services will be deployed to this project. If not specified, each Service will be deployed to the project specified in
||GCP location to use for the Cloud Run Deploy. Must be one of the regions listed in https://cloud.google.com/run/docs/locations.|
||describes a set of lifecycle host hooks that are executed before and after the Cloud Run deployer.|
deploy section instructs Skaffold to deploy the artifacts under
manifests.rawYaml to Cloud Run:
manifests: rawYaml: # Here should be the list of all the Cloud Run Services and Jobs to deploy - cloud-run-service.yaml deploy: cloudrun: projectid: my-gcp-project region: us-central1
NoteImages listed to be deployed with the Cloud Run deployer must be present in Google Artifact Registry or Google Container Registry. If you are using Skaffold to build the images, ensure
pushis set to true.