This section describes how to import a Kubernetes application into a Che workspace.
For demonstration purposes, the section uses a sample Kubernetes application having the following two pods:
-
A NodeJS application specified by this nodejs-app.yaml
-
A MongoDB pod specified by this mongo-db.yaml
To run the application on a Kubernetes cluster:
$ node=https://raw.githubusercontent.com/redhat-developer/devfile/master/samples/web-nodejs-with-db-sample/nodejs-app.yaml && \
mongo=https://raw.githubusercontent.com/redhat-developer/devfile/master/samples/web-nodejs-with-db-sample/mongo-db.yaml && \
kubectl apply -f ${mongo} && \
kubectl apply -f ${node}
To deploy a new instance of this application in a Che workspace, use one of the following three scenarios:
-
Starting from scratch: Writing a new devfile
-
Modifying an existing workspace: Using the Dashboard user interface
-
From a running application: Generating a devfile with
chectl
Including a Kubernetes application in a workspace devfile definition
This procedure demonstrates how to define the Che 7 workspace devfile by Kubernetes application.
-
A running instance of Eclipse Che. To install an instance of Eclipse Che, see Che 'quick-starts'.
-
chectlmanagement tool is installed. See Installing thechectlmanagement tool
The devfile format is used to define a Che workspace, and its format is described in the Making a workspace portable using a devfile section. The following is an example of the simplest devfile:
apiVersion: 1.0.0
metadata:
name: minimal-workspace
Only the name (minimal-workspace) is specified. After the Che server processes this devfile, the devfile is converted to a minimal Che workspace that only has the default editor (Che-Theia) and the default editor plug-ins (example: the terminal).
Use the Kubernetes type of components in the devfile to add Kubernetes applications to a workspace.
For example, the user can embed the NodeJS-Mongo application in the minimal-workspace defined in this paragraph by adding a components section.
apiVersion: 1.0.0
metadata:
name: minimal-workspace
components:
- type: kubernetes
reference: https://raw.githubusercontent.com/.../mongo-db.yaml
- alias: nodejs-app
type: kubernetes
reference: https://raw.githubusercontent.com/.../nodejs-app.yaml
entrypoints:
- command: ['sleep']
args: ['infinity']
Note that the sleep infinity command is added as the entrypoint of the Node.js application. This prevents the application from starting at the workspace start phase. It allows the user to start it when needed for testing or debugging purposes.
To make it easier for a developer to test the application, add the commands in the devfile:
apiVersion: 1.0.0
metadata:
name: minimal-workspace
components:
- type: kubernetes
reference: https://raw.githubusercontent.com/.../mongo-db.yaml
- alias: nodejs-app
type: kubernetes
reference: https://raw.githubusercontent.com/.../nodejs-app.yaml
entrypoints:
- command: ['sleep']
args: ['infinity']
commands:
- name: run
actions:
- type: exec
component: nodejs-app
command: cd ${CHE_PROJECTS_ROOT}/nodejs-mongo-app/EmployeeDB/ && npm install && sed -i -- ''s/localhost/mongo/g'' app.js && node app.js
Use this devfile to create and start a workspace with the chectl command:
$ chectl worspace:start --devfile <devfile-path>
The run command added to the devfile is available as a task in Che-Theia from the command palette. When executed, the command starts the NodeJS application.
Adding a Kubernetes application to an existing workspace using the dashboard
This procedure demonstrates how to modify an existing workspace and import the Kubernetes application using the newly created devfile.
-
A running instance of Eclipse Che. To install an instance of Eclipse Che, see Che 'quick-starts'.
-
An existing workspace defined on this instance of Eclipse Che Creating a workspace from user dashboard.
-
After the creation of a workspace, use the Workspace menu and then the Configure workspace icon to manage the workspace.
-
To modify the workspace details, use the Devfile tab. The workspace details are displayed in this tab in the devfile format.
-
To add a Kubernetes component, use the Devfile editor on the dashboard.
-
For the changes to take effect, save the devfile and restart the Che workspace.
Generating a devfile from an existing Kubernetes application
This procedure demonstrates how to generate a devfile from an existing Kubernetes application using the chectl tool.
-
A running instance of Eclipse Che. To install an instance of Eclipse Che, see Che 'quick-starts'.
-
chectlmanagement tool is installed. See Installing thechectlmanagement tool
-
Use the
chectl devfile:generatecommand to generate a devfile:$ chectl devfile:generate
-
The user can also use the
chectl devfile:generatecommand to generate a devfile from, for example, theNodeJS-MongoDBapplication.The following example generates a devfile that includes the
NodeJScomponent:$ chectl devfile:generate --selector="app=nodejs" apiVersion: 1.0.0 metadata: name: chectl-generated components: - type: kubernetes alias: app=nodejs referenceContent: | kind: List apiVersion: v1 metadata: name: app=nodejs items: - apiVersion: apps/v1 kind: Deployment metadata: labels: app: nodejs name: web (...)The NodeJS application YAML definition is included in the devfile, inline, using the
referenceContentattribute. -
To include support for a language, use the
--languageparameter:$ chectl devfile:generate --selector="app=nodejs" --language="typescript" apiVersion: 1.0.0 metadata: name: chectl-generated components: - type: kubernetes alias: app=nodejs referenceContent: | kind: List apiVersion: v1 (...) - type: chePlugin alias: typescript-ls id: che-incubator/typescript/latest
-
-
Use the generated devfile to start a Che workspace with
chectl.