Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Deploying a Service in Cloud Code for Cloud Shell
2.1.
Deploying a Service to Cloud Run
3.
Manage Kubernetes clusters in Cloud Code for Cloud Shell
3.1.
Creating a GKE cluster and adding it to your KubeConfig
3.2.
Working with an existing GKE cluster
3.3.
Setting a cluster as the default context
3.4.
Removing a cluster from your KubeConfig
4.
Debugging a Kubernetes Application in Cloud Code for Cloud Shell
4.1.
Debugging an Application
5.
Work with Google Cloud and Kubernetes YAML in Cloud Code for Cloud Shell
5.1.
Configuring with Snippets
5.2.
Completing with Context
5.3.
Validating YAML Schema
5.4.
Discovering Documentation on hover
5.5.
Accessing Resource Definitions
5.6.
Applying a YAML file
6.
Migrating an Application from Cloud Shell Editor to a local IDE
6.1.
Migrate your app from Cloud Code to a local IDE
7.
Managing Cloud APIs and Cloud Client Libraries in Cloud Code for Cloud Shell 
7.1.
Browsing Cloud APIs
7.2.
Enabling Cloud APIs
7.3.
Using API samples
8.
Frequently Asked Questions
8.1.
What is the Google Cloud shell?
8.2.
What is the process for creating a Cloud Shell file?
8.3.
How do I get started with Google Cloud Shell?
9.
Conclusion
Last Updated: Mar 27, 2024
Medium

Overview of Cloud Code for Cloud Shell

Introduction

Cloud Code is a set of IDE plugins for popular IDEs that make creating, deploying, and integrating Google Cloud applications easier. You probably know about cloud code this much. But how to deploy a service in cloud code is more fun and confusing part. 
 

Google Cloud Platform

 

In this article, we will do an overview of cloud code for cloud shell, where we will introduce you first to the topic of how to deploy a service to cloud run. Afterward, we will discuss managing the Kubernetes cluster and debugging a Kubernetes application. Ultimately, we will talk about working and managing cloud APIs and libraries. So let’s get started!

Also read, kubernetes interview questions

Deploying a Service in Cloud Code for Cloud Shell

To do an overview of cloud code for cloud shell, it is important to understand how to deploy a service in cloud code for cloud shell.

Deploying a Service to Cloud Run

To deploy your service to Cloud Run, follow these steps:
 Step 1: Run the Deploy to Cloud Run command after opening the command palette (Ctrl/Cmd+Shift+P or View Command Palette).


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


Step 3: Choose an existing service or create a new one.
 

Step 4: If you're creating a new service, under Deployment Platform, select either Cloud Run (fully managed) or Cloud Run for Anthos.
 

Step 5: Choose a region to deploy to if you selected Cloud Run (fully managed). Configure the Kubernetes cluster information if you chose Cloud Run for Anthos.


Step 6: (Optional) Expand the Advanced revision settings section to specify additional settings such as service account, environment variables, and SQL connections.


Step 7: Select whether to build locally or use Cloud Build under the Build environment.


Step 8: Enter the name of your builder (Docker or Buildpack) and its settings.

Step 9: After you've chosen your settings, click Deploy.
Cloud Code for Cloud Shell creates your image, registers it, and deploys it to Cloud Run. Your service is now operational!

Step 10: Follow the URL displayed in the web view to view your running service.
You can also view details about your running service by clicking the Show Detailed Logs button and scrolling through the output window's verbose logs.

deploy to cloud run

Step 11: When your session is finished, right-click and use the following commands:

a.) View Logs: Use the Cloud Code Logs to view the application logs for a specific deployment. Explorer

b.) Open URL: In a web browser, open the application service URL of a specific service.


Step 12: If you disabled watch mode in your launch configuration and want to make changes to your application as well as rebuild and redeploy it, click the Cloud Code status bar and then click Turn on watch mode.

Manage Kubernetes clusters in Cloud Code for Cloud Shell

While doing an overview of cloud code for cloud shell, it is necessary to know how to manage Kubernetes clusters in cloud code for cloud shell. 

Creating a GKE cluster and adding it to your KubeConfig

To make a cluster:

  1. Click Cloud Code - Kubernetes to launch the Kubernetes Explorer.
     
  2. Add a Cluster to the KubeConfig by clicking the Add a Cluster button.
     
  3. Choose Google Kubernetes Engine, then Yes to enable container GCP API in your project.
     
  4. Select either Standard or Autopilot
     
  5. When prompted, click Open to allow Cloud Code to launch the console.
     
  6. Select any configuration options you want to change in the console and then click Create.
     
  7. After you've created the cluster, go to VS Code and click Refresh Kubernetes cluster view Refresh.
     
  8. When the name of your new cluster appears in the list, click it. Your new cluster has been added to the configuration and designated as the default context.

