Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Last Updated: Mar 27, 2024
Difficulty: Easy

Overview of Cloud Code for VS Code

Leveraging ChatGPT - GenAI as a Microsoft Data Expert
Speaker
Prerita Agarwal
Data Specialist @
23 Jul, 2024 @ 01:30 PM

Introduction

The Google Cloud Platform is a collection of computing, networking, storage, big data, machine learning, and management services that Google offers. It utilizes the same cloud infrastructure that Google uses for its own internal applications, including Google Search, Gmail, Google Photos, and YouTube.
 

Google Cloud Platform

 

In this blog, we will discuss the Overview of Cloud Code for VS Code, like installing VS Code, managing client libraries and debugging Kubernetes applications using VS Code.

Installing the Cloud code extension for VS Code

The first topic in the "Overview of Cloud Code for VS Code" series is installing the cloud extension.

Before beginning, we must prepare the environment for the system. Here are some quick setup steps:-

Step 1. Set up Visual Studio Code on your computer by installing it.

Step 2. Configure and install language support that works best with Cloud Code, such as NodeJS, Python, Go, Java, and .NET.

Step 3. Set up  GIT in order to copy the samples to your computer.

Step 4. Add the Docker client to the PATH environment variable after installation.

Step 5. Create a Google Cloud project if you're utilizing it, then activate billing.

You can manage APIs, enable Google Cloud services, add and delete collaborators, gather similar resources for a single application in one location, and manage permissions for Google Cloud resources using projects.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Setting up Cloud Code

Step 1. From the Visual Studio Code Marketplace, install the plugin. Alternatively, you can search for the Cloud Code extension and then click Install in the Extensions tab of Visual Studio Code by clicking the Extension icon for Extensions or by pressing Ctrl/Cmd+Shift+X.

Step 2. Restart the VS Code if prompted. Using the top-level application taskbar, set your Cloud Code installation according to your preferences:  Code under Preferences > Extensions > Settings> Cloud Code.

Custom Version of Cloud Code Dependencies

In the "Overview of Cloud Code for VS Code," steps to use the custom version of Cloud code Dependencies are:-

Step 1. Set Auto Dependencies (cloudcode.autoDependencies) to off by selecting Settings > Manage > Settings.

Step 2. Add dependencies such as “Kubetl, Skaffold, minikube, and Google Cloud CLI”  to your PATH by installing them.

Deploying a Kubernetes application by remote development

In this part of “Overview of Cloud Code for VS Code,” we will discuss deploying Kubernetes applications by remote development.

Steps to create a Kubernetes application

Step 1. Run Cloud Code: New Application after launching the command palette (Ctrl/Cmd+Shift+P or View > Command Palette).

Step 2. Select the Kubernetes application.

Step 3. Select a Hello World application in the language of your choice.

Step 4. Save the new application.

Steps to create a GKE cluster

Step 1. Select the Cloud Code icon. The Kubernetes portion in Cloud Code should be expanded.

Step 2. Click Google Kubernetes Engine in the Quick choose menu after selecting (plus symbol) Add a Cluster to the KubeConfig.

Step 3. Select Yes to enable container.googleapis.com when requested.

Step 4. To create a new GKE cluster, click +.

Step 5. Determine the cluster type to be Standard.

Step 6. To allow Cloud Code to launch the console, click Open.

Step 7. Use your newly created project in the console, and then change the zone to us-central1-a and the cluster name to my-first-cluster.

Step 8. Press Create. It takes time to create a cluster.

Step 9. Click Refresh Kubernetes cluster view Refresh in the Quick select menu once the cluster has been created.

Step 10. Click the cluster name when it appears in the list after you enter the name of your new cluster. The setup now includes your new cluster and is set up to be the active context.

Steps to run and view your application

Step 1. Choose Run on Kubernetes from the Cloud Code status bar by clicking it.

Step 2. Decide if you want to continue using the existing cluster context or if you want to change it.

Step 3. Select an image registry to push the photos, too, if requested. Make sure the image registry is in the same project as your cluster if you're creating a new image registry with gcr.io/PROJECT ID.

A progress bar for your currently running application appears in an output window. The logs from the active pods will also be streamed live on the terminal output.

Step 4. The output pane shows an IP address once your application is running on Kubernetes. Press Ctrl or Command and click the address to access your program using the associated IP address.

Deploy a Cloud Run service with Cloud Code for VS Code

