Google cloud platform: Getting started with GCP virtual machine and run an application in VM instance

In this post we will start with creating an GCP Virtual machine instance and create an express.js web application.

Prerequisite: Have a GCP account with billing enabled. Please refer how to get started with Google Cloud Platform account setup.

Lets open GCP console and create a VM instance. (If you are creating very first time then Google will enforce to enable Compute engine). It will take few seconds to complete and


Configure all the details to define your virtual machine: Click "Create Instance" and provide a valid name for VM. I have used "instance-express-learn". There are multiple ways to create VM(using predefined template, create custom template, etc), I am going ahead with default options of machine configuration.



Click "CREATE" or Copy command from "EQUIVALENT COMMAND LINE" (run command in Cloud shell) to create VM.


What is Google Cloud shell and Where you can find google Cloud shell?

  • Ephemeral VM which offers a terminal on the browser. 
  • Click on Activate Cloud Shell ">". It will open session for executing commands.
 

 
Verify VM is running/listing of your VM instances
:

  • Green tick indicates that VM is successfully created and running. 
  • From cloud shell, run following command and list of all VM's running.When you connect to VMs using the Cloud Console, Compute Engine creates an ephemeral SSH key for you

    n0r0082@m-c02z31rnlvdt ~ % gcloud compute instances list
    NAME                    ZONE           MACHINE_TYPE  PREEMPTIBLE  INTERNAL_IP  EXTERNAL_IP     STATUS
    instance-express-learn  us-central1-a  e2-medium                  10.128.0.2   34.123.1xx.2xx  RUNNING
    

We have a running virtual machine with adequate infrastructure spawned with just few clicks/commands. This summarize beautifully why Cloud is a buzzword :) 

How to access GCP VM from local terminal

  1. Please refer Install the Google Cloud CLI / Cloud SDKs by language to setup gcloud locally.
  2. Once gcloud has been setup, we can login to GCP from terminal. First authenticate terminal session using following command.
    n0r0082@m-c02z31rnlvdt ~ % gcloud auth login
    Your browser has been opened to visit:
    
        https://accounts.google.com/o/oauth2/auth?response_type=code
    &client_id=VERY_BIG_STRING..... You are now logged in as [nikhil*******@gmail.com]. Your current project is [None]. You can change this setting by running: $ gcloud config set project PROJECT_ID Updates are available for some Cloud SDK components. To install them, please run: $ gcloud components update 

    On prompt, click Allow and It will open web browser and enforce to login with an emailId (Use emailId which has been used to create GCP account)
     

     

  3. Once authenticated, close web browser or you can go to console. 
  4. Set PROJET_ID as recommended by above command and Run command to list VM's and we will get same result as command ran from Cloud shell.
    n0r0082@m-c02z31rnlvdt ~ % gcloud config set project named-magnet-342122
    Updated property [core/project].
    n0r0082@m-c02z31rnlvdt ~ %
    n0r0082@m-c02z31rnlvdt ~ %
    n0r0082@m-c02z31rnlvdt ~ % gcloud compute instances list
    NAME                    ZONE           MACHINE_TYPE  PREEMPTIBLE  INTERNAL_IP  EXTERNAL_IP     STATUS
    instance-express-learn  us-central1-a  e2-medium                  10.128.0.2   34.123.124.191  RUNNING
    

    • What is PROJECT_ID value? - Fetch PROJECT_ID value from GCP Console. ID value is PROJECT_ID value.