Working with an existing GKE cluster

If you already have a Standard or Autopilot GKE cluster, you can make it your active cluster and work with it through Cloud Code.

  1. Click Cloud Code - Kubernetes to launch the Kubernetes Explorer.
     
  2. Add a Cluster to the KubeConfig by clicking the Add a Cluster button.
     
  3. Navigate to Google Kubernetes Engine.
     
  4. Click the name of your cluster. Your cluster has been added to KubeConfig.

Setting a cluster as the default context

The active cluster is the cluster to which your application is automatically deployed.

  1. Click Cloud Code - Kubernetes to launch the Kubernetes Explorer.
     
  2. Set as Active Cluster by right-clicking a cluster.

Removing a cluster from your KubeConfig

When you remove a cluster from your KubeConfig, it is no longer available for deployment.

  1. Click Cloud Code - Kubernetes to launch the Kubernetes Explorer.
     
  2. Remove Context Under Cluster by right-clicking a cluster.

Debugging a Kubernetes Application in Cloud Code for Cloud Shell

In our journey to do an overview of cloud code for cloud shell, it is important to know to debug a Kubernetes application using skaffold debug. Cloud Code allows you to easily debug an application deployed to a Kubernetes cluster.

Your application can be debugged on a local cluster (such as minikube or Docker Desktop), Google Kubernetes Engine (GKE), or any other cloud provider.

You don't have to do any manual setup with Cloud Code's debugging support, such as configuring port forwarding or injecting language-specific debug arguments. A Cloud Code-ready Kubernetes application with a skaffold.yaml configuration file and a cloudcode.kubernetes launch configuration is required for debugging.

Debugging an Application

  1. Select the Cloud Code status bar, followed by Debug on Kubernetes.
     
  2. If your application lacks the necessary Skaffold configuration or cloudcode.kubernetes launch configuration, Cloud Code can assist you in obtaining these.
     
  3. Confirm whether the app should be run in the current Kubernetes context (or switch to a preferred one).
     
  4. When prompted, select an image registry to push the images to if you chose a remote cluster as the context. If you're using Container Registry, you can browse to an existing registry or enter a name for a new registry. You can browse to and select an existing Artifact Registry repository if your project has Artifact Registry API enabled and at least one Artifact Registry repository.
     
  5. Confirm or enter the directory in the remote container where the program you want to debug is located for each debuggable container in your application.

    You can also skip debugging the container by pressing ESC.
    remote root prompt

    Each debuggable container in the application is assigned a debug session by Cloud Code.

    Setting breakpoints and stepping through code, as you would when debugging local code, is now possible against a live Kubernetes cluster.

    When you save a change to your application, Cloud Code redeploys it and starts a new debug session by default. The watch flag in your project's launch configuration can be used to enable or disable this feature.
     
  6. The Debug Sidebar can be used to inspect variables and stack information. Use the Debug Console in the bottom pane debugger to interact with the debugging session.
     
  7. After your session is finished, you can use the contextual menu commands listed below:
    1. Open Deployment Logs: Using the Cloud Code Logs Explorer, navigate to the application logs for a specific deployment.
    2. Open Service URL: In a web browser, open the application service URL of a specific service.
       
  8. If you disabled watch mode in your launch configuration and want to make changes to your application and rebuild and redeploy it, pause on the run action in the Development sessions pane and then click the Rebuild and redeploy icon.
     
  9. To end the debugging session, click the Debug Toolbar's Debug stop icon Stop.
    When you finish debugging, all deployed Kubernetes resources are removed from the cluster.

Work with Google Cloud and Kubernetes YAML in Cloud Code for Cloud Shell

In our journey to do an overview of cloud code for cloud shell, we will now learn the working of Google cloud and Kubernetes YAML in cloud code for cloud shell.

Cloud Code for Cloud Shell is intended to simplify Kubernetes and Cloud Build configuration by the linting schema for structure and valid values and reporting descriptive errors.

Configuring with Snippets

Out-of-the-box snippets for common YAML schema (view options with Command/Ctrl+Space) make it simple to start a new YAML file or add to an existing one without errors while adhering to best practices. Cloud Code makes working with repetitive fields easier by filling out the remaining instances after you fill out the first.

Completing with Context

Cloud Code provides contextual completions and relevant docs based on the current schema to assist you in selecting the best option.

Context completion

Validating YAML Schema

Cloud Code provides schema validation by highlighting invalid tags and values in your YAML files and recommending fixes when possible.

yaml validation

Discovering Documentation on hover

When you hover the pointer over a value in the schema, Cloud Code displays relevant documentation.

Documentation in hover

Accessing Resource Definitions

To view a resource's definitions, right-click it and select Go to Definition or Peek Definition.

