Prepare and test your skills
Prepare and test your skills
Management of the Cloud Shell Environment and Persistence is how you control what survives and what is discarded in Cloud Shell (opens in a new tab). Cloud Shell is a browser-based shell environment that runs on a temporary virtual machine (VM) with the Google Cloud CLI already installed and authenticated. A separate 5 GB persistent disk preserves user files between sessions, so management means knowing what is ephemeral, what persists in the home directory, and which preinstalled tools are available.
The Cloud Shell VM lifecycle is temporary and tied to session activity. The VM terminates after 40 minutes of inactivity, and the session can disconnect after about 20 minutes of inactivity. The first connection can take up to 25 seconds because the home disk must be created, while reconnection to an existing VM takes about five seconds. If Cloud Shell has not been used for a week, connection is slower because the home directory must be restored from an archive.
The VM depends on active use to stay alive, and termination discards the running system state. Any change made outside the home directory is lost after the VM terminates, while files inside the home directory survive on persistent storage. Starting a new session provisions a fresh VM and reattaches the existing home directory, so administration must assume the operating system itself is reset between long gaps in use.
The Cloud Shell persistent home directory is a 5 GB free persistent disk mounted as $HOME on the VM. The disk is allocated per user and is available across Google Cloud projects, so scripts, software installed in the home directory, and configuration files such as .bashrc and .vimrc persist between sessions and count toward the 5 GB limit. Only data written under $HOME flows to persistent storage, while data written to system paths outside $HOME stays on the ephemeral VM disk and is discarded on termination.
Storage pressure and long idle periods require active maintenance of the home directory. A no space left on device error means the 5 GB limit is full, which can be investigated with du -hs $(ls -A) to see usage per file and directory before removing unneeded files. If Cloud Shell is not accessed regularly, the $HOME storage may be recycled after an email notification, and starting a session prevents that recycling.
| Mode | Storage behavior | Connection and use |
|---|---|---|
| Default persistent mode | Files in $HOME persist between sessions on 5 GB per-user disk | Slower first connect up to 25 seconds; choose when configuration files and scripts must be retained |
| Ephemeral mode | No persistent disk; all files created in the session are lost on session end | Faster connection performance; choose when no files need to be retained |
Exam tip: Files inside $HOME persist between sessions, while any modification outside $HOME is lost when the VM terminates after 40 minutes of inactivity.
Preinstalled command-line tools in Cloud Shell provide authenticated administration without local setup. The terminal starts with values already set for the current project and automatic authentication with Google credentials, so commands can enable Cloud APIs, start long-running operations, and manage Google Cloud resources immediately. The environment includes the Google Cloud CLI (gcloud), Docker, kubectl, git, and other command-line utilities.
Administrative work flows from the Cloud Shell terminal to Google Cloud APIs and resources:
gcloud manages projects, enables services, and administers resources from the command line.kubectl interacts with Google Kubernetes Engine clusters after fetching credentials.git clones repositories and supports workflows such as Open in Cloud Shell samples.gcloud cloud-shell command group connects a local machine to Cloud Shell for copying files and opening an interactive SSH session.Because authentication and project context are preset, Cloud Shell removes the local steps of installing the SDK and logging in for each task.
The Cloud Shell environment configuration is the set of files and startup settings that must survive VM replacement. To make configurations persist, store scripts and settings under $HOME and use an environment customization script to reinstall or reconfigure anything that lives outside $HOME after each new VM starts. The $HOME/.bashrc file must continue to source the system file at /google/devshell/bashrc.google, or Cloud Shell can produce errors.
Resetting Cloud Shell restores the home directory to a clean default state and provisions a new VM. Before resetting, Safe mode can be used to sign in as root and attempt to fix broken files.
ls -a $HOME to check for personal files, because the next steps permanently delete them.sudo rm -rf $HOME to remove all files from the home directory.Application Testing and Secure Resource Connectivity is the use of Cloud Shell (opens in a new tab) to validate cloud-native applications and to reach private Google Cloud resources without exposing them to the public internet. Cloud Shell is a browser-based shell environment with the Google Cloud CLI already installed and values already set for the current project. Test traffic and administrative traffic flows from the Cloud Shell session to the target virtual machine (VM) or service, while Identity-Aware Proxy (IAP) enforces the identity and trust boundary in between.
The Cloud Shell Terminal is the command-line environment at the bottom of the Google Cloud console used to build, run, and validate applications during implementation. The session starts from the console and can take a few seconds to initialize, after which the project context is already configured and gcloud commands can run immediately. A developer runs the application or test command in the terminal so the app listens on a local port in Cloud Shell, monitors its output and port behavior, and then uses port-forwarding and tunnel commands to connect that local environment to private Google Cloud services. Because the terminal depends on the Cloud Shell managed environment, no local installation or manual project configuration is required before validation begins.
An Identity-Aware Proxy (IAP) tunnel is a secure, authenticated path that carries Secure Shell (SSH) traffic from Cloud Shell to a VM's internal IP address when the VM does not have an external IP address. Traffic flows from the Cloud Shell client through IAP to the VM's internal interface, so the VM stays private while the developer still gets interactive access. The primary command establishes the tunnel and the SSH session in one step:
gcloud compute ssh VM-NAME --tunnel-through-iap
In this flow, Cloud Shell is the source, IAP is the intermediary that checks identity, and the destination VM is named by VM-NAME. Choose this tunnel approach when the target has only an internal IP address and direct SSH over the internet is not possible or not desired.
Reusable SSH access is a local SSH client configuration that routes every connection through IAP by calling gcloud compute start-iap-tunnel as its proxy. The local SSH client depends on IAP for transport and on a propagated SSH key pair for authentication, so keys must be generated and propagated before the custom configuration will work. Setup follows an ordered workflow:
gcloud compute ssh --project=PROJECT_ID --zone=ZONE VM_NAME --tunnel-through-iap once, verify the connection is successful, and then exit.~/.ssh/config on Linux and macOS or %USERPROFILE%\.ssh\config on Windows.Host block where ProxyCommand runs gcloud compute start-iap-tunnel %h %p --listen-on-stdin --project=PROJECT_ID --zone=ZONE --verbosity=warning with the correct identity file and username.ssh VM_NAME from a local terminal, VS Code, or OpenSSH client so traffic flows from the local client through the IAP tunnel to the VM.The host entry requires these values:
VM_NAME is the name of the destination VM and the HostNamePATH_TO_PRIVATE_KEY is the path to the private key, typically ~/.ssh/google_compute_enginePROJECT_ID is the ID of the project that contains the VMZONE is the zone where the VM is locatedUSERNAME is the VM username, such as the OS Login usernameExam tip: Connecting from the Google Cloud console creates an ephemeral SSH key, while connecting with the gcloud CLI creates a persistent SSH key.
Cloud Code is the set of extensions that brings Google Cloud development support into VS Code and supported JetBrains IDEs. The extensions let code developed in a familiar integrated development environment (IDE) move toward deployment on Google Cloud without switching tools. When a workflow needs a fully managed, containerized workspace instead of a local IDE, Cloud Workstations provides managed cloud environments for development and infrastructure tooling.
Cloud-Native Development with Cloud Code (opens in a new tab) and Editor is the browser-based workflow for building, running, and debugging containerized applications without context switching. Cloud Code is an extension that brings Google Cloud services directly into the integrated development environment. Cloud Shell Editor includes Cloud Code by default and provides browser-based support for the full development cycle of Google Kubernetes Engine (GKE) and Cloud Run applications, from creating an app from a template to monitoring deployed resources.
Cloud Code in Cloud Shell Editor is the browser-based combination of editor, terminal, and Cloud Code commands for developing Kubernetes and Cloud Run applications. The extension is also installable in Visual Studio Code (VS Code) and IntelliJ and other supported JetBrains IDEs, with limited support for Android Studio, while Cloud Shell Editor requires no installation. Cloud Code works with command-line container tools like Skaffold, minikube, and kubectl and integrates with the Google Cloud SDK for unified authentication when developing with Google Cloud services.
Supported development languages cover common backend stacks:
Cloud Code provides run-ready sample applications, out-of-the-box configuration snippets, and context-based completions so new projects start from working code. Commands are available from the Cloud Code menu in the status bar and from the Command Palette with Ctrl/Cmd+Shift+P, which keeps build, run, and deploy actions inside the editor.
Google Kubernetes Engine (GKE) development with Cloud Code covers creating, running, debugging, and deploying containerized Kubernetes applications. A new application is created from a sample template that includes application code such as main.go, a Kubernetes Deployment specification such as hello.deployment.yaml, a Kubernetes Service specification such as hello.service.yaml, and a skaffold.yaml file that defines the Skaffold build and deploy workflow. The workflow depends on the Kubernetes context, so the developer confirms the target context before Cloud Code builds source code into a container image, pushes the image to a registry, and deploys it to the selected minikube, Docker Desktop, GKE, or other-provider cluster.
A Kubernetes application is created from a template in an ordered sequence:
Cloud Code: New Application from the Command Palette.Cloud Code supports Skaffold modules for developing and debugging parts of a GKE application independently, where dependencies are defined between skaffold.yaml configuration files and to specific modules. This module structure lets teams change one service without rebuilding the whole application, while Skaffold still coordinates the shared build and deploy workflow.
Cloud Run development with Cloud Code covers creating, running locally, deploying, and monitoring serverless container services. A developer creates and deploys a new service from the editor, then monitors progress with the Cloud Run Explorer and service logs in the Log Viewer. For a local workflow, the built-in Cloud Run emulator allows a service to be developed and debugged locally before deploying to managed Cloud Run.
| Target | Build and run model | Observe and access |
|---|---|---|
| GKE application | Skaffold builds image and deploys Deployment and Service to a Kubernetes context | Kubernetes view shows Namespaces, Services, and External IPs; Development sessions view shows deploy logs |
| Cloud Run service | Cloud Code builds image and deploys revision to Cloud Run, or runs locally in emulator | Cloud Run Explorer shows service progress and Log Viewer shows service logs |
Traffic flows from the built container image in the registry to the running workload, which is a GKE cluster for Kubernetes applications and a Cloud Run service for serverless services. Choose GKE when the workload needs Kubernetes Deployments, Services, and cluster management, and choose Cloud Run when the workload needs a managed service with emulator-based local debugging.
Automated container image builds in Cloud Code turn application source code into secure, production-ready container images without manual container setup. Cloud Code supports Docker, Jib, and Buildpacks artifact types, and its built-in support for Google Cloud buildpacks builds images from source without requiring a Dockerfile. The developer focuses on application code while Cloud Code handles the build, then pushes the resulting image to the selected image repository such as Artifact Registry in the form REGION-docker.pkg.dev/PROJECT_ID/REPO_NAME or gcr.io/PROJECT_NAME.
Build settings are customized in the Cloud Code: Develop on Kubernetes run configuration under Run and Open Configurations, and in the skaffold.yaml launch configuration. Cloud Code is built to work with Cloud Build for remote builds with Google Cloud infrastructure, which moves heavy image builds off the local Cloud Shell environment. For developing and testing an app, run on a non-production cluster, and for changes rolled out to production, use an automated continuous integration and continuous delivery (CI/CD) workflow.
Kubernetes YAML authoring in Cloud Code combines intelligent editing support with continuous run and debug feedback. Developers customize YAML with snippets, context-based completions, and validation that flags manifest errors during editing, which shortens the fix cycle before deployment. Once the app runs with Cloud Code: Run on Kubernetes, watch mode enables continuous building and real-time editing of the live application, so saved file changes trigger an automatic rebuild and redeploy to the active context.
Cloud Shell with integrated Cloud Code provides a tight development inner loop beyond basic editing:
Debugging applies to Go, Node.js, Python, and Java applications, with launch configurations, breakpoints, and variable inspection inside Cloud Shell Editor. An interactive terminal can be opened to a running container from Development Sessions under Deployed Resources and Pods, and detailed deployment output is viewed under the Deploy to Cluster node. When the session ends, Cloud Code forwards ports for preview during the run and then cleans up forwarded resources automatically.
Exam tip: Use watch mode with Run on Kubernetes for fast iterative edits on a non-production or minikube cluster, and use a CI/CD workflow — not the editor deploy — for production rollouts.
$HOME persist on the 5 GB per-user disk.gcloud compute ssh VM-NAME --tunnel-through-iap command carries SSH traffic from Cloud Shell through Identity-Aware Proxy (IAP) to a VM with only an internal IP address.sudo rm -rf $HOME and then selecting Restart to provision a new VM and restore the home directory to its default state.Files stored under $HOME persist between sessions on the 5 GB per-user persistent disk that is available across projects, while any change made outside the home directory stays on the ephemeral virtual machine (VM) disk and is lost when the VM terminates after 40 minutes of inactivity. Starting a new session provisions a fresh VM and reattaches the existing home directory.
Use an Identity-Aware Proxy (IAP) tunnel when the destination virtual machine (VM) has only an internal IP address and direct Secure Shell (SSH) access over the internet is not possible or not desired. Traffic flows from the Cloud Shell client through Identity-Aware Proxy (IAP) to the virtual machine (VM) internal interface so the virtual machine (VM) stays private while still allowing interactive access.
Choose Google Kubernetes Engine (GKE) when the workload needs Kubernetes Deployments, Services, and cluster management with Skaffold building the image and deploying to a Kubernetes context, and choose Cloud Run when the workload needs a managed service with emulator-based local debugging. Cloud Code builds source code into container images for both targets and provides Kubernetes views for Google Kubernetes Engine (GKE) and Cloud Run Explorer with Log Viewer for Cloud Run.
A software engineering team is developing a containerized microservices application targeted for Google Kubernetes Engine (GKE). The team uses the browser-based Cloud Shell Editor and wants to accelerate their development inner loop.
They have the following requirements:
Which workflow and configuration should the team implement in Cloud Shell Editor?
Configure skaffold.yaml and a cloudcode.kubernetes launch configuration in launch.json, then run the Cloud Code: Debug on Kubernetes action with watch mode enabled
Configure a continuous delivery pipeline in Google Cloud Deploy with Cloud Build triggers, and use Cloud Logging Logpoint injection to inspect remote execution
Execute gcloud builds submit on each code save and configure Cloud Profiler with Cloud Trace to capture execution stack traces from GKE workloads
Use the Cloud Shell Terminal to execute skaffold dev, manually configure kubectl port-forward for language ports, and create a standard remote SSH launch configuration
Last updated