Create express.js web-application in VM:

  1.  Install node.js and update with latest versio{by default node is installed in VM}
    nikhilranjan2712@cloudshell:~ (named-magnet-342122)$ node --version
    v12.14.1
    
    >>>Update node version with latest
    nikhilranjan2712@cloudshell:~ (named-magnet-342122)$ nvm install stable
    Downloading and installing node v17.6.0...
    Downloading https://nodejs.org/dist/v17.6.0/node-v17.6.0-linux-x64.tar.xz...
    ###############################################.... 100.0%
    Computing checksum with sha256sum
    Checksums matched!
    Now using node v17.6.0 (npm v8.5.1)
    nikhilranjan2712@cloudshell:~ (named-magnet-342122)$ node --version 
    v17.6.0
  2. Set default to latest version
    nikhilranjan2712@cloudshell:~ (named-magnet-342122)$ nvm alias default stable
    default -> stable (-> v17.6.0)
  3. Install exress-generator and then using exress-generator create an app named "client-app"
    nikhilranjan2712@cloudshell:~ (named-magnet-342122)$ npm install -g express-generator
    nikhilranjan2712@cloudshell:~ (named-magnet-342122)$ npm audit fix --force
    nikhilranjan2712@cloudshell:~ (named-magnet-342122)$ npm install -g express-generator
    
    create : client-app/
       create : client-app/public/
       create : client-app/public/javascripts/
       create : client-app/public/images/
       create : client-app/public/stylesheets/
       create : client-app/public/stylesheets/style.css
       create : client-app/routes/
       create : client-app/routes/index.js
       create : client-app/routes/users.js
       create : client-app/views/
       create : client-app/views/error.jade
       create : client-app/views/index.jade
       create : client-app/views/layout.jade
       create : client-app/app.js
       create : client-app/package.json
       create : client-app/bin/
       create : client-app/bin/www
    
       change directory:
         $ cd client-app
    
       install dependencies:
         $ npm install
    
       run the app:
         $ DEBUG=client-app:* npm start
    

  4. Start app using following command
    nikhilranjan2712@cloudshell:~/client-app (named-magnet-342122)$ DEBUG=client-app:* npm start   
    
    > client-app@0.0.0 start
    > node ./bin/www
    
      client-app:server Listening on port 3000 +0ms
  5. Access application http://localhost:3000. Open a new console and access app using curl command.

-----====-----------

