Learn how to set up a simple Kubernetes app, run the app on a Google Kubernetes Engine cluster, and view and debug your running code.
For step-by-step guidance on this task directly in Cloud Shell Editor, click Guide me:
The following sections take you through the same steps as clicking Guide me.
Before you begin
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
In the Google Cloud Console, on the project selector page, select or create a Google Cloud project.
Make sure that billing is enabled for your Cloud project. Learn how to confirm that billing is enabled for your project.
Creating an application
- Directly launch the Cloud Shell Editor.
From the Cloud Code status bar, select New Application.
Choose 'Kubernetes application' as your preferred application type.
From the list of templates (Node.js, Python (Flask and Django frameworks), Java, Go), choose a Hello World app in a language of your choosing.
For example, choosing
Go: Hello Worldwill create a starter Go Hello World app.
Select a folder as your application location to proceed and click 'Create New Application'.
Cloud Shell Editor loads the application in a new workspace. Once reloaded, your app is accessible in the explorer view.
Testing your application locally
To run your application in a local Kubernetes cluster in Cloud Shell, follow these steps:
In your terminal, run the following command:
When your minikube cluster is ready, click on the Cloud Code status bar and select Run on Kubernetes. Confirm that you want to use the minikube context.
If prompted, authorize Cloud Shell to make Google Cloud API calls.
As your app is being built, you can monitor its progress in the Output Panel. Once it's built, you can launch the app with the link displayed in your Output panel.
Editing your application
To edit your application, follow these steps:
- With the Explorer view, find the main.go file under cmd > hello-world folder.
- Modify "Hello, world!" to a message of your choosing.
- Once you make this change, you'll notice your app being rebuilt by the logs in your Output panel.
- When your app finishes building and deploying, launch it from the link in your Output panel to view your updated application.
Viewing application logs
To analyze your application while it's running, you can access its logs using the Log Viewer:
Launch the Log Viewer by typing "Cloud Code: View Logs" using the Command Palette (accessible with Ctrl/Cmd+Shift+P).
This view allows you to filter and navigate the logs for your app.
Select 'Deployment' or 'Pod' to see the logs for your app.
Refresh your app in the browser, and see the new logs generated by clicking the Logs refresh button.
Creating a Google Kubernetes Engine cluster
To create a GKE cluster, follow these steps:
- Navigate to the Google Kubernetes Engine explorer using the Cloud Code - Kubernetes view , by clicking on its icon in the VS Code Activity bar on the left.
- In the header of the Google Kubernetes Engine explorer panel, click the '+' button() (available on mouseover) to create a new GKE cluster.
- Select your project.
Fill out fields in the Create Cluster wizard and click 'Create Cluster'.
In this example, Project ID is set using the default Project ID button, zone is set as 'us-central1-c', and cluster name is defined as 'test'.
Cluster creation takes a couple of minutes. Once created, details of your cluster and its underlying resources will be available under the Kubernetes Explorer view.
Running your app
You can now run your application and view it live. Additionally, Cloud Code watches your filesystem for changes so that you can edit and rerun your app in near real-time.
To run your application, follow these steps:
- Use the Cloud Code status bar and select Run on Kubernetes.
- Confirm that you're using your new cluster as context for your app.
- Depending on the context chosen, you may be prompted to choose an image registry to push the images to.
- In the Output Panel, you can track the progress of your running application.
Once successful, the output window will display an IP address. Ctrl/Cmd + click to use this linked address to access your application!
Once you terminate your application, all Kubernetes resources deployed during the run will be deleted automatically.
However, to avoid incurring charges to your account for other resources used in this quickstart, be sure to delete the cluster and project you created.
If you'd like to delete just your cluster, you can do so by:
- Using the Kubernetes explorer under the Cloud Code view , right click the cluster you'd like to delete from the Google Kubernetes Engine Explorer pane and select 'Delete cluster'.
To delete your project (and associated resources, including any clusters):
Go to the Projects page in the Cloud Console:
Select the project you created for this Quickstart and click on the trash can icon next to delete it.
This shuts down the project and schedules it for deletion.
- Discover the variety of features the Cloud Shell Editor has to offer.
- Read about debugging with the Cloud Shell Editor and its additional support for Kubernetes applications.