Voiced by Amazon Polly |
Overview
In today’s fast-paced world of software development, deploying applications quickly and efficiently is crucial. Dockerization and serverless platforms like Google Cloud Run have emerged as powerful tools to streamline deployment. In this blog post, we will guide you through creating a Docker image, pushing it to Artifact Registry, deploying the image on Google Cloud Run, and updating the application with zero downtime using the command-line interface (CLI).
Pioneers in Cloud Consulting & Migration Services
- Reduced infrastructural costs
- Accelerated application deployment
Introduction
Google Cloud Run is a serverless computing platform that allows developers to deploy and manage applications as scalable, stateless containers. Leveraging the power of Kubernetes and Native, it offers a flexible and seamless way to run applications in the cloud.
Pre-requisites
- GCP Account: You need an active Google Cloud Platform (GCP) account.
- Access to the Resources: Ensure you have access to the necessary resources within your GCP account to create and manage services.
- Cloud Shell: Access to Google Cloud Shell, a browser-based terminal for interacting with GCP resources and executing commands.
Step-by-Step Guide
Step 1 – Replicate the Source Repository
If you are deploying a pre-existing website, duplicating the source is all you must do. This allows you to concentrate on generating Docker images and launching them on Google Cloud Run.
Begin by opening a new Cloud Shell window and executing the subsequent instructions to clone the Git repository and switch to the designated directory:
1 2 |
$$ git clone https://github.com/googlecodelabs/monolith-to-microservices.git $$ cd ~/monolith-to-microservices |
Next, execute this command to install the NodeJS dependencies, enabling you to test the application before deployment:
1 |
$$ ./setup.sh |
This process will take a few minutes to complete. You will receive a confirmation of success once it’s done.
To test your application, initiate the web server by executing the following command:
1 2 |
$$ cd /monolith-to-microservices/monolith $$ npm start |
Create one artifact registry in GCP to store the images built during this phase.
GCP console >> Artifact-registry >> Repositories >> Create Repository
Enter the below details and click on Create.
Step 2 – Configure Authentication:
Before attempting to push or pull images, it’s essential to configure Docker to utilize the Google Cloud CLI for authentication when requesting Artifact Registry.
To configure authentication for Docker repositories in the “asia-south1” region, execute the following command within Cloud Shell:
1 |
$$ gcloud auth configure-docker asia-south1-docker.pkg.dev |
This command will update your Docker configuration, allowing you to connect with Artifact Registry in your Google Cloud project and facilitate image push and pull operations.
First, enable the Google Cloud Build, Artifact Registry, and Google Cloud Run APIs. Use the following command to enable them:
1 2 3 |
$$ gcloud services enable artifactregistry.googleapis.com \ cloudbuild.googleapis.com \ run.googleapis.com |
Once the APIs are successfully enabled, initiate the build process by executing the following command:
1 |
$$ gcloud builds submit --tag asia-south1-docker.pkg.dev/storage-migration-398805/cloudrun/monolithsampleapp:1.0 |
Step 3 – Deploy the Container to Google Cloud Run
After successfully containerizing your website and pushing the container to Artifact Registry, it’s now time to proceed with the deployment on Google Cloud Run.
Deployment on Google Cloud Run can be accomplished through two approaches:
- Managed Google Cloud Run: This involves utilizing the Platform as a Service model, where the entire container lifecycle is managed by the Google Cloud Run product itself. This is the approach you’ll be using for this particular lab.
- Google Cloud Run on GKE: This approach offers an additional layer of control, allowing you to utilize your own clusters and pods from Google Kubernetes Engine (GKE). If you wish to learn more about this approach, you can find additional information [here](link_to_more_information).
To initiate the deployment of the image to Google Cloud Run, execute the following command:
1 |
$$ gcloud run deploy monolith --image asia-south1-docker.pkg.dev/storage-migration-398805/cloudrun/monolithsampleapp:1.0 --region asia-south1 |
Step 4 – Modify the changes in code and start building the new image
1 |
$$ gcloud builds submit --tag asia-south1-docker.pkg.dev/storage-migration-398805/cloudrun/monolithsampleapp:2.0 |
Go to the artifact-registry and check for the image with version 2.0.
Step 5 – Update application with zero downtime:
Now, it’s essential to update the website seamlessly, ensuring no disruption for the users. Cloud Run adopts an approach where each deployment is treated as a new Revision, gradually transitioning it online and then redirecting traffic to it.
1 |
$$ gcloud run deploy monolith --image asia-south1-docker.pkg.dev/storage-migration-398805/cloudrun/monolithsampleapp:2.0 --region asia-south1 |
Conclusion
With Google Cloud Run, businesses achieve flexible, on-demand application execution while minimizing operational overhead. Its compatibility with various frameworks and rapid scaling capabilities makes it a powerful tool for modern, efficient software deployment.
Drop a query if you have any questions regarding Google Cloud Run and we will get back to you quickly.
Making IT Networks Enterprise-ready – Cloud Management Services
- Accelerated cloud migration
- End-to-end view of the cloud environment
About CloudThat
CloudThat is an official AWS (Amazon Web Services) Advanced Consulting Partner and Training partner, AWS Migration Partner, AWS Data and Analytics Partner, AWS DevOps Competency Partner, Amazon QuickSight Service Delivery Partner, AWS EKS Service Delivery Partner, and Microsoft Gold Partner, helping people develop knowledge of the cloud and help their businesses aim for higher goals using best-in-industry cloud computing practices and expertise. We are on a mission to build a robust cloud computing ecosystem by disseminating knowledge on technological intricacies within the cloud space. Our blogs, webinars, case studies, and white papers enable all the stakeholders in the cloud computing sphere.
To get started, go through our Consultancy page and Managed Services Package, CloudThat’s offerings.
FAQs
1. What is Google Cloud Run and how does it differ from traditional serverless platforms?
ANS: – Google Cloud Run is a serverless computing platform that allows developers to deploy and run applications in containers. Unlike traditional serverless platforms, Google Cloud Run enables developers to use their own containerized code, providing more flexibility and compatibility with existing tools and frameworks.
2. How does scaling work in Google Cloud Run?
ANS: – Google Cloud Run automatically scales your application based on incoming request traffic. It can handle multiple requests concurrently by dynamically adjusting the number of container instances, ensuring optimal performance and responsiveness. This scaling is efficient and can handle both high and low traffic periods seamlessly.
WRITTEN BY Anil Kumar Y A
Anil Kumar Y A works as a Research Associate at CloudThat. He knows GCP Cloud Services and resources and DevOps tools like Docker, K8s, Ansible, and Terraform, and he is also passionate about improving his skills and learning new tools and technologies.
Click to Comment