Remotely accessing workspaces

This section describes how to remotely access Che workspaces outside of the browser.

Che workspaces exist as containers and are, by default, modified from a browser window. In addition to this, there are the following methods of interacting with a Che workspace:

  • Opening a command line in the workspace container using the Kubernetes command-line tool, kubectl.

  • Uploading and downloading files using the kubectl tool.

Remotely accessing workspaces using kubectl

To access Che workspaces remotely using Kubernetes command-line tool (kubectl), follow the instructions in this section.

The kubectl tool is used in this section to open a shell and manage files in a Che workspace. Alternatively, it is possible to use the oc OpenShift command-line tool.
Prerequisites
  • The kubectl, version 1.5.0 or higher, is available. For information about installed version, use:

    $ kubectl version
    Client Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.0"
    
    ...
Procedure

In the example below:

  • workspace7b2wemdf3hx7s3ln.maven-74885cf4d5-kf2q4 is the name of the Pod.

  • che is the namespace.

    1. To find the name of the Kubernetes or OpenShift namespace and the Pod that runs the Che workspace:

      $ kubectl  get pod -l che.workspace_id --all-namespaces
      NAMESPACE   NAME                                               READY   STATUS    RESTARTS   AGE
      che         workspace7b2wemdf3hx7s3ln.maven-74885cf4d5-kf2q4   4/4     Running   0          6m4s
    2. To find the name of the container:

      $ NAMESPACE=che
      $ POD=workspace7b2wemdf3hx7s3ln.maven-74885cf4d5-kf2q4
      $ kubectl  get pod ${POD} -o custom-columns=CONTAINERS:.spec.containers[*].name
      CONTAINERS
      maven,che-machine-execpau,theia-ide6dj,vscode-javaw92
    3. When you have the namespace, Pod name, and the name of the container, use the `kubectl ` command to open a remote shell:

      $ NAMESPACE=che
      $ POD=workspace7b2wemdf3hx7s3ln.maven-74885cf4d5-kf2q4
      $ CONTAINER=maven
      $ kubectl exec -ti -n ${NAMESPACE} ${POD} -c ${CONTAINER} bash
      user@workspace7b2wemdf3hx7s3ln $
    4. From the container, execute the build and run commands (as if from the Che workspace terminal):

      user@workspace7b2wemdf3hx7s3ln $ mvn clean install
      [INFO] Scanning for projects...
      (...)
Additional resources

Downloading and uploading a file to a workspace using the command-line interface

This procedure describes how to use the kubectl tool to download or upload files remotely from or to an Che workspace.

Prerequisites
  • A running instance of Che. To install an instance of Che, see Installing Che.

  • Remote access to the Che workspace you intend to modify. See Remotely accessing workspaces.

  • The kubectl, version 1.5.0 or higher, is available. For information about installed version, use:

    $ kubectl version
    Client Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.0"
    
    ...
Procedure

The following procedure uses che as an example of a user namespace.

  • To download a local file named downloadme.txt from a workspace container to the current home directory of the user, use the following in the Che remote shell.

    $ REMOTE_FILE_PATH=/projects/downloadme.txt
    $ NAMESPACE=che
    $ POD=workspace7b2wemdf3hx7s3ln.maven-74885cf4d5-kf2q4
    $ CONTAINER=maven
    $ kubectl cp ${NAMESPACE}/${POD}:${REMOTE_FILE_PATH} ~/downloadme.txt -c ${CONTAINER}
  • To upload a local file named uploadme.txt to a workspace container in the /projects directory:

$ LOCAL_FILE_PATH=./uploadme.txt
$ NAMESPACE=che
$ POD=workspace7b2wemdf3hx7s3ln.maven-74885cf4d5-kf2q4
$ CONTAINER=maven
$ kubectl cp ${LOCAL_FILE_PATH} ${NAMESPACE}/${POD}:/projects -c ${CONTAINER}

Using the preceding steps, the user can also download and upload directories.

Additional resources