Creating an application from a template
To set up a basic Kubernetes application using an existing sample, use the Command Palette.
The Command Palette is accessible from the 'Manage' menu (gear icon). Once the Command Palette has launched:
- Type or select Cloud Code: New Application.
Select a template based on the language you'd like to use from the available options: NodeJS, Go, Python, Java.
This example uses the 'Node.js: Guestbook' template.
Choose a preferred application location on your local machine.
On clicking enter, a simple two microservice Kubernetes application will be created (number of microservices created is dependant on the template you use).
All language template applications have nearly the same structure. This is not the only supported structure but is recommended when starting.
For the NodeJS Guestbook application, this is what the template structure looks like:
. |---- .vscode | └---- launch.json |---- kubernetes-manifests | |---- guestbook-backend.deployment.yaml | |---- guestbook-backend.service.yaml | |---- guestbook-frontend.deployment.yaml | |---- guestbook-frontend.service.yaml | |---- mongo.deployment.yaml | └---- mongo.service.yaml |---- src | |---- backend | | |---- Dockerfile | | |---- index.js | | |---- app.js | | └---- package.json | |---- frontend | |---- Dockerfile | |---- index.js | | |---- app.js | └---- package.json └---- skaffold.yaml
Taking a closer look at the Guestbook Node.js sample app, here are some key files and their respective uses:
- extensions.json: prompt requesting download of related extensions when opening this project
- launch.json: run and debug configuration information
- tasks.json: configuration information for Visual Studio Code Tasks
- guestbook-backend.deployment.yaml: Pod specification for the backend nodes
- guestbook-frontend.deployment.yaml: Pod specification for the frontend nodes
- mongo.deployment.yaml: Pod specification for the database
- (backend|frontend)/app.js: Node.js code with the web server logic
- (backend|frontend)/Dockerfile: used to build the container image for our program
- skaffold.yaml: config file for Skaffold, which is used by Cloud Code to build and run images
Repurposing an existing application
Alternatively, you can work off of an existing application. You can clone the Guestbook application, a two microservice Kubernetes application that saves logs of names and messages, from the Cloud Code samples GitHub repository to explore features available through Cloud Code. All you have to do is open the folder in VS Code; you can run it straight away, view logs from it, make your own edits, debug your code, and view your changes in real-time.
Using your own application
If you'd like to use a project of your own, you'll need to set up your run and debug configurations. Refer to this guide on setting up your application.