Create a workspace from the command line
Create a workspace from the command line by applying a DevWorkspace custom resource to the cluster. Use this method when your workflow does not permit the OpenShift Dev Spaces dashboard.
Before you begin
- You have an active
ocsession with permissions to createDevWorkspaceresources in your project on the cluster. See Getting started with the CLI. - You know your OpenShift Dev Spaces user namespace on the cluster. The user namespace is created automatically when the user first accesses the OpenShift Dev Spaces dashboard. To retrieve it, visit
https://<openshift_dev_spaces_fqdn>/api/kubernetes/namespaceand find thenamevalue. - You are in your OpenShift Dev Spaces user namespace on the cluster. On OpenShift, use
octo display your current namespace or switch to a namespace.To create workspaces for other users, create the
DevWorkspacecustom resource in the target user namespace. This namespace must be provisioned by OpenShift Dev Spaces or by the administrator. See Configuring a user namespace.
About this task
Creating workspaces through the OpenShift Dev Spaces dashboard provides better user experience and configuration benefits compared to using the command line:
- As a user, you are automatically logged in to the cluster.
- OpenShift clients work automatically.
- OpenShift Dev Spaces and its components automatically convert the target Git repository's devfile into the
DevWorkspaceandDevWorkspaceTemplatecustom resources on the cluster. - Access to the workspace is secured by default with the
routingClass: chein theDevWorkspaceof the workspace. - Recognition of the
DevWorkspaceOperatorConfigconfiguration is managed by OpenShift Dev Spaces. - Recognition of configurations in
spec.devEnvironmentsspecified in theCheClustercustom resource including:- Persistent storage strategy is specified with
devEnvironments.storage. - Default IDE is specified with
devEnvironments.defaultEditor. - Default plugins are specified with
devEnvironments.defaultPlugins. - Container build configuration is specified with
devEnvironments.containerBuildConfiguration. - Available AI providers are configured through an
ai-tool-registryConfigMap in theopenshift-devspacesnamespace.
- Persistent storage strategy is specified with
Procedure
Results
- Verify that the workspace is starting by checking the PHASE status of the
DevWorkspace.$ oc get devworkspaces -n <user_project> --watchExample output:
NAMESPACE NAME DEVWORKSPACE ID PHASE INFO user1-dev my-devworkspace workspacedf64e4a492cd4701 Starting Waiting for workspace deployment - When the workspace has successfully started, its PHASE status changes to Running in the output of the
oc get devworkspacescommand.Example output:
NAMESPACE NAME DEVWORKSPACE ID PHASE INFO user1-dev my-devworkspace workspacedf64e4a492cd4701 Running https://url-to-workspace.comYou can then open the workspace by using one of these options:
- Visit the URL provided in the INFO section of the output of the
oc get devworkspacescommand. - Open the workspace from the OpenShift Dev Spaces dashboard.
- Visit the URL provided in the INFO section of the output of the