In this part of “Overview of Cloud Code for VS Code,” we will discuss deploying a Cloud run service with Cloud Code for VS Code.

Installing Cloud Code to Run Service

Steps to install Cloud Code are:

Step 1. If you haven't already, download and install VS Code.

Step 2. Install Dependencies:

      a. For all Cloud platforms, make sure the Docker client (authenticated with your Docker registry) is in your machine's             PATH.

      b. Run docker -v to see if you already have Docker installed.

      c. For instructions on how to set up your Docker client if you're using Windows Home, read Get started working with               Docker Desktop.

      d. If you're using WSL but are unable to install Docker for Desktop, try minikube for local development using Cloud                 Code instead.

      e. Cloud Code installs kubectl, Skaffold, and gcloud CLI for you.

Step 3. Launch VS Code on your computer. Search for the Cloud Code extension under VS Code Extensions and click Install.    

Creating a Cloud Run Service with Cloud Code

Steps to create a cloud run service are:

Step 1. In the Cloud Code status bar, click Cloud Code and then New Application.

Step 2. Select Cloud Run as your preferred application type.

Step 3. Choose a Hello World service from the list of sample applications (Node.js, Python with Flask and Django frameworks, Java, Go).

Step 4. Confirm the location of your service on disc and click Create New Application.  In VS Code, a preview of the README file for your chosen service will appear.

Deploying Cloud Run Service

Steps to deploy service to cloud run are:

Step 1. Open the Command Palette (Ctrl/Cmd+Shift+P or View > Command Palette) and run the Deploy to Cloud Run command from there.

Step 2. Set your Google Cloud project in the Deploy to Cloud Run pane.

Step 3. Accept the remaining default settings and then press the Deploy button.  Cloud Code creates your image, uploads it to the registry, and deploys it to Cloud Run.

Step 4. Open the URL provided at the top of the Deploy to Cloud Run dialogue to observe your running service.

Managing Cloud APIs using VS Code

In this part of "Overview of Cloud Code for VS Code," we will discuss managing Cloud APIs using VS Code. These Cloud APIs can be accessed using Cloud Client Libraries.

To browse all of the Google Cloud APIs:

Step 1. Expand the Cloud APIs section by clicking Cloud Code.

Step 2. Click the API name to view the API's details. The information provided includes the service name, status, directions for installing client libraries, documentation, and code samples.

Steps to enable Cloud APIs for a project using the API details page:

Step 1. Select the project to enable the Cloud API on the Cloud API information page.

Step 2. Click API Enable. A message is displayed to confirm the change after the API is enabled.

Steps to use code sample for each API  in the API browser:

Step 1. Expand the Cloud APIs section by clicking Cloud Code.

Step 2. Click on the name of an API to display the detail view.

Step 3. Click Code Samples to view code examples for the API.

Step 4. Enter a search term to narrow down the list of samples, or select a programming language from the Language list.

Step 5. Click on the sample's name to view it. You can also choose to view the sample on GitHub or copy it to your clipboard.

You need to configure your application for successful authentication after enabling the required APIs and adding the required client libraries. Your configuration is based on the platform you're using and the type of development you're doing, such as local or remote.

Your application can authenticate and is ready for deployment once you've finished the authentication procedures in the overview of Cloud Code for VS Code.

Debug a Kubernetes application in Cloud Code for VS Code

In this part of “Overview of Cloud Code for VS Code,” we will discuss debugging  Kubernetes applications in Cloud code using skaffold debug.

On a local cluster, such as minikube or Docker Desktop, Google Kubernetes Engine, or any other cloud provider, you can debug your application.

Steps to debug a Kubernetes application

Step 1. Click the Cloud Code status bar. Click Debug on Kubernetes after selecting Cloud Code from the status bar.

Step 2. Cloud Code assists you in setting up the required Skaffold settings and cloudcode.kubernetes launch configuration if your application lacks them.

Step 3. Verify whether to run the application in the current Kubernetes context (or switch to a preferred one).

  • When prompted, select an image registry to push the photos to if you selected a remote cluster as the context.
  • When utilizing Container Registry, you may search for an existing registry or enter a name to build one.
  • If your project has the Artifact Registry API enabled and at least one Artifact Registry repository, you can browse to that repository and select it.

 

