Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing a kubernetes application into a che workspace #760

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
:parent-context-of-importing-a-kubernetes-application-into-a-che-workspace: {context}

[id='importing-a-kubernetes-application-into-a-che-workspace_{context}']
= Importing a Kubernetes application into a Che workspace

:context: importing-a-kubernetes-application-into-a-che-workspace

This section describes how to import a Kubernetes application in a Che workspace.

For demonstration purposes, the section uses a sample Kubernetes application having the following two pods:

* A NodeJS application specified by this link:https://raw.githubusercontent.com/redhat-developer/devfile/master/samples/web-nodejs-with-db-sample/nodejs-app.yaml[nodejs-app.yaml]

* A MongoDB pod specified by this link:https://raw.githubusercontent.com/redhat-developer/devfile/master/samples/web-nodejs-with-db-sample/mongo-db.yaml[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: link:#including-a-kubernetes-application-in-a-workspace-devfile-definition_{context}[Writing a new devfile]
* Modifying an existing workspace: link:#adding-a-kubernetes-application-to-an-existing-workspace-using-the-dashboard_{context}[Using the dashboard UI]
* From a running application: link:#generating-a-devfile-from-an-existing-kubernetes-application_{context}[Generating a devfile with `chectl`]

include::proc_including-a-kubernetes-application-in-a-workspace-devfile-definition.adoc[leveloffset=+1]

include::proc_adding-a-kubernetes-application-to-an-existing-workspace-using-the-dashboard.adoc[leveloffset=+1]

include::proc_generating-a-devfile-from-an-existing-kubernetes-application.adoc[leveloffset=+1]


:context: {parent-context-of-importing-a-kubernetes-application-into-a-che-workspace}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ include::con_workspaces-overview.adoc[leveloffset=+1]

include::assembly_making-a-workspace-portable-using-a-devfile.adoc[leveloffset=+1]

include::assembly_importing-a-kubernetes-application-into-a-che-workspace.adoc[leveloffset=+1]

// include::proc_using-and-customizing-a-workspace-template-stack.adoc[leveloffset=+1]

// include::proc_exporting-a-workspace-with-a-che-factory.adoc[leveloffset=+1]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// importing-a-kubernetes-application-into-a-che-workspace

[id="adding-a-kubernetes-application-to-an-existing-workspace-using-the-dashboard_{context}"]
= 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.

.Procedure

. After the creation of a workspace, use the *Workspace* menu and then the *Configure workspace* icon to manage the workspace.
+
image::workspaces/configure-workspace.png[link="{imagesdir}/workspaces/configure-workspace.png"]

. To modify the workspace details, use the *Devfile* tab. The workspace details are displayed in this tab in the devfile format.
+
image::workspaces/configure-workspace-devfile.png[link="{imagesdir}/workspaces/configure-workspace-devfile.png"]

. 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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// importing-a-kubernetes-application-into-a-che-workspace

[id="generating-a-devfile-from-an-existing-kubernetes-application_{context}"]
= 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.

.Prerequisites

* `chectl` is installed and running

.Procedure

. Use the `chectl devfile:generate` command to generate a devfile:
+
----
$ chectl devfile:generate
----

* The user can also use the `chectl devfile:generate` command to generate a devfile from, for example, the `NodeJS-MongoDB` application.
+
The following example generates a devfile that includes the `NodeJS` component:
+
----
$ 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 `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`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// importing-a-kubernetes-application-into-a-che-workspace

[id="including-a-kubernetes-application-in-a-workspace-devfile-definition_{context}"]
= Including a Kubernetes application in a workspace devfile definition

// TO DO Supply URL for that file location
The devfile format is used to define a Che workspace, and its format is described in the link:#making-a-workspace-portable-using-a-devfile_using-developer-environments-workspaces[Making a workspace portable using a devfile] section. The following is an example of the simplest devfile:

[source,yaml]
----
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.

[source,yaml]
----
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 entry point of the NodeJS application. This prevents the application from starting at the workspace start phase, allowing 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:

[source,yaml]
----
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:

[subs="+quotes"]
----
$ 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.
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,12 @@ include::proc_creating-a-workspace-by-importing-source-code-of-your-project.adoc

include::proc_configuring-a-che-workspace-using-a-devfile.adoc[leveloffset=+1]

// include::proc_importing-a-kubernetes-application-into-a-che-worskspace.adoc[leveloffset=+1]

include::assembly_using-a-visual-studio-code-extension-in-che.adoc[leveloffset=+1]

// include::proc_configuring-plug-ins.adoc[leveloffset=+1]
//
// include::proc_remotely-accessing-your-workspace.adoc[leveloffset=+1]
//
// include::proc_configuring-your-vcs-credentials-for-your-workspaces.adoc[leveloffset=+1]


// [id='related-information-{context}']
// == Related information
//
Expand Down

This file was deleted.