Serverless technology has just crossed the hype cycle and becoming a used technology in the industry. Google Cloud runs the latest player in the group and offers the service for a lesser cost than AWS and Azure.
In this blog post, we will create a hello world application and understand how things work.
Initial Setup
You need to login into the console and if you are logging in for the first time then it allows you to set up an account with 300$ for free.
You have to install gcloud CLI and follow the instructions to set up your first project.
Use the following page to set up Gcloud
Application
We will create a simple Hello World Application and deploy it to cloud run. Let’s open a visual studio and create an asp.net core empty Project.
Once you have the project, you can copy-paste the code.
Cloud Run
Cloud run can run any docker image you give, provided it can listen to 8080. To adhere to that requirement, we need to assign the Port 8080 and pass them in app.Run()
The second part is to create Docker, and right-click and select should do.
Once added, you can move the file to the following Solution file. You can also download the code from my Github repo.
Now it’s time to run the project in cloud run. Run the following command
gcloud builds submit --tag gcr.io/{Project-ID}/helloworld
Project ID here needs a replacement. You can find the Project ID from
gcloud projects list
Build command pushes the docker image to the Google Artifacts. It is like a Docker repository. In simple words, Artifacts is like a place where docker images go !!
Now that Docker images are known to the cloud deploying your app is time.
gcloud run deploy hello --image gcr.io/{Project-ID}/helloworld --allow-unauthenticated
Deploy command asks the cloud run to set up an engine to run a docker image and set up an HTTPS connection.
Cloud Run is the easiest way to deploy the application to the internet and mostly for free of charge.