Applying a YAML file

To use the current file to make a configuration change, open the command palette (Ctrl/Cmd+Shift+P or View Command Palette) and then run Cloud Code: Apply the most recent JSON/YAML file to a K8s deployed resource.

This command displays a diff view so you can review changes. When prompted to apply this change, click Apply. This command executes kubectl apply -f.

Migrating an Application from Cloud Shell Editor to a local IDE

While doing an overview of cloud code for cloud shell, we now have to learn how to migrate an application from cloud shell editor to local IDE. 

Migrate your app from Cloud Code to a local IDE

Follow these steps to migrate your application:

  1. Install the Cloud Code IDE extension.
    Cloud Code is a JetBrains IDE (IntelliJ Ultimate/Community, PyCharm Professional/Community, WebStorm, and GoLand) that can be installed on VS Code.
     
  2. Navigate to File Download to obtain the required source code.
Migrating application process

You can also commit your source code to a Git repo by using the Source Control: Git view from the Activity bar Source Control icon or by using Git commands in the Cloud Code terminal Open terminal icon, which is accessible from the Cloud Code top menu bar.

If you downloaded your Cloud Code workspace, you can now access it from your local IDE via File > Open Workspace (VS Code)/Open (IntelliJ), or via your local Source Control: Git view if you committed your source code to a Git repo.

Managing Cloud APIs and Cloud Client Libraries in Cloud Code for Cloud Shell 

Now the last thing that we are going to cover while doing an overview of cloud code for cloud shell, is managing cloud APIs and cloud client libraries in cloud code for cloud shell.

Cloud APIs are used to programmatically access Google Cloud products and services. These APIs provide a basic JSON REST interface. The Cloud Client Libraries are the recommended method for accessing the Cloud APIs.

Cloud Code makes it simple to add Cloud Client Libraries for the Cloud APIs and language you're working with to your project. You can search for samples for each API in the same view and easily incorporate samples into your application.

Browsing Cloud APIs

To investigate all Google Cloud APIs:

  1. Click Cloud Code - Cloud Run to open the Cloud APIs Explorer.
    The Cloud APIs view categorizes Cloud APIs.
     
  2. Click the API name to view its details. Details such as the service name, status, client library installation instructions, documentation, and code samples are displayed.

Enabling Cloud APIs

Follow these steps to enable Cloud APIs for a project via the API details page:

  1. Select the project for which you want to enable the Cloud API on the Cloud API details page.
     
  2. Click the Enable API button. After enabling the API, a message is displayed to confirm the change.

Using API samples

In the API browser, you can find and use code samples for each API.

  1. Click Cloud Code - Cloud Run to open the Cloud APIs Explorer.
     
  2. Click the name of an API to open the detail view.
     
  3. Click Code Samples to view API code samples.
     
  4. Type text to search for or select a programming language from the Language list to filter the list of samples.
     
  5. To view a sample, click the sample's name. You can also copy the sample to your clipboard or view the sample on GitHub.

Frequently Asked Questions

What is the Google Cloud shell?

Cloud Shell is a Google Cloud interactive shell environment that allows you to learn and experiment with Google Cloud while also managing your projects and resources from your web browser.

What is the process for creating a Cloud Shell file?

To create a new file in the cloud shell editor, type code filename> to open the editor without the file explorer and create a new file. If you want to delete the file, use the BASH command rm -r filename>.

How do I get started with Google Cloud Shell?

  1. Step 1: To launch a cloud shell, click the Activate Cloud Shell button at the top of the Google Cloud Console window.
  2. Step 2: You can now use your Google Cloud Shell session.
  3. Step 3: When you launch Google Cloud Shell, the active project in Console is synced with your gcloud configuration inside Cloud Shell.

Conclusion

In this article, we have extensively discussed the overview of cloud code for cloud shell, how to deploy different services that will run on cloud code for sample applications, setting up, managing, and working with Google Clouds along with debugging them. We had also discussed how to develop a server locally in the cloud for Cloud Shell.

If you think this blog has helped you with an overview of cloud code for cloud shell, and if you would like to learn more, check out our articles Introduction to cloud computing, Cloud Computing, Cloud Computing Architecture and Overview of a log-based metric, and many more on our Website.

Refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and AlgorithmsCompetitive ProgrammingJavaScriptSystem Design, and many more! If you want to test your competency in coding, you may check out the mock test series and participate in the contests hosted on Coding Ninjas Studio! 

But suppose you have just started your learning process and are looking for questions asked by tech giants like Amazon, Microsoft, Uber, etc. In that case, you must look at the problemsinterview experiences, and interview bundle for placement preparations.

Nevertheless, you may consider our paid courses to give your career an edge over others!

Happy Learning!

Live masterclass