38 Comments

  1. I read your blog now share great information here.
    Bobcat hire

    ReplyDelete
  2. I can't express enough how valuable Whizlabs has been in my pursuit of the Google Cloud Architect certification. The information provided on updated exam practice questions is not only accurate but also aligned with the latest industry trends. The training offered a structured learning path, and the online course was a treasure trove of knowledge. The hands-on labs were instrumental in honing my practical skills, making me feel more confident in implementing cloud architectures on GCP. Whizlabs' commitment to providing a holistic approach to certification is truly commendable.

    ReplyDelete
  3. https://gardenersschool.com/calendula-the-cheerful-versatile-flower/

    ReplyDelete
  4. Toilet Bowl Cleaner Liquid, introducing our premium solution tailored for your household’s needs. Formulated to effortlessly tackle tough stains and germs, leaving your toilet sparkling clean and smelling fresh with every use. Say goodbye to grime and hello to a hygienic, inviting bathroom experience.

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. MonkTaxSolutions is providing outsourced accounting services with tax preparations & payroll services, etc. Switch to an affordable accounting solution today. Our team will manage the whole process. Our team of professional bookkeepers and accountants provides the services that clients need, with our rates typically 50% less than the equivalent service. Speak to us today!

    Visit - https://monktaxsolutions.com/

    ReplyDelete
  7. Getting started with Google Cloud Platform (GCP) involves creating a virtual machine (VM) instance via the GCP Console, configuring it with necessary resources, and then deploying and running your application on this instance. This process allows you to leverage GCP's robust infrastructure for scalable and reliable application hosting.

    Plz Visit my Website:- Door to Door Car Shipping Services

    ReplyDelete
  8. This blog is an absolute gem! It's packed with valuable information and practical advice that can truly benefit people. wavesprinter

    ReplyDelete
  9. Your blog has quickly become one of my favorites. The depth and quality of your content are truly impressive. Looking forward to your next post! plan to visit - team outing venues in Jhajjar,
    pratapgarh farms and resorts in Jhajjar
    is best place for day event near delhi.

    ReplyDelete
  10. Kpop4d merupakan link situs slot gacor gampang menang yang sudah mendapat legalisir dari lembaga judi Internasional.

    ReplyDelete
  11. Excited to learn more about Google Cloud Platform's virtual machines and running applications? This article is a great starting point! Looking forward to diving in and exploring the possibilities.

    ReplyDelete
  12. Your blog is packed with valuable information. Thankyou!!!

    ReplyDelete
  13. I enjoyed reading your blog article. I'm grateful that you shared.

    ReplyDelete
  14. This article is a great starting point! Looking forward to diving in and exploring the possibilities.

    ReplyDelete
  15. Extremely appreciated. Thanx for being here.

    ReplyDelete
  16. The Hayati Pro Ultra is priced at £8.98 for a single unit, with discounts available for bulk purchases. It aims to provide a blend of convenience, style, and long-lasting performance for vaping enthusiasts.
    For more details, you can visit the
    OrderVape website.

    ReplyDelete
  17. Thank you for this information and putting some pictures that helps us understand the topic. I'm glad I encountered your informative blog content. If you want to play games while earning as well, you may try and visit my blog to know how: https://pinaskohan.com/maswerte/

    ReplyDelete
  18. Thank you for providing such a detailed and insightful article. It's incredibly helpful and offers valuable information that I can easily apply. Great Job!
    https://pinaskohan.com/phbet-casino-online/

    ReplyDelete
  19. Getting started with Google Cloud Platform (GCP) is straightforward. First, create a GCP account and navigate to the Compute Engine section to set up a virtual machine (VM). Choose your desired configuration and operating system, then deploy the VM instance. Once your VM is running, you can SSH into the instance and install the necessary software to run your application. For those balancing tech projects with academic commitments, consider utilizing dissertation writing services to ensure you stay on top of your studies while exploring GCP.

    ReplyDelete
  20. Nice Blog, its really help to our projects . looking forward to more blog like this. thankyou

    ReplyDelete
  21. Starting with Google Cloud Platform's virtual machines is straightforward and powerful. By creating a VM instance through the GCP console or command line, you can quickly define configurations and launch within seconds. The Cloud Shell provides an ephemeral VM terminal accessible directly from your browser, simplifying command execution and management. Once set up, accessing VMs from your local terminal involves installing the Cloud SDK, authenticating, and using commands like gcloud to interact seamlessly. It's a robust platform for deploying applications like an express.js web-app, leveraging cloud infrastructure effortlessly."

    ISO Certification in iraq

    ReplyDelete
  22. I appreciate you sharing this kind of content. I am a blogger and I do contents about earning gaming apps. If you're interested to know about it, you may visit my blog by clicking my profile name.

    ReplyDelete
  23. AT thechickenfarmers
    We provide
    BEST HENS
    Our hens are bred for their impressive egg-laying capabilities. They consistently deliver a high volume of eggs, ensuring a reliable and abundant supply for your needs.
    EGGS
    We prioritize the quality of the eggs our hens produce. You can expect eggs with vibrant yolks, excellent taste, and optimal nutritional value, making them perfect for both culinary delights and nutritious meals.

    Visit our websitehttps://thechickenfarmers.com/
    https://thechickenfarmers.com/
    Natural and Sustainable Farming
    you can be confident that you are getting poultry products that are free from added hormones and antibiotics. We prioritize natural and sustainable farming methods, allowing our birds to roam freely in spacious, clean environments and providing them with a balanced diet to promote their overall health.

    ReplyDelete
  24. If the dog continues toward the boundary, the collar delivers a mild static correction, encouraging the dog to retreat click here. Over time, dogs learn to associate the warning beep with the static correction and avoid the boundary. This training process is crucial for the system's success and typically involves positive reinforcement techniques.

    ReplyDelete
  25. Thank you for the clear and insightful writing. I really appreciate it! also visit my website

    ReplyDelete
  26. Thank you for the invaluable information you provide. Your blog is a beacon of knowledge.

    ReplyDelete
  27. I always find your posts to be so enlightening and full of useful information. Your blog is an incredible resource.

    ReplyDelete
  28. This comment has been removed by the author.

    ReplyDelete
  29. Thank you for sharing your thoughts! 🌟

    For those seeking the ultimate comfort upgrade, look no further than our Best Car Seat Cushionand Office Chair. Engineered for superior support and pressure relief, this cushion transforms long drives and extended office hours into more comfortable experiences. Its gel-infused design molds to your body, ensuring a cool and comfortable seating experience. Plus, it's versatile and portable, allowing you to bring comfort with you wherever you go!

    Learn more about our gel seat cushions - https://econour.com/collections/best-seat-cushion

    ReplyDelete
  30. See how businesses like yours successfully implemented DMARC and improved security.

    ReplyDelete
  31. I am Assignment helper working as an assignment helper in Workingment. Our team providing support and guidance their acadmeic success. Every students are worried about who Do My Assignment.

    ReplyDelete

  32. You can read more articles on the topic of opportunities to become a little richer and more productive in online business!

    ReplyDelete
  33. The information you shared is incredibly helpful and very beneficial for those who need it, like me. The Best Travel Agency in Dhaka

    ReplyDelete
  34. Promoedge is a leading media Production House In Delhi, renowned for its innovative approach and high-quality production services. Specializing in a wide range of media solutions, including corporate films, commercials, digital content, and event coverage, Promoedge combines cutting-edge technology with creative expertise to deliver compelling visual experiences.

    ReplyDelete
  35. Ultron services Calgary - secondary backyard suite in Calgary - backyard suite construction - flat roofing repair in Airdried - airdried roofing experts - airdried roof replacement.

    ReplyDelete
Previous Post Next Post