Learn how to set up a simple Kubernetes app, run the app on a Google Kubernetes Engine (GKE) 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
- Launch the Cloud Shell Editor.
From the Cloud Code status bar, select New Application.
Choose Kubernetes application as the application type.
From the list of templates (Node.js, Python (Flask and Django frameworks), Java, Go), choose a Hello World app.
For example, choosing
Go: Hello Worldcreates a starter Go Hello World app.
Select a folder as your application location and then 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 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. After 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.
After you make this change, you'll notice your app being rebuilt by the logs in the Output panel.
When your app finishes building and deploying, launch it from the link in the 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 that were generated by clicking the Logs refresh button.
Creating a GKE cluster
To create a GKE cluster, follow these steps:
- To open the Kubernetes Explorer, click Cloud Code - Kubernetes.
- In the header of the Kubernetes Explorer pane, click + Add a Cluster to the KubeConfig.
- Choose Google Kubernetes Engine and then click + Create a new GKE Cluster.
- Choose Standard or Autopilot as the cluster type.
- Click Open to permit Cloud Code to open the Cloud Console.
- In Cloud Console, configure your cluster.
- Click Create. Cluster creation takes a couple minutes.
- After the cluster is created, in Kubernetes Explorer, click Refresh.
- After the name of your new cluster appears in the list, click the cluster name. Your new cluster is added to the configuration and configured to be the active context.
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 might 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.
After your application is running, the output window displays an IP address. Ctrl/Cmd + click to use this linked address to access your application!
After you stop your application, all Kubernetes resources deployed during the run are deleted automatically. To avoid incurring charges to your account for other resources used in this quickstart, be sure to delete the project or the cluster you created.
To delete just your cluster, follow these steps:
- In the Kubernetes Explorer, hover over your cluster name and then click Open in Cloud Console.
- Click Delete and then click Delete.
To delete your project (and associated resources, including any clusters):
Go to the Projects page in the Cloud Console:
Select the project that you created for this quickstart and then click Delete.
Type the project ID to confirm and then click Shut down.
This shuts down the project and schedules it for deletion.
- Discover the features the Cloud Shell Editor has to offer.
- Read about debugging with the Cloud Shell Editor and Cloud Shell Editor's additional support for Kubernetes applications.