The Guestbook sample demonstrates how to deploy a Kubernetes application with a front end service and a back end service using the Cloud Code extension for Visual Studio Code. When you run the application, Cloud Code uses skaffold under the hood to build an image and deploy the project's Kubernetes manifests. To learn more about Kubernetes, explore the Kubernetes overview.
- What's in this sample
- Getting Started
- Next steps
- Sign up for User Research
-
skaffold.yaml- A schema file that serves as an entry point for all Skaffold modules in the app -
src/frontend/- Guestbook frontend service, containing the following config files:skaffold.yaml- A schema file that defines the frontend Skaffold module (skaffold.yaml reference)kubernetes-manifests/guestbook-frontend.deployment.yaml- deploys a pod with the frontend container imagekubernetes-manifests/guestbook-frontend.service.yaml- creates a load balancer and exposes the frontend service on an external IP in the cluster
-
src/backend/- Guestbook backend service, containing the following config files:skaffold.yaml- A schema file that defines the backend Skaffold module (skaffold.yaml reference)kubernetes-manifests/guestbook-backend.deployment.yaml- deploys a pod with the backend container imagekubernetes-manifests/guestbook-backend.service.yaml- exposes the backend service on an internal IP in the clusterkubernetes-manifests/guestbook-mongodb.deployment.yaml- deploys a pod containing a MongoDB instancekubernetes-manifests/guestbook-mongodb.service.yaml- exposes the MongoDB service on an internal IP in the cluster
The Guestbook app uses Skaffold configuration dependencies, or modules, to define individual configurations for the frontend and backend services. Each module constitutes a single build-test-deploy pipeline that can be executed in isolation or as a dependency of another module.
Cloud Code enables iterative development and debugging on a single module or a subset of many modules, and makes editing the skaffold.yaml file configuration with modules easier. Underlying Skaffold takes care of module dependencies and their order of deployment.
Guestbook runs both the frontend and backend modules by default. To run a single module, follow the steps in the section Run individual services with Skaffold modules.
Cloud Code uses minikube to create a free local cluster.
- Navigate to the Clusters explorer in the Cloud Code - Kubernetes sidebar using the left side Activity bar.
Note: in newer versions of VS Code, the Clusters explorer has been replaced with a dedicated Kubernetes section.
-
Click '+' in the title bar of the Clusters explorer to create a new cluster. If prompted, follow the instructions to log in to Google Cloud Platform.
-
Choose Minikube and then select minikube.
-
Select Start. Cloud Code will initiate a minikube cluster.
- Navigate to the Clusters explorer in the Cloud Code - Kubernetes sidebar using the left side Activity bar.
Note: in newer versions of VS Code, the Clusters explorer has been replaced with a dedicated Kubernetes section.
-
Click '+' in the title bar of the Clusters explorer to create a new cluster. If prompted, follow the instructions to log in to Google Cloud Platform.
-
Choose Google Kubernetes Engine. If you have existing clusters associated with your GCP project, you can select one from this dialog. To create a new cluster, click + Create a new GKE Cluster and follow these steps:
a. Choose Standard or Autopilot. For more information, see Comparing Autopilot and Standard modes.
b. If prompted, click Open to permit Cloud Code to open the Cloud Console.
c. In the Cloud Console, choose any configuration options that you want to customize and then click Create.
d. Once the cluster has finished being created, return to VS Code and click Refresh.
You can now select your newly created cluster.
-
The cluster you select will be added to the Clusters explorer and set as the default context. You can inspect the cluster's properties, make changes to the cluster's resources, and view logs by clicking the dropdown arrow next to the cluster name in the Clusters explorer.
-
Navigate to the Development Sessions explorer in the Cloud Code - Kubernetes sidebar using the Activity bar on the left side of the IDE.
-
Click the 'Play' icon in the title bar of the Development Sessions explorer to run the application. If prompted, confirm the current context and image registry.
-
View the build progress in the Development Sessions explorer. Once the build has finished, the URLs for your deployed app will be displayed under Port Forward URLs. Click on the 'Open Window' icon next to the frontend service's URL to visit your deployed app.
-
To stop the application, click the stop icon on the Debug Toolbar.
If you created a GKE cluster for this tutorial, be sure to delete your cluster to avoid incurring charges.
The Guestbook app needs both services deployed to function properly, but for this tutorial we'll deploy only the frontend service to demonstrate running individual modules.
-
First, we need to deploy both services such that the backend will stay up after ending the development session. a. Open .vscode/launch.json and change the
cleanUpproperty tofalse. b. Follow the steps above in "Deploy app to cluster" to deploy both services. When you click the stop icon to end the debug session, the services will remain deployed. (We'll leavebackendrunning and only updatefrontend). -
Open .vscode/launch.json and add the following code below the
skaffoldConfigproperty:
"skaffoldFlags": {
"modules": [
"frontend"
]
},
This tells Cloud Code to build and deploy only the frontend module.
-
Click on the Cloud Code status bar and select Run on Kubernetes.
-
If prompted, confirm the current context and image registry.
-
View the build's progress in the OUTPUT window. Once the build has finished, you can view the deployed frontend module by clicking on the URL in the OUTPUT window.
-
Now, you can quickly iterate on the frontend service without having to rebuild and deploy the entire app for every change. a. Navigate to frontend/templates/home.html. b. Make a change to the file (e.g. "My Guestbook" > "My Frontend Guestbook"). c. The frontend service will rebuild and you can see your changes in the deployed frontend service.
You can see how the Guestbook frontend module is defined by checking out the frontend's skaffold.yaml file.
For more info on how to use Skaffold modules, see the Skaffold documentation.
- Try debugging your app using Cloud Code
- Navigate the Kubernetes Engine Explorer
- Learn how to edit YAML files to deploy your Kubernetes app
- Configure an existing app to run on Cloud Code
- Enable Cloud APIs and client libraries
- Manage secrets with Secret Manager
For more Cloud Code tutorials and resources, check out Awesome Cloud Code!
We want to hear your feedback!
The Cloud Code team is inviting our user community to sign-up to participate in Google User Experience Research.
If you’re invited to join a study, you may try out a new product or tell us what you think about the products you use every day. At this time, Google is only sending invitations for upcoming remote studies. Once a study is complete, you’ll receive a token of thanks for your participation such as a gift card or some Google swag.
Sign up using this link and answer a few questions about yourself, as this will help our research team match you to studies that are a great fit.
