This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.2.5. Creating a single-component application with odo
With odo
, you can create and deploy applications on clusters.
2.5.1. Prerequisites 复制链接链接已复制到粘贴板!
-
odo
is installed. - You have a running cluster. You can use CodeReady Containers (CRC) to deploy a local cluster quickly.
2.5.2. Creating a project 复制链接链接已复制到粘贴板!
Create a project to keep your source code, tests, and libraries organized in a separate single unit.
Procedure
Log in to an OpenShift Container Platform cluster:
odo login -u developer -p developer
$ odo login -u developer -p developer
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a project:
odo project create myproject
$ odo project create myproject
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
✓ Project 'myproject' is ready for use ✓ New project created and now using project : myproject
✓ Project 'myproject' is ready for use ✓ New project created and now using project : myproject
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.5.3. Creating a Node.js application with odo 复制链接链接已复制到粘贴板!
To create a Node.js component, download the Node.js application and push the source code to your cluster with odo
.
Procedure
Create a directory for your components:
mkdir my_components && cd my_components
$ mkdir my_components && cd my_components
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Download the example Node.js application:
git clone https://github.com/openshift/nodejs-ex
$ git clone https://github.com/openshift/nodejs-ex
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Change the current directory to the directory with your application:
cd <directory_name>
$ cd <directory_name>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Add a component of the type Node.js to your application:
odo create nodejs
$ odo create nodejs
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 注意By default, the latest image is used. You can also explicitly specify an image version by using
odo create openshift/nodejs:8
.Push the initial source code to the component:
odo push
$ odo push
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Your component is now deployed to OpenShift Container Platform.
Create a URL and add an entry in the local configuration file as follows:
odo url create --port 8080
$ odo url create --port 8080
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Push the changes. This creates a URL on the cluster.
odo push
$ odo push
Copy to Clipboard Copied! Toggle word wrap Toggle overflow List the URLs to check the desired URL for the component.
odo url list
$ odo url list
Copy to Clipboard Copied! Toggle word wrap Toggle overflow View your deployed application using the generated URL.
curl <url>
$ curl <url>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.5.4. Modifying your application code 复制链接链接已复制到粘贴板!
You can modify your application code and have the changes applied to your application on OpenShift Container Platform.
- Edit one of the layout files within the Node.js directory with your preferred text editor.
Update your component:
odo push
$ odo push
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Refresh your application in the browser to see the changes.
2.5.5. Adding storage to the application components 复制链接链接已复制到粘贴板!
Persistent storage keeps data available between restarts of odo. Use the odo storage
command to add persistent data to your application. Examples of data that must persist include database files, dependencies, and build artifacts, such as a .m2
Maven directory.
Procedure
Add the storage to your component:
odo storage create <storage_name> --path=<path_to_the_directory> --size=<size>
$ odo storage create <storage_name> --path=<path_to_the_directory> --size=<size>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Push the storage to the cluster:
odo push
$ odo push
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that the storage is now attached to your component by listing all storage in the component:
odo storage list
$ odo storage list
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The component 'nodejs' has the following storage attached: NAME SIZE PATH STATE mystorage 1Gi /data Pushed
The component 'nodejs' has the following storage attached: NAME SIZE PATH STATE mystorage 1Gi /data Pushed
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Delete the storage from your component:
odo storage delete <storage_name>
$ odo storage delete <storage_name>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow List all storage to verify that the storage state is
Locally Deleted
:odo storage list
$ odo storage list
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The component 'nodejs' has the following storage attached: NAME SIZE PATH STATE mystorage 1Gi /data Locally Deleted
The component 'nodejs' has the following storage attached: NAME SIZE PATH STATE mystorage 1Gi /data Locally Deleted
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Push the changes to the cluster:
odo push
$ odo push
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.5.6. Adding a custom builder to specify a build image 复制链接链接已复制到粘贴板!
With OpenShift Container Platform, you can add a custom image to bridge the gap between the creation of custom images.
The following example demonstrates the successful import and use of the redhat-openjdk-18
image:
Prerequisites
- The OpenShift CLI (oc) is installed.
Procedure
Import the image into OpenShift Container Platform:
oc import-image openjdk18 \ --from=registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift \ --confirm
$ oc import-image openjdk18 \ --from=registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift \ --confirm
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Tag the image to make it accessible to odo:
oc annotate istag/openjdk18:latest tags=builder
$ oc annotate istag/openjdk18:latest tags=builder
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Deploy the image with odo:
odo create openjdk18 --git \ https://github.com/openshift-evangelists/Wild-West-Backend
$ odo create openjdk18 --git \ https://github.com/openshift-evangelists/Wild-West-Backend
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
The OpenShift service catalog is an implementation of the Open Service Broker API (OSB API) for Kubernetes. You can use it to connect applications deployed in OpenShift Container Platform to a variety of services.
Prerequisites
- You have a running OpenShift Container Platform cluster.
- The service catalog is installed and enabled on your cluster.
Procedure
To list the services:
odo catalog list services
$ odo catalog list services
Copy to Clipboard Copied! Toggle word wrap Toggle overflow To use service catalog-related operations:
odo service <verb> <service_name>
$ odo service <verb> <service_name>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.5.8. Deleting an application 复制链接链接已复制到粘贴板!
Deleting an application will delete all components associated with the application.
Procedure
List the applications in the current project:
odo app list
$ odo app list
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
The project '<project_name>' has the following applications: NAME app
The project '<project_name>' has the following applications: NAME app
Copy to Clipboard Copied! Toggle word wrap Toggle overflow List the components associated with the applications. These components will be deleted with the application:
odo component list
$ odo component list
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
APP NAME TYPE SOURCE STATE app nodejs-nodejs-ex-elyf nodejs file://./ Pushed
APP NAME TYPE SOURCE STATE app nodejs-nodejs-ex-elyf nodejs file://./ Pushed
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Delete the application:
odo app delete <application_name>
$ odo app delete <application_name>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
? Are you sure you want to delete the application: <application_name> from project: <project_name>
? Are you sure you want to delete the application: <application_name> from project: <project_name>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Confirm the deletion with
Y
. You can suppress the confirmation prompt using the-f
flag.