Google Cloud Run

What is Cloud Computing?

Cloud Computing is on-demand access to computing resources – including servers, applications, data storage, networking functionality, development tools, databases, analytics and intelligence and further more- over the internet. It offers faster innovation, flexibility in acquiring resources and better economies of scale. It saves the enterprises from spending on procuring, configuring and managing resources themselves. In simple words, it lowers IT costs, enhances agility and time-to-value, and scales more easily and cost-effectively. To cover all these advantages, Google offers a platform for cloud computing where the users only pay for the services they used and the rest is handled by Google Cloud itself.

What is Google Cloud Platform (GCP)?

GCP is a suite of cloud computing services, offered by Google, that runs on the same infrastructure that Google uses internally for its end-user products such as Gmail, Google Search, YouTube etc. Google Cloud Platform provides infrastructure as a service, platform as a service, and serverless computing environments. It is cost-effective and highly scalable. It offers custom Machine types where it allows applications to adapt to various amount of traffic. It has IoT(Internet of Things) core which is a fully managed service that allows you to easily and securely connect, manage, and ingest data from millions of globally dispersed devices.

It also has an API platform and ecosystem which allows you to work in any language you prefer. GCP offers Big Data Analyses that helps you explore and layer data points, and they also make data analytics a lot easier for enterprise customers. These utility datasets let you start with a set of valid, clean data, rather than having to start from scratch. Cloud AI services are also provided by GCP that give sophisticated machine learning models and improve current capabilities by enabling more efficient use of data.

Google Cloud Platform also has Security services which includes Cloud Resource Manager, Cloud IAM, Cloud Security Scanner and Cloud Platform. These security services set up permission rights and scan all applications or links for any vulnerabilities. It also offers Network Services such as Cloud Virtual Network, Cloud Load Balancing, Cloud CDN (Content Delivery Network) and Cloud DNS (Domain Network Service) where Cloud CDN solves data latency problems by allocating edge locations to every data center which helps in swiftly retrieving the frequently accessed data from the data server by caching it in a particular edge location. Cloud DNS provides the information on where the data resides.

In simple words, GCP help users and application programmers to create a serverless execution environment which helps in developing an application and testing the same by creating virtual machines. It maintains all their work without the hassle of worrying about the underlying infrastructure.

Deploy a Flask API to Google Cloud Run using GCP

Before we deploy a Flask API on Google Cloud Run, there are some pre-requisites that are to be taken care of.

  1. Create an account on GCP. This will require you to add some billing or card details. The best thing about GCP is that it will give you $300 free to use.
  2. Open thin link https://console.cloud.google.com/
  3. Click the icon, to the right of Google Cloud
  4. Click on New Project

5. Fill in all the details and then click on Create.

6. Open into the project that you just created. It will provide you The information of your project. The most important is the Project ID which will be be used further later.

7. Now, enable Cloud API by searching it on the Google Cloud. Make sure you are in the project that you just made and will deploy in future. You will know this by checking if that Project Name is showing on the right of Google Cloud.

8. Now, Install Google Cloud CLI through the following link. For the steps, follow the link under ‘Install’. https://dl.google.com/dl/cloudsdk/channels/rapid/GoogleCloudSDKInstaller.exe

9. Initialize the Google Cloud CLI

gcloud init

10. Set up GCP account and project by typing these on Google Cloud SDK Shell:


$ gcloud config set account $MY_EMAIL_ADDRESS #type email address

$ gcloud auth login $MY_EMAIL_ADDRESS
$ gcloud config set project $MY_PROJECT_ID #this is the Project ID that we talked about previously.

11. Make a flask API application, which must have main.py, requirement.txt and Dockerfile. For this, first we need to download Docker Desktop for Windows. Make sure that Hyper-V and virtualization BIOS are enabled in your Window.

12. Follow these following codes:

main.py

requirements.txt

Dockerfile

Your app is finished and ready to be deployed.

13. Deploy this app to Cloud Run by writing the following code to your source code directory:

$ gcloud run deploy

If prompted to enable the API, Reply y to enable.

  1. When you are prompted for the source code location, press Enter to deploy the current folder.
  2. When you are prompted for the service name, press Enter to accept the default name, helloworld or anything you want to name it
  3. If you are prompted to enable the Artifact Registry API, respond by pressing y.
  4. When you are prompted for region: select the region of your choice, for example us-central1.
  5. You will be prompted to allow unauthenticated invocations: respond y .

If the deployment is successful, you will get a URL at the end and this is what you see.

14. Copy the URL and open it on browser.

Write a Comment

Your email address will not be published. Required fields are marked *