Many enterprises lookout for managed services to reduce the efforts for certain operations, such as server configuration management, infrastructure maintenance and provisioning, auto-scaling, disaster recovery, etc. The serverless services are a kind of managed services that can be scaled down to zero if no requests are made to the service/application. In such cases, server maintenance is looked after by outsourced cloud service providers with service-level agreements and objectives.
A container is a package of different software components and programs that runs in an isolated environment. It is lightweight and can be easily moved to any platform. In this blog, we will discuss one of the most critical containerized and serverless cloud solutions - Cloud Run - offered by Google Cloud.
Cloud Run is a way of building microservice-like applications that perform data processing/conversion jobs, batch operation jobs, scheduled jobs, and the jobs that perform data updates from the source to destination on-demand. Since batch and scheduled jobs run on a schedule or manual triggers, instead of allocating fixed resources, we can use Cloud Run to complete these jobs faster with sufficient resources for a limited time in a highly scalable environment. Cloud Run is built on Knative, a Kubernetes-based platform for serverless workloads.
Cloud Run is a developer-friendly service that can easily deploy services or applications using a docker image and invoke an HTTP trigger. The only effort required here is making a docker custom image from the application. Cloud Run service will expose a unique endpoint by default. It also gives an option to configure a custom domain name for a service or application.
Let’s look at the 3 concepts of Cloud Run:
Cloud Run also supports Anthos where it creates a Kubernetes cluster or uses an existing cluster to provide the resources for services or applications.
1. Make a custom image of your application using a docker file.
2. To push the docker image to a Google Container Registry, the naming convention of the image should go like
HOSTNAME : gcr.io
PROJECT-ID : your GCP project id
IMAGE : Image name(here flask-app)
TAG : Version (will take the latest version by default)
3. Once the image is generated, check generated images using the command ‘docker images.
4. To make the image available in Cloud Run, push the image in Google Container Registry.
5. Once the image is uploaded on Google Container Registry, go to Cloud Run and click on ‘Create a Service’
6. Enter the service name, choose the authorization option based on the requirement, and click Next.
7. Select the container image, click on advanced settings, and enter the container port that is mentioned in the code. In this example, we have used 8081 as a container port, where we replaced the default value 8080 with 8081. Click on Create.
8. Your application is now ready and a unique URL is provided to access the service. Test the URL.
Congratulations! The services are up and running now. This is one of the best options to build microservices and to leverage containerization technology.
Cloud Run is serverless, containerized, and highly scalable. It is one of the best options for tasks like event-based updates, scheduled tasks, data processing, and batch jobs. Since Cloud Run effortlessly uses Knative, it allows easy migration of jobs to Cloud Run by making a docker image from the existing service and application. It’s easy to save a lot of computing resources and costs with Cloud Run.