What is CloudRun
Cloud run is what i expected Appengine to be - A container plantform without any proprietary API’s or restrictions. Cloudrun recently announced GA.
Pro’s
- Scale to zero container instances when there is no traffic.
- Built on Knative and its portable across platforms and minimize lock-in
- Pay-per use model - pay only for compute/mem/network used.
- If you have existing GKE cluster then there is an add-on to use CloudRun on the existing GKE cluster.
Con’s
- Currently you cannot check the current number of active instances. It isn’t clear if the instance was shutdown when there is no traffic. Additional reference: link here
- Cannot configure CPU on fully-managed instance. Its possible only with on-prem Anthos.
- While building from docker - files need to be in current directory of host and not target subdirectory.
Step 2/4 : COPY HelloStackExplorer-0.0.1-SNAPSHOT.jar /HelloStackExplorer-0.0.1-SNAPSHOT.jar COPY failed: stat /var/lib/docker/tmp/docker-builder188329130/HelloStackExplorer-0.0.1-SNAPSHOT.jar: no such file or directory ERROR ERROR: build step 0 "gcr.io/cloud-builders/docker" failed: exit status 1 -------------------------------------------------------------------------------- ERROR: (gcloud.builds.submit) build 7a43b056-0ac3-4fba-bed6-33b59fcff9b1 completed with status "FAILURE"
CloudRun example
In order to use CloudRun you just need to buld and deploy your application as container with any language/tools of your choice. Following steps give an example of running hello world web application:
- Build the app
- Write code
- Define Docker file
As a quick hello-world example of app with docker file created the following: HelloWorldSpringBoot repo Just checkout the code locally for this step.
- Publish Docker image to repo
gcloud builds submit --tag gcr.io/stackexplorer-project/hello
Published container is submitted to the private continer registery for your project. Its not visible to others.
- Deploy the docker file to CloudRun
gcloud run deploy --tag gcr.io/stackexplorer-project/hello
Provide service name and region, after successful deployment it shows the
Alternatively you can deploy it to CloudRun on Existing GKE cluster using:
gcloud run deploy --tag gcr.io/stackexplorer-project/hello \
--cluster=mygkecluster
Cost
You can manage costs by setting limit for memory allocated per instance, max/min number of instances. Reference: https://cloud.google.com/run/docs/configuring/max-instances
Example command to set memory limit and max instances:
gcloud run deploy --image gcr.io/stackexplorer-project/hello \
--max-instances 3 --memory 250 --platform managed