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.Questo contenuto non è disponibile nella lingua selezionata.
Chapter 2. Developer CLI (odo)
2.1. Understanding odo Copia collegamentoCollegamento copiato negli appunti!
odo
is a CLI tool for creating applications on OpenShift Container Platform and Kubernetes. With odo
, you can write, build, and debug applications on a cluster without the need to administer the cluster itself. Creating deployment configurations, build configurations, service routes and other OpenShift Container Platform or Kubernetes elements are all automated by odo
.
Existing tools such as oc
are operations-focused and require a deep understanding of Kubernetes and OpenShift Container Platform concepts. odo
abstracts away complex Kubernetes and OpenShift Container Platform concepts allowing developers to focus on what is most important to them: code.
2.1.1. Key features Copia collegamentoCollegamento copiato negli appunti!
odo
is designed to be simple and concise with the following key features:
- Simple syntax and design centered around concepts familiar to developers, such as projects, applications, and components.
- Completely client based. No additional server other than OpenShift Container Platform is required for deployment.
- Official support for Node.js and Java components.
- Partial compatibility with languages and frameworks such as Ruby, Perl, PHP, and Python.
- Detects changes to local code and deploys it to the cluster automatically, giving instant feedback to validate changes in real time.
- Lists all the available components and services from the cluster.
2.1.2. Core concepts Copia collegamentoCollegamento copiato negli appunti!
- Project
- A project is your source code, tests, and libraries organized in a separate single unit.
- Application
- An application is a program designed for end users. An application consists of multiple microservices or components that work individually to build the entire application. Examples of applications: a video game, a media player, a web browser.
- Component
- A component is a set of Kubernetes resources which host code or data. Each component can be run and deployed separately. Examples of components: Node.js, Perl, PHP, Python, Ruby.
- Service
-
A service is software that your component links to or depends on. Examples of services: MariaDB, Jenkins, MySQL. In
odo
, services are provisioned from the OpenShift Service Catalog and must be enabled within your cluster.
2.1.2.1. Officially supported languages and corresponding container images Copia collegamentoCollegamento copiato negli appunti!
Language | Container image | Package manager | Platform |
---|---|---|---|
Node.js | NPM | amd64, s390x, ppc64le | |
NPM | amd64, s390x, ppc64le | ||
Java | Maven, Gradle | amd64, s390x, ppc64le | |
Maven, Gradle | amd64, s390x, ppc64le | ||
Maven, Gradle | amd64, s390x, ppc64le |
2.1.2.1.1. Listing available container images Copia collegamentoCollegamento copiato negli appunti!
The list of available container images is sourced from the cluster’s internal container registry and external registries associated with the cluster.
To list the available components and associated container images for your cluster:
Log in to the cluster with
odo
:odo login -u developer -p developer
$ odo login -u developer -p developer
Copy to Clipboard Copied! Toggle word wrap Toggle overflow List the available
odo
supported and unsupported components and corresponding container images:odo catalog list components
$ odo catalog list components
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
TAGS
column represents the available image versions, for example,10
represents therhoar-nodejs/nodejs-10
container image.
2.2. odo architecture Copia collegamentoCollegamento copiato negli appunti!
This section describes odo
architecture and how odo
manages resources on a cluster.
2.2.1. Developer setup Copia collegamentoCollegamento copiato negli appunti!
With odo you can create and deploy application on OpenShift Container Platform clusters from a terminal. Code editor plug-ins use odo which allows users to interact with OpenShift Container Platform clusters from their IDE terminals. Examples of plug-ins that use odo: VS Code OpenShift Connector, OpenShift Connector for Intellij, Codewind for Eclipse Che.
odo works on Windows, macOS, and Linux operating systems and from any terminal. odo provides autocompletion for bash and zsh command line shells.
odo supports Node.js and Java components.
2.2.2. OpenShift source-to-image Copia collegamentoCollegamento copiato negli appunti!
OpenShift Source-to-Image (S2I) is an open-source project which helps in building artifacts from source code and injecting these into container images. S2I produces ready-to-run images by building source code without the need of a Dockerfile. odo uses S2I builder image for executing developer source code inside a container.
2.2.3. OpenShift cluster objects Copia collegamentoCollegamento copiato negli appunti!
2.2.3.1. Init Containers Copia collegamentoCollegamento copiato negli appunti!
Init containers are specialized containers that run before the application container starts and configure the necessary environment for the application containers to run. Init containers can have files that application images do not have, for example setup scripts. Init containers always run to completion and the application container does not start if any of the init containers fails.
The pod created by odo executes two Init Containers:
-
The
copy-supervisord
Init container. -
The
copy-files-to-volume
Init container.
2.2.3.1.1. copy-supervisord Copia collegamentoCollegamento copiato negli appunti!
The copy-supervisord
Init container copies necessary files onto an emptyDir
volume. The main application container utilizes these files from the emptyDir
volume.
Files that are copied onto the emptyDir
volume:
Binaries:
-
go-init
is a minimal init system. It runs as the first process (PID 1) inside the application container. go-init starts theSupervisorD
daemon which runs the developer code. go-init is required to handle orphaned processes. -
SupervisorD
is a process control system. It watches over configured processes and ensures that they are running. It also restarts services when necessary. For odo,SupervisorD
executes and monitors the developer code.
-
Configuration files:
-
supervisor.conf
is the configuration file necessary for the SupervisorD daemon to start.
-
Scripts:
-
assemble-and-restart
is an OpenShift S2I concept to build and deploy user-source code. The assemble-and-restart script first assembles the user source code inside the application container and then restarts SupervisorD for user changes to take effect. -
Run
is an OpenShift S2I concept of executing the assembled source code. Therun
script executes the assembled code created by theassemble-and-restart
script. -
s2i-setup
is a script that creates files and directories which are necessary for theassemble-and-restart
and run scripts to execute successfully. The script is executed whenever the application container starts.
-
Directories:
-
language-scripts
: OpenShift S2I allows customassemble
andrun
scripts. A few language specific custom scripts are present in thelanguage-scripts
directory. The custom scripts provide additional configuration to make odo debug work.
-
The emptyDir
volume is mounted at the /opt/odo
mount point for both the Init container and the application container.
2.2.3.1.2. copy-files-to-volume Copia collegamentoCollegamento copiato negli appunti!
The copy-files-to-volume
Init container copies files that are in /opt/app-root
in the S2I builder image onto the persistent volume. The volume is then mounted at the same location (/opt/app-root
) in an application container.
Without the persistent volume on /opt/app-root
the data in this directory is lost when the persistent volume claim is mounted at the same location.
The PVC is mounted at the /mnt
mount point inside the Init container.
2.2.3.2. Application container Copia collegamentoCollegamento copiato negli appunti!
Application container is the main container inside of which the user-source code executes.
Application container is mounted with two volumes:
-
emptyDir
volume mounted at/opt/odo
-
The persistent volume mounted at
/opt/app-root
go-init
is executed as the first process inside the application container. The go-init
process then starts the SupervisorD
daemon.
SupervisorD
executes and monitors the user assembled source code. If the user process crashes, SupervisorD
restarts it.
2.2.3.3. Persistent volumes and persistent volume claims Copia collegamentoCollegamento copiato negli appunti!
A persistent volume claim (PVC) is a volume type in Kubernetes which provisions a persistent volume. The life of a persistent volume is independent of a pod lifecycle. The data on the persistent volume persists across pod restarts.
The copy-files-to-volume
Init container copies necessary files onto the persistent volume. The main application container utilizes these files at runtime for execution.
The naming convention of the persistent volume is <component_name>-s2idata.
Container | PVC mounted at |
---|---|
|
|
Application container |
|
2.2.3.4. emptyDir volume Copia collegamentoCollegamento copiato negli appunti!
An emptyDir
volume is created when a pod is assigned to a node, and exists as long as that pod is running on the node. If the container is restarted or moved, the content of the emptyDir
is removed, Init container restores the data back to the emptyDir
. emptyDir
is initially empty.
The copy-supervisord
Init container copies necessary files onto the emptyDir
volume. These files are then utilized by the main application container at runtime for execution.
Container | emptyDir volume mounted at |
---|---|
|
|
Application container |
|
2.2.3.5. Service Copia collegamentoCollegamento copiato negli appunti!
A service is a Kubernetes concept of abstracting the way of communicating with a set of pods.
odo creates a service for every application pod to make it accessible for communication.
2.2.4. odo push workflow Copia collegamentoCollegamento copiato negli appunti!
This section describes odo push
workflow. odo push deploys user code on an OpenShift Container Platform cluster with all the necessary OpenShift Container Platform resources.
Creating resources
If not already created,
odo
push creates the following OpenShift Container Platform resources:DeploymentConfig
object:-
Two init containers are executed:
copy-supervisord
andcopy-files-to-volume
. The init containers copy files onto theemptyDir
and thePersistentVolume
type of volumes respectively. -
The application container starts. The first process in the application container is the
go-init
process with PID=1. go-init
process starts the SupervisorD daemon.NoteThe user application code has not been copied into the application container yet, so the
SupervisorD
daemon does not execute therun
script.
-
Two init containers are executed:
-
Service
object -
Secret
objects -
PersistentVolumeClaim
object
Indexing files
- A file indexer indexes the files in the source code directory. The indexer traverses through the source code directories recursively and finds files which have been created, deleted, or renamed.
-
A file indexer maintains the indexed information in an odo index file inside the
.odo
directory. - If the odo index file is not present, it means that the file indexer is being executed for the first time, and creates a new odo index JSON file. The odo index JSON file contains a file map - the relative file paths of the traversed files and the absolute paths of the changed and deleted files.
Pushing code
Local code is copied into the application container, usually under
/tmp/src
.Executing
assemble-and-restart
On a successful copy of the source code, the
assemble-and-restart
script is executed inside the running application container.
2.3. Installing odo Copia collegamentoCollegamento copiato negli appunti!
The following section describes how to install odo
on different platforms using the CLI.
Currently, odo
does not support installation in a restricted network environment.
You can also find the URL to the latest binaries from the OpenShift Container Platform web console by clicking the ? icon in the upper-right corner and selecting Command Line Tools
2.3.1. Installing odo on Linux Copia collegamentoCollegamento copiato negli appunti!
2.3.1.1. Binary installation Copia collegamentoCollegamento copiato negli appunti!
Procedure
Obtain the binary:
curl -L https://mirror.openshift.com/pub/openshift-v4/clients/odo/latest/odo-linux-amd64 -o /usr/local/bin/odo
# curl -L https://mirror.openshift.com/pub/openshift-v4/clients/odo/latest/odo-linux-amd64 -o /usr/local/bin/odo
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Change the permissions on the file:
chmod +x /usr/local/bin/odo
# chmod +x /usr/local/bin/odo
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.3.1.2. Tarball installation Copia collegamentoCollegamento copiato negli appunti!
Procedure
Obtain the tarball:
sh -c 'curl -L https://mirror.openshift.com/pub/openshift-v4/clients/odo/latest/odo-linux-amd64.tar.gz | gzip -d > /usr/local/bin/odo'
# sh -c 'curl -L https://mirror.openshift.com/pub/openshift-v4/clients/odo/latest/odo-linux-amd64.tar.gz | gzip -d > /usr/local/bin/odo'
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Change the permissions on the file:
chmod +x /usr/local/bin/odo
# chmod +x /usr/local/bin/odo
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.3.2. Installing odo on Linux on IBM Power Copia collegamentoCollegamento copiato negli appunti!
2.3.2.1. Binary installation Copia collegamentoCollegamento copiato negli appunti!
Procedure
Obtain the binary:
curl -L https://mirror.openshift.com/pub/openshift-v4/clients/odo/latest/odo-linux-ppc64le -o /usr/local/bin/odo
# curl -L https://mirror.openshift.com/pub/openshift-v4/clients/odo/latest/odo-linux-ppc64le -o /usr/local/bin/odo
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Change the permissions on the file:
chmod +x /usr/local/bin/odo
# chmod +x /usr/local/bin/odo
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.3.2.2. Tarball installation Copia collegamentoCollegamento copiato negli appunti!
Procedure
Obtain the tarball:
sh -c 'curl -L https://mirror.openshift.com/pub/openshift-v4/clients/odo/latest/odo-linux-ppc64le.tar.gz | gzip -d > /usr/local/bin/odo'
# sh -c 'curl -L https://mirror.openshift.com/pub/openshift-v4/clients/odo/latest/odo-linux-ppc64le.tar.gz | gzip -d > /usr/local/bin/odo'
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Change the permissions on the file:
chmod +x /usr/local/bin/odo
# chmod +x /usr/local/bin/odo
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.3.3. Installing odo on Linux on IBM Z and LinuxONE Copia collegamentoCollegamento copiato negli appunti!
2.3.3.1. Binary installation Copia collegamentoCollegamento copiato negli appunti!
Procedure
Obtain the binary:
curl -L https://mirror.openshift.com/pub/openshift-v4/clients/odo/latest/odo-linux-s390x -o /usr/local/bin/odo
# curl -L https://mirror.openshift.com/pub/openshift-v4/clients/odo/latest/odo-linux-s390x -o /usr/local/bin/odo
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Change the permissions on the file:
chmod +x /usr/local/bin/odo
# chmod +x /usr/local/bin/odo
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.3.3.2. Tarball installation Copia collegamentoCollegamento copiato negli appunti!
Procedure
Obtain the tarball:
sh -c 'curl -L https://mirror.openshift.com/pub/openshift-v4/clients/odo/latest/odo-linux-s390x.tar.gz | gzip -d > /usr/local/bin/odo'
# sh -c 'curl -L https://mirror.openshift.com/pub/openshift-v4/clients/odo/latest/odo-linux-s390x.tar.gz | gzip -d > /usr/local/bin/odo'
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Change the permissions on the file:
chmod +x /usr/local/bin/odo
# chmod +x /usr/local/bin/odo
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.3.4. Installing odo on Windows Copia collegamentoCollegamento copiato negli appunti!
2.3.4.1. Binary installation Copia collegamentoCollegamento copiato negli appunti!
-
Download the latest
odo.exe
file. -
Add the location of your
odo.exe
to yourGOPATH/bin
directory.
Setting the PATH
variable for Windows 7/8
The following example demonstrates how to set up a path variable. Your binaries can be located in any location, but this example uses C:\go-bin
as the location.
-
Create a folder at
C:\go-bin
. - Right click Start and click Control Panel.
- Select System and Security and then click System.
- From the menu on the left, select the Advanced systems settings and click the Environment Variables button at the bottom.
- Select Path from the Variable section and click Edit.
-
Click New and type
C:\go-bin
into the field or click Browse and select the directory, and click OK.
Setting the PATH
variable for Windows 10
Edit Environment Variables
using search:
-
Click Search and type
env
orenvironment
. - Select Edit environment variables for your account.
- Select Path from the Variable section and click Edit.
-
Click New and type
C:\go-bin
into the field or click Browse and select the directory, and click OK.
2.3.5. Installing odo on macOS Copia collegamentoCollegamento copiato negli appunti!
2.3.5.1. Binary installation Copia collegamentoCollegamento copiato negli appunti!
Procedure
Obtain the binary:
curl -L https://mirror.openshift.com/pub/openshift-v4/clients/odo/latest/odo-darwin-amd64 -o /usr/local/bin/odo
# curl -L https://mirror.openshift.com/pub/openshift-v4/clients/odo/latest/odo-darwin-amd64 -o /usr/local/bin/odo
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Change the permissions on the file:
chmod +x /usr/local/bin/odo
# chmod +x /usr/local/bin/odo
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.3.5.2. Tarball installation Copia collegamentoCollegamento copiato negli appunti!
Procedure
Obtain the tarball:
sh -c 'curl -L https://mirror.openshift.com/pub/openshift-v4/clients/odo/latest/odo-darwin-amd64.tar.gz | gzip -d > /usr/local/bin/odo'
# sh -c 'curl -L https://mirror.openshift.com/pub/openshift-v4/clients/odo/latest/odo-darwin-amd64.tar.gz | gzip -d > /usr/local/bin/odo'
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Change the permissions on the file:
chmod +x /usr/local/bin/odo
# chmod +x /usr/local/bin/odo
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.4. Using odo in a restricted environment Copia collegamentoCollegamento copiato negli appunti!
2.4.1. About odo in a restricted environment Copia collegamentoCollegamento copiato negli appunti!
To run odo
in a disconnected cluster or a cluster provisioned in a restricted environment, you must ensure that a cluster administrator has created a cluster with a mirrored registry.
To start working in a disconnected cluster, you must first push the odo
init image to the registry of the cluster and then overwrite the odo
init image path using the ODO_BOOTSTRAPPER_IMAGE
environment variable.
After you push the odo
init image, you must mirror a supported builder image from the registry, overwrite a mirror registry and then create your application. A builder image is necessary to configure a runtime environment for your application and also contains the build tool needed to build your application, for example npm for Node.js or Maven for Java. A mirror registry contains all the necessary dependencies for your application.
Additional resources
2.4.2. Pushing the odo init image to the restricted cluster registry Copia collegamentoCollegamento copiato negli appunti!
Depending on the configuration of your cluster and your operating system you can either push the odo
init image to a mirror registry or directly to an internal registry.
2.4.2.1. Prerequisites Copia collegamentoCollegamento copiato negli appunti!
-
Install
oc
on the client operating system. -
Install
odo
on the client operating system. - Access to a restricted cluster with a configured internal registry or a mirror registry.
2.4.2.2. Pushing the odo init image to a mirror registry Copia collegamentoCollegamento copiato negli appunti!
Depending on your operating system, you can push the odo
init image to a cluster with a mirror registry as follows:
2.4.2.2.1. Pushing the init image to a mirror registry on Linux Copia collegamentoCollegamento copiato negli appunti!
Procedure
Use
base64
to encode the root certification authority (CA) content of your mirror registry:echo <content_of_additional_ca> | base64 --decode > disconnect-ca.crt
$ echo <content_of_additional_ca> | base64 --decode > disconnect-ca.crt
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Copy the encoded root CA certificate to the appropriate location:
sudo cp ./disconnect-ca.crt /etc/pki/ca-trust/source/anchors/<mirror-registry>.crt
$ sudo cp ./disconnect-ca.crt /etc/pki/ca-trust/source/anchors/<mirror-registry>.crt
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Trust a CA in your client platform and log into the OpenShift Container Platform mirror registry:
sudo update-ca-trust enable && sudo systemctl daemon-reload && sudo systemctl restart / docker && docker login <mirror-registry>:5000 -u <username> -p <password>
$ sudo update-ca-trust enable && sudo systemctl daemon-reload && sudo systemctl restart / docker && docker login <mirror-registry>:5000 -u <username> -p <password>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Mirror the
odo
init image:oc image mirror registry.access.redhat.com/openshiftdo/odo-init-image-rhel7:<tag> <mirror-registry>:5000/openshiftdo/odo-init-image-rhel7:<tag>
$ oc image mirror registry.access.redhat.com/openshiftdo/odo-init-image-rhel7:<tag> <mirror-registry>:5000/openshiftdo/odo-init-image-rhel7:<tag>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Override the default
odo
init image path by setting theODO_BOOTSTRAPPER_IMAGE
environment variable:export ODO_BOOTSTRAPPER_IMAGE=<mirror-registry>:5000/openshiftdo/odo-init-image-rhel7:<tag>
$ export ODO_BOOTSTRAPPER_IMAGE=<mirror-registry>:5000/openshiftdo/odo-init-image-rhel7:<tag>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.4.2.2.2. Pushing the init image to a mirror registry on MacOS Copia collegamentoCollegamento copiato negli appunti!
Procedure
Use
base64
to encode the root certification authority (CA) content of your mirror registry:echo <content_of_additional_ca> | base64 --decode > disconnect-ca.crt
$ echo <content_of_additional_ca> | base64 --decode > disconnect-ca.crt
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Copy the encoded root CA certificate to the appropriate location:
- Restart Docker using the Docker UI.
Run the following command:
docker login <mirror-registry>:5000 -u <username> -p <password>
$ docker login <mirror-registry>:5000 -u <username> -p <password>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Mirror the
odo
init image:oc image mirror registry.access.redhat.com/openshiftdo/odo-init-image-rhel7:<tag> <mirror-registry>:5000/openshiftdo/odo-init-image-rhel7:<tag>
$ oc image mirror registry.access.redhat.com/openshiftdo/odo-init-image-rhel7:<tag> <mirror-registry>:5000/openshiftdo/odo-init-image-rhel7:<tag>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Override the default
odo
init image path by setting theODO_BOOTSTRAPPER_IMAGE
environment variable:export ODO_BOOTSTRAPPER_IMAGE=<mirror-registry>:5000/openshiftdo/odo-init-image-rhel7:<tag>
$ export ODO_BOOTSTRAPPER_IMAGE=<mirror-registry>:5000/openshiftdo/odo-init-image-rhel7:<tag>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.4.2.2.3. Pushing the init image to a mirror registry on Windows Copia collegamentoCollegamento copiato negli appunti!
Procedure
Use
base64
to encode the root certification authority (CA) content of your mirror registry:PS C:\> echo <content_of_additional_ca> | base64 --decode > disconnect-ca.crt
PS C:\> echo <content_of_additional_ca> | base64 --decode > disconnect-ca.crt
Copy to Clipboard Copied! Toggle word wrap Toggle overflow As an administrator, copy the encoded root CA certificate to the appropriate location by executing the following command:
PS C:\WINDOWS\system32> certutil -addstore -f "ROOT" disconnect-ca.crt
PS C:\WINDOWS\system32> certutil -addstore -f "ROOT" disconnect-ca.crt
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Trust a CA in your client platform and log into the OpenShift Container Platform mirror registry:
- Restart Docker using the Docker UI.
Run the following command:
PS C:\WINDOWS\system32> docker login <mirror-registry>:5000 -u <username> -p <password>
PS C:\WINDOWS\system32> docker login <mirror-registry>:5000 -u <username> -p <password>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Mirror the
odo
init image:PS C:\> oc image mirror registry.access.redhat.com/openshiftdo/odo-init-image-rhel7:<tag> <mirror-registry>:5000/openshiftdo/odo-init-image-rhel7:<tag>
PS C:\> oc image mirror registry.access.redhat.com/openshiftdo/odo-init-image-rhel7:<tag> <mirror-registry>:5000/openshiftdo/odo-init-image-rhel7:<tag>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Override the default
odo
init image path by setting theODO_BOOTSTRAPPER_IMAGE
environment variable:PS C:\> $env:ODO_BOOTSTRAPPER_IMAGE="<mirror-registry>:5000/openshiftdo/odo-init-image-rhel7:<tag>"
PS C:\> $env:ODO_BOOTSTRAPPER_IMAGE="<mirror-registry>:5000/openshiftdo/odo-init-image-rhel7:<tag>"
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.4.2.3. Pushing the odo init image to an internal registry directly Copia collegamentoCollegamento copiato negli appunti!
If your cluster allows images to be pushed to the internal registry directly, push the odo
init image to the registry as follows:
2.4.2.3.1. Pushing the init image directly on Linux Copia collegamentoCollegamento copiato negli appunti!
Procedure
Enable the default route:
oc patch configs.imageregistry.operator.openshift.io cluster -p '{"spec":{"defaultRoute":true}}' --type='merge' -n openshift-image-registry
$ oc patch configs.imageregistry.operator.openshift.io cluster -p '{"spec":{"defaultRoute":true}}' --type='merge' -n openshift-image-registry
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Get a wildcard route CA:
oc get secret router-certs-default -n openshift-ingress -o yaml
$ oc get secret router-certs-default -n openshift-ingress -o yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use
base64
to encode the root certification authority (CA) content of your mirror registry:echo <tls.crt> | base64 --decode > ca.crt
$ echo <tls.crt> | base64 --decode > ca.crt
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Trust a CA in your client platform:
sudo cp ca.crt /etc/pki/ca-trust/source/anchors/externalroute.crt && sudo update-ca-trust enable && sudo systemctl daemon-reload && sudo systemctl restart docker
$ sudo cp ca.crt /etc/pki/ca-trust/source/anchors/externalroute.crt && sudo update-ca-trust enable && sudo systemctl daemon-reload && sudo systemctl restart docker
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Log into the internal registry:
oc get route -n openshift-image-registry docker login <registry_path> -u kubeadmin -p $(oc whoami -t)
$ oc get route -n openshift-image-registry NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD default-route <registry_path> image-registry <all> reencrypt None $ docker login <registry_path> -u kubeadmin -p $(oc whoami -t)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Push the
odo
init image:docker pull registry.access.redhat.com/openshiftdo/odo-init-image-rhel7:<tag> docker tag registry.access.redhat.com/openshiftdo/odo-init-image-rhel7:<tag> <registry_path>/openshiftdo/odo-init-image-rhel7:<tag> docker push <registry_path>/openshiftdo/odo-init-image-rhel7:<tag>
$ docker pull registry.access.redhat.com/openshiftdo/odo-init-image-rhel7:<tag> $ docker tag registry.access.redhat.com/openshiftdo/odo-init-image-rhel7:<tag> <registry_path>/openshiftdo/odo-init-image-rhel7:<tag> $ docker push <registry_path>/openshiftdo/odo-init-image-rhel7:<tag>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Override the default
odo
init image path by setting theODO_BOOTSTRAPPER_IMAGE
environment variable:export ODO_BOOTSTRAPPER_IMAGE=<registry_path>/openshiftdo/odo-init-image-rhel7:1.0.1
$ export ODO_BOOTSTRAPPER_IMAGE=<registry_path>/openshiftdo/odo-init-image-rhel7:1.0.1
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.4.2.3.2. Pushing the init image directly on MacOS Copia collegamentoCollegamento copiato negli appunti!
Procedure
Enable the default route:
oc patch configs.imageregistry.operator.openshift.io cluster -p '{"spec":{"defaultRoute":true}}' --type='merge' -n openshift-image-registry
$ oc patch configs.imageregistry.operator.openshift.io cluster -p '{"spec":{"defaultRoute":true}}' --type='merge' -n openshift-image-registry
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Get a wildcard route CA:
oc get secret router-certs-default -n openshift-ingress -o yaml
$ oc get secret router-certs-default -n openshift-ingress -o yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use
base64
to encode the root certification authority (CA) content of your mirror registry:echo <tls.crt> | base64 --decode > ca.crt
$ echo <tls.crt> | base64 --decode > ca.crt
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Trust a CA in your client platform:
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ca.crt
$ sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ca.crt
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Log into the internal registry:
oc get route -n openshift-image-registry docker login <registry_path> -u kubeadmin -p $(oc whoami -t)
$ oc get route -n openshift-image-registry NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD default-route <registry_path> image-registry <all> reencrypt None $ docker login <registry_path> -u kubeadmin -p $(oc whoami -t)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Push the
odo
init image:docker pull registry.access.redhat.com/openshiftdo/odo-init-image-rhel7:<tag> docker tag registry.access.redhat.com/openshiftdo/odo-init-image-rhel7:<tag> <registry_path>/openshiftdo/odo-init-image-rhel7:<tag> docker push <registry_path>/openshiftdo/odo-init-image-rhel7:<tag>
$ docker pull registry.access.redhat.com/openshiftdo/odo-init-image-rhel7:<tag> $ docker tag registry.access.redhat.com/openshiftdo/odo-init-image-rhel7:<tag> <registry_path>/openshiftdo/odo-init-image-rhel7:<tag> $ docker push <registry_path>/openshiftdo/odo-init-image-rhel7:<tag>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Override the default
odo
init image path by setting theODO_BOOTSTRAPPER_IMAGE
environment variable:export ODO_BOOTSTRAPPER_IMAGE=<registry_path>/openshiftdo/odo-init-image-rhel7:1.0.1
$ export ODO_BOOTSTRAPPER_IMAGE=<registry_path>/openshiftdo/odo-init-image-rhel7:1.0.1
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.4.2.3.3. Pushing the init image directly on Windows Copia collegamentoCollegamento copiato negli appunti!
Procedure
Enable the default route:
PS C:\> oc patch configs.imageregistry.operator.openshift.io cluster -p '{"spec":{"defaultRoute":true}}' --type='merge' -n openshift-image-registry
PS C:\> oc patch configs.imageregistry.operator.openshift.io cluster -p '{"spec":{"defaultRoute":true}}' --type='merge' -n openshift-image-registry
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Get a wildcard route CA:
PS C:\> oc get secret router-certs-default -n openshift-ingress -o yaml
PS C:\> oc get secret router-certs-default -n openshift-ingress -o yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use
base64
to encode the root certification authority (CA) content of your mirror registry:PS C:\> echo <tls.crt> | base64 --decode > ca.crt
PS C:\> echo <tls.crt> | base64 --decode > ca.crt
Copy to Clipboard Copied! Toggle word wrap Toggle overflow As an administrator, trust a CA in your client platform by executing the following command:
PS C:\WINDOWS\system32> certutil -addstore -f "ROOT" ca.crt
PS C:\WINDOWS\system32> certutil -addstore -f "ROOT" ca.crt
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Log into the internal registry:
PS C:\> oc get route -n openshift-image-registry NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD default-route <registry_path> image-registry <all> reencrypt None PS C:\> docker login <registry_path> -u kubeadmin -p $(oc whoami -t)
PS C:\> oc get route -n openshift-image-registry NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD default-route <registry_path> image-registry <all> reencrypt None PS C:\> docker login <registry_path> -u kubeadmin -p $(oc whoami -t)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Push the
odo
init image:PS C:\> docker pull registry.access.redhat.com/openshiftdo/odo-init-image-rhel7:<tag> PS C:\> docker tag registry.access.redhat.com/openshiftdo/odo-init-image-rhel7:<tag> <registry_path>/openshiftdo/odo-init-image-rhel7:<tag> PS C:\> docker push <registry_path>/openshiftdo/odo-init-image-rhel7:<tag>
PS C:\> docker pull registry.access.redhat.com/openshiftdo/odo-init-image-rhel7:<tag> PS C:\> docker tag registry.access.redhat.com/openshiftdo/odo-init-image-rhel7:<tag> <registry_path>/openshiftdo/odo-init-image-rhel7:<tag> PS C:\> docker push <registry_path>/openshiftdo/odo-init-image-rhel7:<tag>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Override the default
odo
init image path by setting theODO_BOOTSTRAPPER_IMAGE
environment variable:PS C:\> $env:ODO_BOOTSTRAPPER_IMAGE="<registry_path>/openshiftdo/odo-init-image-rhel7:<tag>"
PS C:\> $env:ODO_BOOTSTRAPPER_IMAGE="<registry_path>/openshiftdo/odo-init-image-rhel7:<tag>"
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.4.3. Creating and deploying a component to the disconnected cluster Copia collegamentoCollegamento copiato negli appunti!
After you push the init
image to a cluster with a mirrored registry, you must mirror a supported builder image for your application with the oc
tool, overwrite the mirror registry using the environment variable, and then create your component.
2.4.3.1. Prerequisites Copia collegamentoCollegamento copiato negli appunti!
-
Install
oc
on the client operating system. -
Install
odo
on the client operating system. - Access to an restricted cluster with a configured internal registry or a mirror registry.
-
Push the
odo
init image to your cluster registry.
2.4.3.2. Mirroring a supported builder image Copia collegamentoCollegamento copiato negli appunti!
To use npm packages for Node.js dependencies and Maven packages for Java dependencies and configure a runtime environment for your application, you must mirror a respective builder image from the mirror registry.
Procedure
Verify that the required images tag is not imported:
oc describe is nodejs -n openshift
$ oc describe is nodejs -n openshift
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Mirror the supported image tag to the private registry:
oc image mirror registry.access.redhat.com/rhscl/nodejs-10-rhel7:<tag> <private_registry>/rhscl/nodejs-10-rhel7:<tag>
$ oc image mirror registry.access.redhat.com/rhscl/nodejs-10-rhel7:<tag> <private_registry>/rhscl/nodejs-10-rhel7:<tag>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Import the image:
oc tag <mirror-registry>:<port>/rhscl/nodejs-10-rhel7:<tag> nodejs-10-rhel7:latest --scheduled
$ oc tag <mirror-registry>:<port>/rhscl/nodejs-10-rhel7:<tag> nodejs-10-rhel7:latest --scheduled
Copy to Clipboard Copied! Toggle word wrap Toggle overflow You must periodically re-import the image. The
--scheduled
flag enables automatic re-import of the image.Verify that the images with the given tag have been imported:
oc describe is nodejs -n openshift
$ oc describe is nodejs -n openshift
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.4.3.3. Overwriting the mirror registry Copia collegamentoCollegamento copiato negli appunti!
To download npm packages for Node.js dependencies and Maven packages for Java dependencies from a private mirror registry, you must create and configure a mirror npm or Maven registry on the cluster. You can then overwrite the mirror registry on an existing component or when you create a new component.
Procedure
To overwrite the mirror registry on an existing component:
odo config set --env NPM_MIRROR=<npm_mirror_registry>
$ odo config set --env NPM_MIRROR=<npm_mirror_registry>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow To overwrite the mirror registry when creating a component:
odo component create nodejs --env NPM_MIRROR=<npm_mirror_registry>
$ odo component create nodejs --env NPM_MIRROR=<npm_mirror_registry>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.4.3.4. Creating a Node.js application with odo Copia collegamentoCollegamento copiato negli appunti!
To create a Node.js component, download the Node.js application and push the source code to your cluster with odo
.
Procedure
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 NoteBy 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. Creating a single-component application with odo Copia collegamentoCollegamento copiato negli appunti!
With odo
, you can create and deploy applications on clusters.
2.5.1. Prerequisites Copia collegamentoCollegamento copiato negli appunti!
-
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 Copia collegamentoCollegamento copiato negli appunti!
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 Copia collegamentoCollegamento copiato negli appunti!
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 NoteBy 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 Copia collegamentoCollegamento copiato negli appunti!
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 Copia collegamentoCollegamento copiato negli appunti!
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 Example output
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 Example output
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 Copia collegamentoCollegamento copiato negli appunti!
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
2.5.7. Connecting your application to multiple services using OpenShift Service Catalog Copia collegamentoCollegamento copiato negli appunti!
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 Copia collegamentoCollegamento copiato negli appunti!
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.
2.6. Creating a multicomponent application with odo Copia collegamentoCollegamento copiato negli appunti!
odo
allows you to create a multicomponent application, modify it, and link its components in an easy and automated way.
This example describes how to deploy a multicomponent application - a shooter game. The application consists of a front-end Node.js component and a back-end Java component.
2.6.1. Prerequisites Copia collegamentoCollegamento copiato negli appunti!
-
odo
is installed. - You have a running cluster. Developers can use CodeReady Containers (CRC) to deploy a local cluster quickly.
- Maven is installed.
2.6.2. Creating a project Copia collegamentoCollegamento copiato negli appunti!
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.6.3. Deploying the back-end component Copia collegamentoCollegamento copiato negli appunti!
To create a Java component, import the Java builder image, download the Java application and push the source code to your cluster with odo
.
Procedure
Import
openjdk18
into the cluster: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 as
builder
to make it accessible for odo:oc annotate istag/openjdk18:latest tags=builder
$ oc annotate istag/openjdk18:latest tags=builder
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run
odo catalog list components
to see the created image:odo catalog list components
$ odo catalog list components
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 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 back-end application:
git clone https://github.com/openshift-evangelists/Wild-West-Backend backend
$ git clone https://github.com/openshift-evangelists/Wild-West-Backend backend
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Change to the back-end source directory:
cd backend
$ cd backend
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Check that you have the correct files in the directory:
ls
$ ls
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
debug.sh pom.xml src
debug.sh pom.xml src
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Build the back-end source files with Maven to create a JAR file:
mvn package
$ mvn package
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a component configuration of Java component-type named
backend
:odo create openjdk18 backend --binary target/wildwest-1.0.jar
$ odo create openjdk18 backend --binary target/wildwest-1.0.jar
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
✓ Validating component [1ms] Please use `odo push` command to create the component with source deployed
✓ Validating component [1ms] Please use `odo push` command to create the component with source deployed
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Now the configuration file
config.yaml
is in the local directory of the back-end component that contains information about the component for deployment.Check the configuration settings of the back-end component in the
config.yaml
file using:odo config view
$ odo config view
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Push the component to the OpenShift Container Platform cluster.
odo push
$ odo push
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Using
odo push
, OpenShift Container Platform creates a container to host the back-end component, deploys the container into a pod running on the OpenShift Container Platform cluster, and starts thebackend
component.Validate:
The status of the action in odo:
odo log -f
$ odo log -f
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
2019-09-30 20:14:19.738 INFO 444 --- [ main] c.o.wildwest.WildWestApplication : Starting WildWestApplication v1.0 onbackend-app-1-9tnhc with PID 444 (/deployments/wildwest-1.0.jar started by jboss in /deployments)
2019-09-30 20:14:19.738 INFO 444 --- [ main] c.o.wildwest.WildWestApplication : Starting WildWestApplication v1.0 onbackend-app-1-9tnhc with PID 444 (/deployments/wildwest-1.0.jar started by jboss in /deployments)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The status of the back-end component:
odo list
$ odo list
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
APP NAME TYPE SOURCE STATE app backend openjdk18 file://target/wildwest-1.0.jar Pushed
APP NAME TYPE SOURCE STATE app backend openjdk18 file://target/wildwest-1.0.jar Pushed
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.6.4. Deploying the front-end component Copia collegamentoCollegamento copiato negli appunti!
To create and deploy a front-end component, download the Node.js application and push the source code to your cluster with odo
.
Procedure
Download the example front-end application:
git clone https://github.com/openshift/nodejs-ex frontend
$ git clone https://github.com/openshift/nodejs-ex frontend
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Change the current directory to the front-end directory:
cd frontend
$ cd frontend
Copy to Clipboard Copied! Toggle word wrap Toggle overflow List the contents of the directory to see that the front end is a Node.js application.
ls
$ ls
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
README.md openshift server.js views helm package.json tests
README.md openshift server.js views helm package.json tests
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteThe front-end component is written in an interpreted language (Node.js); it does not need to be built.
Create a component configuration of Node.js component-type named
frontend
:odo create nodejs frontend
$ odo create nodejs frontend
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
✓ Validating component [5ms] Please use `odo push` command to create the component with source deployed
✓ Validating component [5ms] Please use `odo push` command to create the component with source deployed
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Push the component to a running container.
odo push
$ odo push
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.6.5. Linking both components Copia collegamentoCollegamento copiato negli appunti!
Components running on the cluster need to be connected in order to interact. OpenShift Container Platform provides linking mechanisms to publish communication bindings from a program to its clients.
Procedure
List all the components that are running on the cluster:
odo list
$ odo list
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
OpenShift Components: APP NAME PROJECT TYPE SOURCETYPE STATE app backend testpro openjdk18 binary Pushed app frontend testpro nodejs local Pushed
OpenShift Components: APP NAME PROJECT TYPE SOURCETYPE STATE app backend testpro openjdk18 binary Pushed app frontend testpro nodejs local Pushed
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Link the current front-end component to the back end:
odo link backend --port 8080
$ odo link backend --port 8080
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
✓ Component backend has been successfully linked from the component frontend Following environment variables were added to frontend component: - COMPONENT_BACKEND_HOST - COMPONENT_BACKEND_PORT
✓ Component backend has been successfully linked from the component frontend Following environment variables were added to frontend component: - COMPONENT_BACKEND_HOST - COMPONENT_BACKEND_PORT
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The configuration information of the back-end component is added to the front-end component and the front-end component restarts.
2.6.6. Exposing components to the public Copia collegamentoCollegamento copiato negli appunti!
Procedure
Navigate to the
frontend
directory:cd frontend
$ cd frontend
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create an external URL for the application:
odo url create frontend --port 8080
$ odo url create frontend --port 8080
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
✓ URL frontend created for component: frontend To create URL on the OpenShift cluster, use `odo push`
✓ URL frontend created for component: frontend To create URL on the OpenShift cluster, use `odo push`
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Apply the changes:
odo push
$ odo push
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Open the URL in a browser to view the application.
If an application requires permissions to the active service account to access the OpenShift Container Platform namespace and delete active pods, the following error may occur when looking at odo log
from the back-end component:
Message: Forbidden!Configured service account doesn’t have access. Service account may have been revoked
To resolve this error, add permissions for the service account role:
oc policy add-role-to-group view system:serviceaccounts -n <project>
$ oc policy add-role-to-group view system:serviceaccounts -n <project>
oc policy add-role-to-group edit system:serviceaccounts -n <project>
$ oc policy add-role-to-group edit system:serviceaccounts -n <project>
Do not do this on a production cluster.
2.6.7. Modifying the running application Copia collegamentoCollegamento copiato negli appunti!
Procedure
Change the local directory to the front-end directory:
cd frontend
$ cd frontend
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Monitor the changes on the file system using:
odo watch
$ odo watch
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Edit the
index.html
file to change the displayed name for the game.NoteA slight delay is possible before odo recognizes the change.
odo pushes the changes to the front-end component and prints its status to the terminal:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Refresh the application page in the web browser. The new name is now displayed.
2.6.8. Deleting an application Copia collegamentoCollegamento copiato negli appunti!
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.
2.7. Creating an application with a database Copia collegamentoCollegamento copiato negli appunti!
This example describes how to deploy and connect a database to a front-end application.
2.7.1. Prerequisites Copia collegamentoCollegamento copiato negli appunti!
-
odo
is installed. -
oc
client is installed. - You have a running cluster. Developers can use CodeReady Containers (CRC) to deploy a local cluster quickly.
The Service Catalog is installed and enabled on your cluster.
NoteService Catalog is deprecated on OpenShift Container Platform 4 and later.
2.7.2. Creating a project Copia collegamentoCollegamento copiato negli appunti!
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.7.3. Deploying the front-end component Copia collegamentoCollegamento copiato negli appunti!
To create and deploy a front-end component, download the Node.js application and push the source code to your cluster with odo
.
Procedure
Download the example front-end application:
git clone https://github.com/openshift/nodejs-ex frontend
$ git clone https://github.com/openshift/nodejs-ex frontend
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Change the current directory to the front-end directory:
cd frontend
$ cd frontend
Copy to Clipboard Copied! Toggle word wrap Toggle overflow List the contents of the directory to see that the front end is a Node.js application.
ls
$ ls
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
README.md openshift server.js views helm package.json tests
README.md openshift server.js views helm package.json tests
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteThe front-end component is written in an interpreted language (Node.js); it does not need to be built.
Create a component configuration of Node.js component-type named
frontend
:odo create nodejs frontend
$ odo create nodejs frontend
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
✓ Validating component [5ms] Please use `odo push` command to create the component with source deployed
✓ Validating component [5ms] Please use `odo push` command to create the component with source deployed
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a URL to access the frontend interface.
odo url create myurl
$ odo url create myurl
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
✓ URL myurl created for component: nodejs-nodejs-ex-pmdp
✓ URL myurl created for component: nodejs-nodejs-ex-pmdp
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Push the component to the OpenShift Container Platform cluster.
odo push
$ odo push
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.7.4. Deploying a database in interactive mode Copia collegamentoCollegamento copiato negli appunti!
odo provides a command-line interactive mode which simplifies deployment.
Procedure
Run the interactive mode and answer the prompts:
odo service create
$ odo service create
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Your password or username will be passed to the front-end application as environment variables.
2.7.5. Deploying a database manually Copia collegamentoCollegamento copiato negli appunti!
List the available services:
odo catalog list services
$ odo catalog list services
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Choose the
mongodb-persistent
type of service and see the required parameters:odo catalog describe service mongodb-persistent
$ odo catalog describe service mongodb-persistent
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Pass the required parameters as flags and wait for the deployment of the database:
odo service create mongodb-persistent --plan default --wait -p DATABASE_SERVICE_NAME=mongodb -p MEMORY_LIMIT=512Mi -p MONGODB_DATABASE=sampledb -p VOLUME_CAPACITY=1Gi
$ odo service create mongodb-persistent --plan default --wait -p DATABASE_SERVICE_NAME=mongodb -p MEMORY_LIMIT=512Mi -p MONGODB_DATABASE=sampledb -p VOLUME_CAPACITY=1Gi
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.7.6. Connecting the database to the front-end application Copia collegamentoCollegamento copiato negli appunti!
Link the database to the front-end service:
odo link mongodb-persistent
$ odo link mongodb-persistent
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow See the environment variables of the application and the database in the pod:
Get the pod name:
oc get pods
$ oc get pods
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
NAME READY STATUS RESTARTS AGE mongodb-1-gsznc 1/1 Running 0 28m nodejs-nodejs-ex-mhbb-app-4-vkn9l 1/1 Running 0 1m
NAME READY STATUS RESTARTS AGE mongodb-1-gsznc 1/1 Running 0 28m nodejs-nodejs-ex-mhbb-app-4-vkn9l 1/1 Running 0 1m
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Connect to the pod:
oc rsh nodejs-nodejs-ex-mhbb-app-4-vkn9l
$ oc rsh nodejs-nodejs-ex-mhbb-app-4-vkn9l
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Check the environment variables:
env
sh-4.2$ env
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
uri=mongodb://172.30.126.3:27017 password=dHIOpYneSkX3rTLn database_name=sampledb username=user43U admin_password=NCn41tqmx7RIqmfv
uri=mongodb://172.30.126.3:27017 password=dHIOpYneSkX3rTLn database_name=sampledb username=user43U admin_password=NCn41tqmx7RIqmfv
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Open the URL in the browser and notice the database configuration in the bottom right:
odo url list
$ odo url list
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.7.7. Deleting an application Copia collegamentoCollegamento copiato negli appunti!
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.
2.8. Using devfiles in odo Copia collegamentoCollegamento copiato negli appunti!
Creating applications by using devfiles with `odo` is a Technology Preview feature only. Technology Preview features are not supported with Red Hat production service level agreements (SLAs) and might not be functionally complete. Red Hat does not recommend using them in production. These features provide early access to upcoming product features, enabling customers to test functionality and provide feedback during the development process.
For more information about the support scope of Red Hat Technology Preview features, see https://access.redhat.com/support/offerings/techpreview/.
2.8.1. About the devfile in odo Copia collegamentoCollegamento copiato negli appunti!
The devfile is a portable file that describes your development environment. With the devfile, you can define a portable developmental environment without the need for reconfiguration.
With the devfile, you can describe your development environment, such as the source code, IDE tools, application runtimes, and predefined commands. To learn more about the devfile, see the devfile documentation.
With odo
, you can create components from the devfiles. When creating a component by using a devfile, odo
transforms the devfile into a workspace consisting of multiple containers that run on OpenShift Container Platform, Kubernetes, or Docker. odo
automatically uses the default devfile registry but users can add their own registries.
2.8.2. Creating a Java application by using a devfile Copia collegamentoCollegamento copiato negli appunti!
2.8.3. Prerequisites Copia collegamentoCollegamento copiato negli appunti!
-
You have installed
odo
. -
You must know your ingress domain cluster name. Contact your cluster administrator if you do not know it. For example,
apps-crc.testing
is the cluster domain name for Red Hat CodeReady Containers. You have enabled Experimental Mode in
odo
.-
To enable Experimental Mode in
odo
preferences, runodo preference set Experimental true
or use the environment variableodo config set --env ODO_EXPERIMENTAL=true
-
To enable Experimental Mode in
2.8.3.1. Creating a project Copia collegamentoCollegamento copiato negli appunti!
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.8.3.2. Listing available devfile components Copia collegamentoCollegamento copiato negli appunti!
With odo
, you can display all the components that are available for you on the cluster. Components that are available depend on the configuration of your cluster.
Procedure
To list available devfile components on your cluster, run:
odo catalog list components
$ odo catalog list components
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The output lists the available
odo
components:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.8.3.3. Deploying a Java application using a devfile Copia collegamentoCollegamento copiato negli appunti!
In this section, you will learn how to deploy a sample Java project that uses Maven and Java 8 JDK using a devfile.
Procedure
Create a directory to store the source code of your component:
mkdir <directory-name>
$ mkdir <directory-name>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a component configuration of Spring Boot component type named
myspring
and download its sample project:odo create java-spring-boot myspring --starter
$ odo create java-spring-boot myspring --starter
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The previous command produces the following output:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
odo create
command downloads the associateddevfile.yaml
file from the recorded devfile registries.List the contents of the directory to confirm that the devfile and the sample Java application were downloaded:
ls
$ ls
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The previous command produces the following output:
README.md devfile.yaml pom.xml src
README.md devfile.yaml pom.xml src
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a URL to access the deployed component:
odo url create --host apps-crc.testing
$ odo url create --host apps-crc.testing
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The previous command produces the following output:
✓ URL myspring-8080.apps-crc.testing created for component: myspring To apply the URL configuration changes, please use odo push
✓ URL myspring-8080.apps-crc.testing created for component: myspring To apply the URL configuration changes, please use odo push
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteYou must use your cluster host domain name when creating the URL.
Push the component to the cluster:
odo push
$ odo push
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The previous command produces the following output:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow List the URLs of the component to verify that the component was pushed successfully:
odo url list
$ odo url list
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The previous command produces the following output:
Found the following URLs for component myspring NAME URL PORT SECURE myspring-8080 http://myspring-8080.apps-crc.testing 8080 false
Found the following URLs for component myspring NAME URL PORT SECURE myspring-8080 http://myspring-8080.apps-crc.testing 8080 false
Copy to Clipboard Copied! Toggle word wrap Toggle overflow View your deployed application by using the generated URL:
curl http://myspring-8080.apps-crc.testing
$ curl http://myspring-8080.apps-crc.testing
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.8.4. Converting an S2I component into a devfile component Copia collegamentoCollegamento copiato negli appunti!
With odo
, you can create both Source-to-Image (S2I) and devfile components. If you have an existing S2I component, you can convert it into a devfile component using the odo utils
command.
Procedure
Run all the commands from the S2I component directory.
Run the
odo utils convert-to-devfile
command, which createsdevfile.yaml
andenv.yaml
based on your component:odo utils convert-to-devfile
$ odo utils convert-to-devfile
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Push the component to your cluster:
odo push
$ odo push
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteIf the devfile component deployment failed, delete it by running:
odo delete -a
Verify that the devfile component deployed successfully:
odo list
$ odo list
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Delete the S2I component:
odo delete --s2i
$ odo delete --s2i
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.9. Using sample applications Copia collegamentoCollegamento copiato negli appunti!
odo
offers partial compatibility with any language or runtime listed within the OpenShift catalog of component types. For example:
For odo
Java and Node.js are the officially supported component types. Run odo catalog list components
to verify the officially supported component types.
In order to access the component over the web, create a URL using odo url create
.
2.9.1. Examples from Git repositories Copia collegamentoCollegamento copiato negli appunti!
2.9.1.1. httpd Copia collegamentoCollegamento copiato negli appunti!
This example helps build and serve static content using httpd on CentOS 7. For more information about using this builder image, including OpenShift Container Platform considerations, see the Apache HTTP Server container image repository.
odo create httpd --git https://github.com/openshift/httpd-ex.git
$ odo create httpd --git https://github.com/openshift/httpd-ex.git
2.9.1.2. java Copia collegamentoCollegamento copiato negli appunti!
This example helps build and run fat JAR Java applications on CentOS 7. For more information about using this builder image, including OpenShift Container Platform considerations, see the Java S2I Builder image.
odo create java --git https://github.com/spring-projects/spring-petclinic.git
$ odo create java --git https://github.com/spring-projects/spring-petclinic.git
2.9.1.3. nodejs Copia collegamentoCollegamento copiato negli appunti!
Build and run Node.js applications on CentOS 7. For more information about using this builder image, including OpenShift Container Platform considerations, see the Node.js 8 container image.
odo create nodejs --git https://github.com/openshift/nodejs-ex.git
$ odo create nodejs --git https://github.com/openshift/nodejs-ex.git
2.9.1.4. perl Copia collegamentoCollegamento copiato negli appunti!
This example helps build and run Perl applications on CentOS 7. For more information about using this builder image, including OpenShift Container Platform considerations, see the Perl 5.26 container image.
odo create perl --git https://github.com/openshift/dancer-ex.git
$ odo create perl --git https://github.com/openshift/dancer-ex.git
2.9.1.5. php Copia collegamentoCollegamento copiato negli appunti!
This example helps build and run PHP applications on CentOS 7. For more information about using this builder image, including OpenShift Container Platform considerations, see the PHP 7.1 Docker image.
odo create php --git https://github.com/openshift/cakephp-ex.git
$ odo create php --git https://github.com/openshift/cakephp-ex.git
2.9.1.6. python Copia collegamentoCollegamento copiato negli appunti!
This example helps build and run Python applications on CentOS 7. For more information about using this builder image, including OpenShift Container Platform considerations, see the Python 3.6 container image.
odo create python --git https://github.com/openshift/django-ex.git
$ odo create python --git https://github.com/openshift/django-ex.git
2.9.1.7. ruby Copia collegamentoCollegamento copiato negli appunti!
This example helps build and run Ruby applications on CentOS 7. For more information about using this builder image, including OpenShift Container Platform considerations, see Ruby 2.5 container image.
odo create ruby --git https://github.com/openshift/ruby-ex.git
$ odo create ruby --git https://github.com/openshift/ruby-ex.git
2.9.1.8. wildfly Copia collegamentoCollegamento copiato negli appunti!
This example helps build and run WildFly applications on CentOS 7. For more information about using this builder image, including OpenShift Container Platform considerations, see the Wildfly - CentOS Docker images for OpenShift.
odo create wildfly --git https://github.com/openshift/openshift-jee-sample.git
$ odo create wildfly --git https://github.com/openshift/openshift-jee-sample.git
2.9.2. Binary examples Copia collegamentoCollegamento copiato negli appunti!
2.9.2.1. java Copia collegamentoCollegamento copiato negli appunti!
Java can be used to deploy a binary artifact as follows:
git clone https://github.com/spring-projects/spring-petclinic.git cd spring-petclinic mvn package odo create java test3 --binary target/*.jar odo push
$ git clone https://github.com/spring-projects/spring-petclinic.git
$ cd spring-petclinic
$ mvn package
$ odo create java test3 --binary target/*.jar
$ odo push
2.9.2.2. wildfly Copia collegamentoCollegamento copiato negli appunti!
WildFly can be used to deploy a binary application as follows:
2.10. Creating instances of services managed by Operators Copia collegamentoCollegamento copiato negli appunti!
Creating instances of services managed by Operators in `odo` is a Technology Preview feature only. Technology Preview features are not supported with Red Hat production service level agreements (SLAs) and might not be functionally complete. Red Hat does not recommend using them in production. These features provide early access to upcoming product features, enabling customers to test functionality and provide feedback during the development process.
For more information about the support scope of Red Hat Technology Preview features, see https://access.redhat.com/support/offerings/techpreview/.
Operators are a method of packaging, deploying, and managing Kubernetes services. With odo
, you can create instances of services from the custom resource definitions (CRDs) provided by the Operators. You can then use these instances in your projects and link them to your components.
To create services from an Operator, you must ensure that the Operator has valid values defined in its metadata
to start the requested service. odo
uses the metadata.annotations.alm-examples
YAML file of an Operator to start the service. If this YAML has placeholder values or sample values, a service cannot start. You can modify the YAML file and start the service with the modified values. To learn how to modify YAML files and start services from it, see Creating services from YAML files.
2.10.1. Prerequisites Copia collegamentoCollegamento copiato negli appunti!
Install the
oc
CLI and log into the cluster.- Note that the configuration of the cluster determines the services available to you. To access the Operator services, a cluster administrator must install the respective Operator on the cluster first. To learn more, see Adding Operators to the cluster.
-
Install the
odo
CLI. -
Enable experimental mode. To enable experimental mode in
odo
, run:odo preference set Experimental true
or use the environment variableodo config set --env ODO_EXPERIMENTAL=true
2.10.2. Creating a project Copia collegamentoCollegamento copiato negli appunti!
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.10.3. Listing available services from the Operators installed on the cluster Copia collegamentoCollegamento copiato negli appunti!
With odo
, you can display the list of the Operators installed on your cluster, and the services they provide.
To list the Operators installed in current project, run:
odo catalog list services
$ odo catalog list services
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The command lists Operators and the CRDs. The output of the command shows the Operators installed on your cluster. For example:
Operators available in the cluster NAME CRDs etcdoperator.v0.9.4 EtcdCluster, EtcdBackup, EtcdRestore mongodb-enterprise.v1.4.5 MongoDB, MongoDBUser, MongoDBOpsManager
Operators available in the cluster NAME CRDs etcdoperator.v0.9.4 EtcdCluster, EtcdBackup, EtcdRestore mongodb-enterprise.v1.4.5 MongoDB, MongoDBUser, MongoDBOpsManager
Copy to Clipboard Copied! Toggle word wrap Toggle overflow etcdoperator.v0.9.4
is the Operator,EtcdCluster
,EtcdBackup
andEtcdRestore
are the CRDs provided by the Operator.
2.10.4. Creating a service from an Operator Copia collegamentoCollegamento copiato negli appunti!
If an Operator has valid values defined in its metadata
to start the requested service, you can use the service with odo service create
.
Print the YAML of the service as a file on your local drive:
oc get csv/etcdoperator.v0.9.4 -o yaml
$ oc get csv/etcdoperator.v0.9.4 -o yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that the values of the service are valid:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Start an
EtcdCluster
service from theetcdoperator.v0.9.4
Operator:odo service create etcdoperator.v0.9.4 EtcdCluster
$ odo service create etcdoperator.v0.9.4 EtcdCluster
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that a service has started:
oc get EtcdCluster
$ oc get EtcdCluster
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.10.5. Creating services from YAML files Copia collegamentoCollegamento copiato negli appunti!
If the YAML definition of the service or custom resource (CR) has invalid or placeholder data, you can use the --dry-run
flag to get the YAML definition, specify the correct values, and start the service using the corrected YAML definition. Printing and modifying the YAML used to start a service odo
provides the feature to print the YAML definition of the service or CR provided by the Operator before starting a service.
To display the YAML of the service, run:
odo service create <operator-name> --dry-run
$ odo service create <operator-name> --dry-run
Copy to Clipboard Copied! Toggle word wrap Toggle overflow For example, to print YAML definition of
EtcdCluster
provided by theetcdoperator.v0.9.4
Operator, run:odo service create etcdoperator.v0.9.4 --dry-run
$ odo service create etcdoperator.v0.9.4 --dry-run
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The YAML is saved as the
etcd.yaml
file.Modify the
etcd.yaml
file:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Start a service from the YAML file:
odo service create --from-file etcd.yaml
$ odo service create --from-file etcd.yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that the
EtcdCluster
service has started with one pod instead of the pre-configured three pods:oc get pods | grep my-etcd-cluster
$ oc get pods | grep my-etcd-cluster
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.11. Debugging applications in odo Copia collegamentoCollegamento copiato negli appunti!
With odo
, you can attach a debugger to remotely debug your application. This feature is only supported for NodeJS and Java components.
Components created with odo
run in the debug mode by default. A debugger agent runs on the component, on a specific port. To start debugging your application, you must start port forwarding and attach the local debugger bundled in your Integrated development environment (IDE).
2.11.1. Debugging an application Copia collegamentoCollegamento copiato negli appunti!
You can debug your application on in odo
with the odo debug
command.
Procedure
After an application is deployed, start the port forwarding for your component to debug the application:
odo debug port-forward
$ odo debug port-forward
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Attach the debugger bundled in your IDE to the component. Instructions vary depending on your IDE.
2.11.2. Configuring debugging parameters Copia collegamentoCollegamento copiato negli appunti!
You can specify a remote port with odo config
command and a local port with the odo debug
command.
Procedure
To set a remote port on which the debugging agent should run, run:
odo config set DebugPort 9292
$ odo config set DebugPort 9292
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteYou must redeploy your component for this value to be reflected on the component.
To set a local port to port forward, run:
odo debug port-forward --local-port 9292
$ odo debug port-forward --local-port 9292
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteThe local port value does not persist. You must provide it every time you need to change the port.
2.12. Managing environment variables Copia collegamentoCollegamento copiato negli appunti!
odo
stores component-specific configurations and environment variables in the config
file. You can use the odo config
command to set, unset, and list environment variables for components without the need to modify the config
file.
2.12.1. Setting and unsetting environment variables Copia collegamentoCollegamento copiato negli appunti!
Procedure
To set an environment variable in a component:
odo config set --env <variable>=<value>
$ odo config set --env <variable>=<value>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow To unset an environment variable in a component:
odo config unset --env <variable>
$ odo config unset --env <variable>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow To list all environment variables in a component:
odo config view
$ odo config view
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.13. Configuring the odo CLI Copia collegamentoCollegamento copiato negli appunti!
2.13.1. Using command completion Copia collegamentoCollegamento copiato negli appunti!
Currently command completion is only supported for bash, zsh, and fish shells.
odo provides a smart completion of command parameters based on user input. For this to work, odo needs to integrate with the executing shell.
Procedure
To install command completion automatically:
Run:
odo --complete
$ odo --complete
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Press
y
when prompted to install the completion hook.
-
To install the completion hook manually, add
complete -o nospace -C <full_path_to_your_odo_binary> odo
to your shell configuration file. After any modification to your shell configuration file, restart your shell. To disable completion:
Run:
odo --uncomplete
$ odo --uncomplete
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Press
y
when prompted to uninstall the completion hook.
Re-enable command completion if you either rename the odo executable or move it to a different directory.
2.13.2. Ignoring files or patterns Copia collegamentoCollegamento copiato negli appunti!
You can configure a list of files or patterns to ignore by modifying the .odoignore
file in the root directory of your application. This applies to both odo push
and odo watch
.
If the .odoignore
file does not exist, the .gitignore
file is used instead for ignoring specific files and folders.
To ignore .git
files, any files with the .js
extension, and the folder tests
, add the following to either the .odoignore
or the .gitignore
file:
.git *.js tests/
.git
*.js
tests/
The .odoignore
file allows any glob expressions.
2.14. odo CLI reference Copia collegamentoCollegamento copiato negli appunti!
2.14.1. Basic odo CLI commands Copia collegamentoCollegamento copiato negli appunti!
2.14.1.1. app Copia collegamentoCollegamento copiato negli appunti!
Perform application operations related to your OpenShift Container Platform project.
Example using app
2.14.1.2. catalog Copia collegamentoCollegamento copiato negli appunti!
Perform catalog-related operations.
Example using catalog
2.14.1.3. component Copia collegamentoCollegamento copiato negli appunti!
Manage components of an application.
Example using component
Create a new component Create a local configuration and create all objects on the cluster
# Create a new component
odo component create
# Create a local configuration and create all objects on the cluster
odo component create --now
2.14.1.4. config Copia collegamentoCollegamento copiato negli appunti!
Modify odo
specific settings within the config
file.
Example using config
Application | Application is the name of application the component needs to be part of |
CPU | The minimum and maximum CPU a component can consume |
Ignore | Consider the .odoignore file for push and watch |
Application | The name of application that the component needs to be part of |
CPU | The minimum and maximum CPU a component can consume |
Ignore |
Whether to consider the |
MaxCPU | The maximum CPU a component can consume |
MaxMemory | The maximum memory a component can consume |
Memory | The minimum and maximum memory a component can consume |
MinCPU | The minimum CPU a component can consume |
MinMemory | The minimum memory a component is provided |
Name | The name of the component |
Ports | Ports to be opened in the component |
Project | The name of the project that the component is part of |
Ref | Git ref to use for creating component from git source |
SourceLocation | The path indicates the location of binary file or git source |
SourceType | Type of component source - git/binary/local |
Storage | Storage of the component |
Type | The type of component |
Url | The URL to access the component |
2.14.1.5. create Copia collegamentoCollegamento copiato negli appunti!
Create a configuration describing a component to be deployed on OpenShift Container Platform. If a component name is not provided, it is autogenerated.
By default, builder images are used from the current namespace. To explicitly supply a namespace, use: odo create namespace/name:version
. If a version is not specified, the version defaults to latest
.
Use odo catalog list
to see a full list of component types that can be deployed.
Example using create
2.14.1.6. debug Copia collegamentoCollegamento copiato negli appunti!
Debug a component.
Example using debug
2.14.1.7. delete Copia collegamentoCollegamento copiato negli appunti!
Delete an existing component.
Example using delete
Delete component named 'frontend'.
# Delete component named 'frontend'.
odo delete frontend
odo delete frontend --all-apps
2.14.1.8. describe Copia collegamentoCollegamento copiato negli appunti!
Describe the given component.
Example using describe
Describe nodejs component
# Describe nodejs component
odo describe nodejs
2.14.1.9. link Copia collegamentoCollegamento copiato negli appunti!
Link a component to a service or component.
Example using link
Link adds the appropriate secret to the environment of the source component. The source component can then consume the entries of the secret as environment variables. If the source component is not provided, the current active component is assumed.
2.14.1.10. list Copia collegamentoCollegamento copiato negli appunti!
List all the components in the current application and the states of the components.
The states of the components
- Pushed
- A component is pushed to the cluster.
- Not Pushed
- A component is not pushed to the cluster.
- Unknown
-
odo
is disconnected from the cluster.
Example using list
List all components in the application
# List all components in the application
odo list
# List all the components in a given path
odo list --path <path_to_your_component>
2.14.1.11. log Copia collegamentoCollegamento copiato negli appunti!
Retrieve the log for the given component.
Example using log
Get the logs for the nodejs component
# Get the logs for the nodejs component
odo log nodejs
2.14.1.12. login Copia collegamentoCollegamento copiato negli appunti!
Log in to the cluster.
Example using login
2.14.1.13. logout Copia collegamentoCollegamento copiato negli appunti!
Log out of the current OpenShift Container Platform session.
Example using logout
Log out
# Log out
odo logout
2.14.1.14. preference Copia collegamentoCollegamento copiato negli appunti!
Modify odo
specific configuration settings within the global preference file.
Example using preference
By default, the path to the global preference file is ~/.odo/preferece.yaml
and it is stored in the environment variable GLOBALODOCONFIG
. You can set up a custom path by setting the value of the environment variable to a new preference path, for example GLOBALODOCONFIG="new_path/preference.yaml"
NamePrefix | The default prefix is the current directory name. Use this value to set a default name prefix. |
Timeout | The timeout (in seconds) for OpenShift Container Platform server connection checks. |
UpdateNotification | Controls whether an update notification is shown. |
2.14.1.15. project Copia collegamentoCollegamento copiato negli appunti!
Perform project operations.
Example using project
2.14.1.16. push Copia collegamentoCollegamento copiato negli appunti!
Push source code to a component.
Example using push
2.14.1.17. registry Copia collegamentoCollegamento copiato negli appunti!
Create and modify custom registries.
Example using registry
2.14.1.18. service Copia collegamentoCollegamento copiato negli appunti!
Perform service catalog operations.
Example using service
2.14.1.19. storage Copia collegamentoCollegamento copiato negli appunti!
Perform storage operations.
Example using storage
2.14.1.20. unlink Copia collegamentoCollegamento copiato negli appunti!
Unlink component or a service.
For this command to be successful, the service or component must have been linked prior to the invocation using odo link
.
Example using unlink
2.14.1.21. update Copia collegamentoCollegamento copiato negli appunti!
Update the source code path of a component
Example using update
2.14.1.22. url Copia collegamentoCollegamento copiato negli appunti!
Expose a component to the outside world.
Example using url
The URLs that are generated using this command can be used to access the deployed components from outside the cluster.
2.14.1.23. utils Copia collegamentoCollegamento copiato negli appunti!
Utilities for terminal commands and modifying odo configurations.
Example using utils
Bash terminal PS1 support
# Bash terminal PS1 support
source <(odo utils terminal bash)
# Zsh terminal PS1 support
source <(odo utils terminal zsh)
2.14.1.24. version Copia collegamentoCollegamento copiato negli appunti!
Print the client version information.
Example using version
Print the client version of odo
# Print the client version of odo
odo version
2.14.1.25. watch Copia collegamentoCollegamento copiato negli appunti!
odo starts watching for changes and updates the component upon a change automatically.
Example using watch
Watch for changes in directory for current component
# Watch for changes in directory for current component
odo watch
# Watch for changes in directory for component called frontend
odo watch frontend
2.15. odo release notes Copia collegamentoCollegamento copiato negli appunti!
2.15.1. Notable changes and improvements in odo Copia collegamentoCollegamento copiato negli appunti!
-
The
--devfile
flag is added toodo create
. Runodo create <component name> --devfile <devfile path>
to specify your devfile location. This flag is only available in the Experimental Mode. See Technology Preview features to learn how to enable it. Dynamic registry support. Now you can configure your own registries with the following commands:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
The
--starter
flag is added toodo create
. Runodo create nodejs --starter <project-name>
to download the source code of a project specified in the devfile. If no project name is specified,odo
downloads the first one. -
The
--context
flag is added toodo push
. With--context
, you can triggerodo push
from outside the source code directory. Runodo push --devfile <path to the devfile> --context <directory with your component>
to specify the directory of your component. -
Performance improvement for
odo catalog list components
when using the devfiles. -
The
--now
flag is added forodo url delete
when using the devfiles. -
odo url delete --now
now works with the devfiles. -
The
--debug
flag now works with the devfiles. -
Added machine-readable output for listing Operator-backed services. Run
odo catalog list services -o json
to display information about Operators and services in JSON format. -
Added machine-readable output for debugging. Run
odo debug info -o json
to display the debugging information in JSON format. -
Added machine-readable output for
odo push
. Runodo push -o json
to display event notifications in JSON format.
2.15.2. Getting support Copia collegamentoCollegamento copiato negli appunti!
For Documentation
If you find an error or have suggestions for improving the documentation, file an issue in Bugzilla. Choose the OpenShift Container Platform product type and the Documentation component type.
For Product
If you find an error, encounter a bug, or have suggestions for improving the functionality of odo
, file an issue in Bugzilla. Choose the Red Hat odo for OpenShift Container Platform product type.
Provide as many details in the issue description as possible.
2.15.3. Known issues Copia collegamentoCollegamento copiato negli appunti!
-
Bug 1760574 A deleted namespace is listed in the
odo project get
command. -
Bug 1760586 The
odo delete
command starts an infinite loop after a project is deleted and a component name is set. -
Bug 1760588 The
odo service create
command crashes when run in Cygwin. -
Bug 1760590 In Git BASH for Windows, the
odo login -u developer
command does not hide a typed password when requested. -
Bug 1783188 In a disconnected cluster, the
odo component create
command throws an error…tag not found…
despite the component being listed in the catalog list. - Bug 1761440 It is not possible to create two Services of the same type in one project.
Bug 1821643
odo push
does not work on the .NET component tag 2.1+.Workaround: specify your .NET project file by running:
odo config set --env DOTNET_STARTUP_PROJECT=<path to your project file>
$ odo config set --env DOTNET_STARTUP_PROJECT=<path to your project file>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.15.4. Technology Preview features odo Copia collegamentoCollegamento copiato negli appunti!
-
odo debug
is a feature that allows users to attach a local debugger to a component running in the Pod. To learn more, see Debugging applications in odo.
odo debug is a Technology Preview feature only. Technology Preview features are not supported with Red Hat production service level agreements (SLAs) and might not be functionally complete. Red Hat does not recommend using them in production. These features provide early access to upcoming product features, enabling customers to test functionality and provide feedback during the development process.
For more information about the support scope of Red Hat Technology Preview features, see https://access.redhat.com/support/offerings/techpreview/.
Devfile support. With odo, you can create and deploy your applications using the devfiles. To learn more, see Creating applications by using devfiles. To access this feature, you must enable Experimental Mode with
odo preference set experimental true
.To see the list of currently supported devfile components, run
odo catalog list components
.
Devfile support is a Technology Preview feature only. Technology Preview features are not supported with Red Hat production service level agreements (SLAs) and might not be functionally complete. Red Hat does not recommend using them in production. These features provide early access to upcoming product features, enabling customers to test functionality and provide feedback during the development process.
For more information about the support scope of Red Hat Technology Preview features, see https://access.redhat.com/support/offerings/techpreview/.
-
Operators support. You can now create services from Operators with
odo
. To learn more, see Creating instances of services managed by Operators. To access this feature, you must enable Experimental Mode withodo preference set experimental true
.
Operators support is a Technology Preview feature only. Technology Preview features are not supported with Red Hat production service level agreements (SLAs) and might not be functionally complete. Red Hat does not recommend using them in production. These features provide early access to upcoming product features, enabling customers to test functionality and provide feedback during the development process.
For more information about the support scope of Red Hat Technology Preview features, see https://access.redhat.com/support/offerings/techpreview/.