Step 4. Cloud Code joins the name of the image supplied in the Kubernetes manifests with this image registry to create the final name of the image repository. Your cloudcode.kubernetes launch configuration (located in.vscode/launch.json) contains a record of this decision.

  • Building your containers, pushing them to the registry, configuring Kubernetes, and waiting for the rollout are all steps that Cloud Code takes.
  •  In order to allow you to explore your live application after the rollout, Cloud Code automatically port-forwards all specified container ports to your workstation and displays the URLs in the output window.

 

Step 5. Verify or enter the directory in the remote container where the program you wish to debug is located for each debuggable container in your application. Alternatively, you can press ESC to omit container debugging.

Step 6. Each debuggable container in the application has a debug session attached via Cloud Code.

  • Now, you can use a live Kubernetes cluster to carry out the same debugging operations you typically carry out on local code, such as setting breakpoints and stepping through code.
  • By default, Cloud Code redeploys your application and starts a new debug session whenever you save a change to it. With the watch flag set in your project's launch configuration, you can turn this function on or off.

 

Step 7. Use the Debug Sidebar to explore variables and stack information. To participate in the debugging session, use the Debug Console in the bottom pane debugger.

Step 8. You can use the contextual menu commands listed below after your session ends:

  • Open Deployment Logs: Open the application logs of a specific deployment with the Cloud Code Logs Explorer.
  • Link to Open Service: Open a web browser and enter the application service URL of the desired service.

 

Step 9. If you want to make changes to your application and rebuild and redeploy it after turning off watch mode in your launch configuration, pause on the run action in the Development sessions pane and then click the Rebuild and redeploy icon. Redeploy the application after rebuilding it.

Also see, kubernetes interview questions

Frequently Asked Questions

What is API in Google Cloud?

Programmatic access to Google Cloud Platform services is made possible by the Google Cloud APIs. They are a crucial part of the Google Cloud Platform because they make it simple for you to provide your apps access to the processing, networking, storage, and machine-learning-based data analysis capacity.

What is VPC in the Google Cloud Platform?

The Google Cloud Platform's (GCP) Virtual Private Cloud (VPC) is a virtual network that connects your GKE (Google Kubernetes Engine) clusters, VM instances of compute engines, and numerous other resources. With regard to deciding how the workloads link locally or internationally, the VPC offers a great deal of flexibility. A single VPC can communicate across numerous areas without using the public internet.

What is Google Cloud SDK?

A group of command-line utilities makes up the Google Cloud SDK. It is employed in the creation of the Google cloud. These tools enable direct command-line access to the compute engine, cloud storage, bigquery, and other services. Client libraries and API libraries are also included. You may operate with VM instances, manage computer engine networks, firewalls & storage, and more with these tools & libraries.

Conclusion

Congratulations on finishing the blog! We have discussed the overview of Cloud Code for VS Code. We further look at the installation of VS Code, deploying and debugging Kubernetes applications, and managing cloud APIs using VS Code.

If you want to explore more blogs like an overview of Cloud Code for VS Code, please follow these blogs especially curated for readers like you- GCP vs. AWSCloud Computing, Cloud Computing Technologies, Cloud Server, and Cloud Computing Infrastructure.

Please refer to our guided pathways on Code studio to learn more about DSACompetitive ProgrammingJavaScriptSystem Design, etc. Enroll in our courses, and use the accessible sample exams and questions as a guide. For placement preparations, look at the interview experiences and interview package.

Please do upvote our blogs if you find them helpful and informative!

Happy learning!

Topics covered
1.
Introduction
2.
Installing the Cloud code extension for VS Code
3.
Setting up Cloud Code
4.
Custom Version of Cloud Code Dependencies
5.
Deploying a Kubernetes application by remote development
5.1.
Steps to create a Kubernetes application
5.2.
Steps to create a GKE cluster
5.3.
Steps to run and view your application
6.
Deploy a Cloud Run service with Cloud Code for VS Code
6.1.
Installing Cloud Code to Run Service
6.2.
Creating a Cloud Run Service with Cloud Code
6.3.
Deploying Cloud Run Service
7.
Managing Cloud APIs using VS Code
7.1.
To browse all of the Google Cloud APIs:
7.2.
Steps to enable Cloud APIs for a project using the API details page:
7.3.
Steps to use code sample for each API  in the API browser:
8.
Debug a Kubernetes application in Cloud Code for VS Code
8.1.
Steps to debug a Kubernetes application
9.
Frequently Asked Questions
9.1.
What is API in Google Cloud?
9.2.
What is VPC in the Google Cloud Platform?
9.3.
What is Google Cloud SDK?
10.
Conclusion