ODO and Rancher Desktop
odo
is a fast, iterative and straightforward CLI tool for developers who write, build, and deploy applications on Kubernetes. The odo
CLI abstracts away complex Kubernetes concepts and allows developers to focus on iterating code. The helper tool can detect changes to local code and deploy them to a container orchestrated cluster automatically, giving instant feedback to validate changes in real-time. Please refer to the odo
project documentation to learn more.
Prerequisites​
For this guide you will use the express-sample node.js application in the Rancher Desktop documentation repository as a way to demonstrate the use of odo
and Rancher Desktop.
odo
works with the dockerd (moby)
runtime, be sure to have it selected from the preferences dialog location Preferences > Container Engine > Allowed Images.
Please ensure that Kubernetes is enabled for your application. Additionally, in order to use odo deploy
, you will need to be able to build and push an image to a Docker container registry. Log in using your Docker credentials as noted below:
$ docker login docker.io
Username:
Password:
Login Succeeded!
Installation​
Install odo
by visiting https://odo.dev/docs/overview/installation and perform the appropriate install for your platform. The tool can be used both as a CLI tool or an IDE plugin, as well as a few alternative install methods depending on your preference. This guide will focus on using the tool through the CLI.
Steps: odo init
​
This command will initialize the application by creating a devfile.yaml
for deployments.
- Clone the Rancher Desktop documentation repository and change your directory to the sample-express application.
git clone https://github.com/rancher-sandbox/docs.rancherdesktop.io.git
cd docs.rancherdesktop.io/assets/express-sample
- Before initializing, you must connect
odo
to your cluster via a namespace, which can be created with the commandodo create namespace <name>
:
odo create namespace odo-dev
Details
Sample Output
$ odo create namespace odo-dev
✓ Creating the namespace "odo-dev" [5ms]
✓ Namespace "odo-dev" is ready for use
✓ New namespace created and now using namespace: odo-dev
- The command
odo init
will auto-detect your project framework and choose the appropriatedevfile.yaml
to be used for deployment of your application. The command will allow you to confirm the Devfile (Y/n), select a container to change configuration (choose none for this example), and enter a component name (e.g. my-nodejs-app).
Alternatively, the following command with the additional flags (e.g. --devfile-version 2.2.0
) can be used to initialize odo
and allow your application to be deployed:
odo init --name my-nodejs-app --devfile nodejs --devfile-registry DefaultDevfileRegistry --devfile-version 2.2.0
Details
Sample Output
__
/ \__ Initializing a new component
\__/ \
/ \__/ odo version: v3.13.0
\__/
✓ Downloading devfile "nodejs:2.2.0" from registry "DefaultDevfileRegistry" [1s]
Your new component 'my-nodejs-app' is ready in the current directory.
To start editing your component, use 'odo dev' and open this folder in your favorite IDE.
Changes will be directly reflected on the cluster.
odo init
Details
Sample Output
$ odo init
__
/ \__ Initializing a new component
\__/ \ Files: Source code detected, a Devfile will be determined based upon source code autodetection
/ \__/ odo version: v3.13.0
\__/
Interactive mode enabled, please answer the following questions:
✓ Determining a Devfile for the current directory [910ms]
Based on the files in the current directory odo detected
Language: JavaScript
Project type: Node.js
Application ports: 3000
The devfile "nodejs:2.1.1" from the registry "DefaultDevfileRegistry" will be downloaded.
? Is this correct? Yes
✓ Downloading devfile "nodejs:2.1.1" from registry "DefaultDevfileRegistry" [933ms]