Importing Kubernetes applications into a workspace
This section describes how to import Kubernetes or OpenShift applications into a Che workspace.
For demonstration purposes, the section uses a sample Kubernetes or OpenShift application having the following two Pods:
-
A Node.js application specified by this nodejs-app.yaml
-
A MongoDB Pod specified by this mongo-db.yaml
To run the application on a Kubernetes or OpenShift 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 or OpenShift application in a workspace devfile definition
This procedure describes how to define a Che workspace devfile to include a Kubernetes application.
The devfile format is used to define a Che workspace, and its format is described in the Configuring a workspace using a devfile section.
-
You are logged in to the cluster with a running instance of Eclipse Che. To install an instance of Eclipse Che, see Installing Che.
-
chectl
management tool is available. See Using the chectl management tool.
-
Create the simplest devfile:
apiVersion: 1.0.0 metadata: name: minimal-workspace (1)
1 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, including, for example, the terminal. -
To add Kubernetes applications to a workspace, modify the devfile and add the
Kubernetes
component type.For example, to embed the NodeJS-Mongo application in the
minimal-workspace
: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'] (1) args: ['infinity']
1 The sleep infinity
command is added as the entrypoint of the Node.js application. The command prevents the application from starting at the workspace start phase. This configuration allows the user to start the application when needed for testing or debugging purposes. -
Add the commands in the devfile to make it easier for a developer to test the application:
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 (1) 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
1 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 Node.js application. -
Use the devfile to create and start a workspace:
$ chectl workspace:start --devfile <devfile-path>
Adding a Kubernetes or OpenShift application to an existing workspace using the dashboard
This procedure demonstrates how to modify an existing workspace and import the Kubernetes or OpenShift application using the newly created devfile.
-
A running instance of Che. To install an instance of Che, see Installing Che.
-
An existing workspace defined on this instance of Che.
-
After the creation of a workspace, use the Workspace menu and then click on the desired workspace.
-
Modify the workspace devfile, use the Devfile tab.
-
Add a Kubernetes or OpenShift component.
-
For the changes to take effect, save the devfile and restart the Che workspace.
Generating a devfile from an existing Kubernetes or OpenShift application
This procedure demonstrates how to generate a devfile from an existing Kubernetes or OpenShift application using the chectl
tool.
-
A running instance of Che. To install an instance of Che, see Installing Che.
-
The
chectl
management tool is available. See Using the chectl management tool. -
You are logged in to Che. See How to login into Che using chectl
-
To generate a devfile, use:
$ chectl devfile:generate
-
It is also possible to generate a devfile from, for example, the
NodeJS-MongoDB
application that includes theNodeJS
component, using thechectl devfile:generate
command:Example:$ 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 Node.js application YAML definition is available in the devfile, inline, using the
referenceContent
attribute. -
To include support for a language, use the
--language
parameter:$ 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
.$ chectl workspace:start --devfile=devfile​.yaml