Workspace Templates
tip
See our Templates repository for a list of ready to use Workspace Templates. You can also use these as reference for defining youur own Workspace Templates.
Getting started with Workspace Templates
You can define reusable templates for Workspaces. Workspace Templates are a combination of Docker images and a YAML definition. Each section in this template abstracts and simplifies Kubernetes YAML and at the same time provides maximum flexibility.
Onepanel's Workspace Template YAML definitions are composed of subsets of Kubernetes and Istio YAML definitions.
Here's a simple NGINX Workspace Template definition:
Sections
arguments (optional)
parameters
You can define and use parameters in your Workspace Templates. These parameters are displayed in the Workspace creation form (or are made available via CLI) and can be referenced in the template like so:
The syntax for parameter definitions are as follows:
If a parameter is defined, name
and value
are required.
name
is the name of the parameters, only alphanumeric characters and-
allowedvalue
is the default value for the parameterdisplayName
is the text that is displayed to the usertype
indicates how the parameter is rendered in the Workspace creation form in the Web UI. Possible values are:input.text
renders a textboxinput.number
renders a textbox that only accepts numbersinput.radio
renders radio buttonsselect.select
renders a dropdownselect.nodepool
renders a dropdown populated with the node pool options available. Usedefault
for the value.textarea.textarea
renders a textarea
options
define options iftype
isselect.select
orinput.radio
Example:
containers
This is where you define the container(s) that your Workspace needs to function.
name
The name of the container, should be unique in this template definition.
image
The image you want to use for your application.
Some examples include:
- nodered/node-red
- codercom/code-server:3.3.1
- jupyter/tensorflow-notebook
command and args
If you want to override the Docker image ENTRYPOINT, then you can use a combination of command
and args
fields to do that, for example:
For more information, see Define a Command and Arguments for a Container in Kubernetes docs.
env
These are environment variables that you want to define specifically for this Workspace.
Example:
note
Onepanel automatically adds certain Environment variables along with the ones you define in the Settings section before these environment variables. Though not recommended, you can override those by naming these environment variables the same.
container ports
These are the ports needed by the image you use. Make sure to add all of the ones you want to have access to.
- For the
nginxdemos/hello
we need port 80. - For
jupyter/tensorflow-notebook
we need port 8888.
volumeMounts
This is where you define volumes to be mounted in a container. Onepanel will automatically create these volumes and mount them to the container. You can choose the size of the volume when you start the workspace.
For example, the following will mount a volume in your container at /data
path:
note
You can mount an number of volumes allowed by the cloud provider's machine type. There is generally a limit on how many disks you can attach based on the size of the machine.
imagePullSecrets
You can set your private Docker registry credentials using the imagePullSecrets
field.
You will first need to store your credentials in a docker-registry
secret:
For Docker Hub, you can set docker-server
to docker.io
.
Then you can reference the secret in your template as follows:
See Kubernetes documentation for more information.
ports
These identify what ports your workspace exposes and the protocol used. These are NOT the same as container ports. Your workspace will have a url you can visit in your browser, and it is the ports defined under this section that are visible.
Each port can map to a container port. So if you have port 8888 on your container, but you want to reach it via http (port 80), use:
routes
These are the urls that you can reach on your workspace. Each one must map to a port defined under ports
.
For example, if you want the root of your workspace to take you to your only container running under port 80
:
You can also do regex matching:
Or query parameter matching:
volumeClaimTemplates (optional)
By setting the volumeClaimTemplates
field, you can override the volumes that Onepanel automatically generates. This is useful if you want to define your own storageClass
or make the storage size to a static number.
Note that the automatically generated volume is overwritten only if the name
in volumeClaimTemplates
matches the volumeMounts
name.
postExecutionWorkflow (optional)
This is a DAG workflow that runs after your workspace is ready. For more information, see Workflow Templates.
More involved example
Let's look at a more complicated example to cement some of these ideas.
For this example, we're going to have both JupyterLab and Visual Studio Code in the same workspace.
JupyterLab will be accessible at <url>/jupyterlab
and Visual Studio Code will be at the root <url>/
Here's the final YAML, we've added comments to explain different parts.
The comments in the YAML above should provide most of the information about the setup.
The key points here are:
- We can have multiple containers running on the same workspace
- The
ports
section can be thought of as a mapping forroutes
to use - jupyter allows you to run at
/jupyter
as a setting. Not all software supports something like this.