Visual Studio Code (VSCode), is a source-code editor made by Microsoft that includes support for debugging, syntax highlighting, intelligent code completion, snippets, code refactoring, and embedded Git. Users can change the theme, keyboard shortcuts, preferences, and install extensions that add additional functionality.
In this tutorial you will learn how to deploy VSCode so it can be accessed by any browser, allowing you to quickly and safely browse source code repositories and make lightweight code changes.
- A playground account. Follow the Signup process if you would like to create one.
To deploy the application, open the catalog by clicking on the upper left hand corner:
Then, select the VSCode application in the Napptive namespace and choose the desired tag and click Deploy. Each tag (go, nodejs, and python) is associated with a specific technology and it is already configured with the default compiler and toolchain (additional extensions can be then added through the VSCode interface).
Once the application is running, click in the application endpoint to open VSCode in your browser.
To secure your VSCode instance, the application is configured to ask for a password. The default password is pass and we encourage you to change it on the application parameters before deploying it. To change the default password, just modify the PASSWORD environment variable as shown below:
env: # Login credentials - name: PASSWORD value: pass
At this point, VSCode is ready to go, just clone any Git repository you want, or work locally.
Cloning a remote repository using git
To clone a remote repository, select Clone Git Repository from the Get Started window.
After that, you will be asked to authorize the GitHub extension to log into your account.
Alternatively, you can use the
git command opening a terminal from VSCode.
Installing additional libraries
Installing additional base libraries may require launching the application as root. Before deploying VSCode, modify the application parameters by changing the
security-context trait to run it as root as shown below.
# Security Context trait to run the app as root - type: security-context properties: fsGroup: 0 runAsUser: 0 runAsGroup: 0
Accessing the kubernetes API from Visual Code
VSCode has been configured to include the
kubectl command by default. This is done by the
kubeconfig-injector trait that is already attached. The trait creates a kubeconfig file to access the same environment as the one VSCode has been deployed is already configured. To interact with Kubernetes, and operate on that environment, open a terminal and issue
kubectl commands as needed.
To open the terminal, select the top left hand icon to open the menu, click on Terminal and select New Terminal.
kubectl get pod NAME READY STATUS RESTARTS AGE go-vscode-... 1/1 Running 0 4h36m
Adding persistent storage
This application has an ephemeral volume defined and mounted on the
home/coder path. All the data stored in this path will be lost in case of application restarts. If you need a persistent volume, change the volume definition to a persistent volume when deploying the application.