OpenShift - Container - Platform 4.3 CLI - Tools en US
OpenShift - Container - Platform 4.3 CLI - Tools en US
CLI tools
Learning how to use the command-line tools for OpenShift Container Platform
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons
Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is
available at
http://creativecommons.org/licenses/by-sa/3.0/
. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must
provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert,
Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift,
Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States
and other countries.
Linux ® is the registered trademark of Linus Torvalds in the United States and other countries.
XFS ® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States
and/or other countries.
MySQL ® is a registered trademark of MySQL AB in the United States, the European Union and
other countries.
Node.js ® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the
official Joyent Node.js open source or commercial project.
The OpenStack ® Word Mark and OpenStack logo are either registered trademarks/service marks
or trademarks/service marks of the OpenStack Foundation, in the United States and other
countries and are used with the OpenStack Foundation's permission. We are not affiliated with,
endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
Abstract
This document provides information about installing, configuring, and using the command-line tools
for OpenShift Container Platform. It also contains a reference of CLI commands and examples of
how to use them.
Table of Contents
Table of Contents
.CHAPTER
. . . . . . . . . . 1.. .OPENSHIFT
. . . . . . . . . . . . .CLI
. . . .(OC)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7. . . . . . . . . . . . .
1.1. GETTING STARTED WITH THE CLI 7
1.1.1. About the CLI 7
1.1.2. Installing the CLI 7
1.1.2.1. Installing the CLI by downloading the binary 7
1.1.2.2. Installing the CLI by using an RPM 7
1.1.3. Logging in to the CLI 8
1.1.4. Using the CLI 9
1.1.4.1. Creating a project 9
1.1.4.2. Creating a new app 9
1.1.4.3. Viewing pods 9
1.1.4.4. Viewing pod logs 10
1.1.4.5. Viewing the current project 10
1.1.4.6. Viewing the status for the current project 10
1.1.4.7. Listing supported API resources 10
1.1.5. Getting help 11
1.1.6. Logging out of the CLI 12
1.2. CONFIGURING THE CLI 12
1.2.1. Enabling tab completion 12
1.3. EXTENDING THE CLI WITH PLUG-INS 12
1.3.1. Writing CLI plug-ins 12
1.3.2. Installing and using CLI plug-ins 14
1.4. DEVELOPER CLI COMMANDS 14
1.4.1. Basic CLI commands 15
1.4.1.1. explain 15
1.4.1.2. login 15
1.4.1.3. new-app 15
1.4.1.4. new-project 15
1.4.1.5. project 15
1.4.1.6. projects 16
1.4.1.7. status 16
1.4.2. Build and Deploy CLI commands 16
1.4.2.1. cancel-build 16
1.4.2.2. import-image 16
1.4.2.3. new-build 16
1.4.2.4. rollback 17
1.4.2.5. rollout 17
1.4.2.6. start-build 17
1.4.2.7. tag 17
1.4.3. Application management CLI commands 18
1.4.3.1. annotate 18
1.4.3.2. apply 18
1.4.3.3. autoscale 18
1.4.3.4. create 18
1.4.3.5. delete 18
1.4.3.6. describe 19
1.4.3.7. edit 19
1.4.3.8. expose 19
1.4.3.9. get 19
1.4.3.10. label 20
1.4.3.11. scale 20
1
OpenShift Container Platform 4.3 CLI tools
1.4.3.12. secrets 20
1.4.3.13. serviceaccounts 20
1.4.3.14. set 20
1.4.4. Troubleshooting and debugging CLI commands 20
1.4.4.1. attach 20
1.4.4.2. cp 21
1.4.4.3. debug 21
1.4.4.4. exec 21
1.4.4.5. logs 21
1.4.4.6. port-forward 21
1.4.4.7. proxy 21
1.4.4.8. rsh 22
1.4.4.9. rsync 22
1.4.4.10. run 22
1.4.4.11. wait 22
1.4.5. Advanced developer CLI commands 22
1.4.5.1. api-resources 22
1.4.5.2. api-versions 23
1.4.5.3. auth 23
1.4.5.4. cluster-info 23
1.4.5.5. convert 23
1.4.5.6. extract 23
1.4.5.7. idle 24
1.4.5.8. image 24
1.4.5.9. observe 24
1.4.5.10. patch 24
1.4.5.11. policy 24
1.4.5.12. process 24
1.4.5.13. registry 25
1.4.5.14. replace 25
1.4.6. Settings CLI commands 25
1.4.6.1. completion 25
1.4.6.2. config 25
1.4.6.3. logout 25
1.4.6.4. whoami 26
1.4.7. Other developer CLI commands 26
1.4.7.1. help 26
1.4.7.2. plugin 26
1.4.7.3. version 26
1.5. ADMINISTRATOR CLI COMMANDS 26
1.5.1. Cluster management CLI commands 26
1.5.1.1. inspect 26
1.5.1.2. must-gather 27
1.5.1.3. top 27
1.5.2. Node management CLI commands 27
1.5.2.1. cordon 27
1.5.2.2. drain 27
1.5.2.3. node-logs 28
1.5.2.4. taint 28
1.5.2.5. uncordon 28
1.5.3. Security and policy CLI commands 28
1.5.3.1. certificate 28
1.5.3.2. groups 28
2
Table of Contents
1.5.3.3. new-project 28
1.5.3.4. pod-network 29
1.5.3.5. policy 29
1.5.4. Maintenance CLI commands 29
1.5.4.1. migrate 29
1.5.4.2. prune 29
1.5.5. Configuration CLI commands 29
1.5.5.1. create-api-client-config 29
1.5.5.2. create-bootstrap-policy-file 30
1.5.5.3. create-bootstrap-project-template 30
1.5.5.4. create-error-template 30
1.5.5.5. create-kubeconfig 30
1.5.5.6. create-login-template 30
1.5.5.7. create-provider-selection-template 31
1.5.6. Other Administrator CLI commands 31
1.5.6.1. build-chain 31
1.5.6.2. completion 31
1.5.6.3. config 31
1.5.6.4. release 31
1.5.6.5. verify-image-signature 32
1.6. USAGE OF OC AND KUBECTL COMMANDS 32
1.6.1. The oc binary 32
1.6.2. The kubectl binary 32
. . . . . . . . . . . 2.
CHAPTER . . OPENSHIFT
. . . . . . . . . . . . . DO
. . . . DEVELOPER
. . . . . . . . . . . . . .CLI
. . . .(ODO)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .33
..............
2.1. UNDERSTANDING OPENSHIFT DO 33
2.1.1. Key features 33
2.1.2. Core concepts 33
2.1.2.1. Officially supported languages and corresponding container images 33
2.1.2.1.1. Listing available container images 34
2.2. ODO ARCHITECTURE 35
2.2.1. Developer setup 35
2.2.2. OpenShift source-to-image 35
2.2.3. OpenShift cluster objects 35
2.2.3.1. Init Containers 35
2.2.3.1.1. copy-supervisord 35
2.2.3.1.2. copy-files-to-volume 36
2.2.3.2. Application container 36
2.2.3.3. PersistentVolume and PersistentVolumeClaim 36
2.2.3.4. emptyDir Volume 37
2.2.3.5. Service 37
2.2.4. odo push workflow 37
2.3. INSTALLING ODO 38
2.3.1. Installing odo on Linux 38
2.3.1.1. Binary installation 38
2.3.1.2. Tarball installation 38
2.3.2. Installing odo on Windows 39
2.3.2.1. Binary installation 39
Setting the PATH variable for Windows 7/8 39
Setting the PATH variable for Windows 10 39
2.3.3. Installing odo on macOS 39
2.3.3.1. Binary installation 39
2.3.3.2. Tarball installation 39
3
OpenShift Container Platform 4.3 CLI tools
4
Table of Contents
. . . . . . . . . . . 3.
CHAPTER . . HELM
. . . . . . . CLI
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .79
..............
3.1. GETTING STARTED WITH HELM 3 ON OPENSHIFT CONTAINER PLATFORM 79
3.1.1. Understanding Helm 79
3.1.1.1. Key features 79
3.1.2. Installing Helm 79
3.1.2.1. On Linux 79
3.1.2.2. On Windows 7/8 80
3.1.2.3. On Windows 10 80
3.1.2.4. On MacOS 80
3.1.3. Installing a Helm chart on an OpenShift Container Platform cluster 81
3.1.4. Creating a custom Helm chart on OpenShift Container Platform 81
5
OpenShift Container Platform 4.3 CLI tools
6
CHAPTER 1. OPENSHIFT CLI (OC)
Are restricted by bandwidth resources and can not use the web console.
You can install the CLI in order to interact with OpenShift Container Platform using a command-line
interface.
IMPORTANT
If you installed an earlier version of oc, you cannot use it to complete all of the commands
in OpenShift Container Platform 4.3. Download and install the new version of oc.
Procedure
1. From the Infrastructure Provider page on the Red Hat OpenShift Cluster Manager site, navigate
to the page for your installation type and click Download Command-line Tools.
2. Click the folder for your operating system and architecture and click the compressed file.
NOTE
$ oc <command>
For Red Hat Enterprise Linux (RHEL), you can install the OpenShift CLI (oc) as an RPM if you have an
7
OpenShift Container Platform 4.3 CLI tools
For Red Hat Enterprise Linux (RHEL), you can install the OpenShift CLI (oc) as an RPM if you have an
active OpenShift Container Platform subscription on your Red Hat account.
Prerequisites
Procedure
# subscription-manager register
# subscription-manager refresh
4. In the output for the previous command, find the pool ID for an OpenShift Container Platform
subscription and attach the subscription to the registered system:
$ oc <command>
Prerequisites
Procedure
Log in to the CLI using the oc login command and enter the required information when
prompted.
8
CHAPTER 1. OPENSHIFT CLI (OC)
$ oc login
Server [https://localhost:8443]: https://openshift.example.com:6443 1
The server uses a certificate signed by an unknown authority.
You can bypass the certificate check, but any data you send to the server could be
intercepted by others.
Use insecure connections? (y/n): y 2
You don't have any projects. You can try to create a new project, by running
oc new-project <projectname>
You can now create a project or issue other commands for managing your cluster.
$ oc new-project my-project
Now using project "my-project" on server "https://openshift.example.com:6443".
$ oc new-app https://github.com/sclorg/cakephp-ex
--> Found image 40de956 (9 days old) in imagestream "openshift/php" under tag "7.2" for "php"
...
9
OpenShift Container Platform 4.3 CLI tools
Use the oc get pods command to view the pods for the current project.
$ oc logs cakephp-ex-1-deploy
--> Scaling cakephp-ex-1 to 1
--> Success
$ oc project
Using project "my-project" on server "https://openshift.example.com:6443".
Use the oc status command to view information about the current project, such as Services,
DeploymentConfigs, and BuildConfigs.
$ oc status
In project my-project on server https://openshift.example.com:6443
Use the oc api-resources command to view the list of supported API resources on the server.
$ oc api-resources
NAME SHORTNAMES APIGROUP NAMESPACED KIND
bindings true Binding
componentstatuses cs false ComponentStatus
configmaps cm true ConfigMap
...
10
CHAPTER 1. OPENSHIFT CLI (OC)
Use oc help to get a list and description of all available CLI commands:
$ oc help
OpenShift Client
This client helps you develop, build, deploy, and run your applications on any OpenShift or
Kubernetes compatible
platform. It also includes the administrative commands for managing a cluster under the 'adm'
subcommand.
Usage:
oc [flags]
Basic Commands:
login Log in to a server
new-project Request a new project
new-app Create a new application
...
Use the --help flag to get help about a specific CLI command:
$ oc create --help
Create a resource by filename or stdin
Usage:
oc create -f FILENAME [flags]
...
Use the oc explain command to view the description and fields for a particular resource:
$ oc explain pods
KIND: Pod
VERSION: v1
DESCRIPTION:
Pod is a collection of containers that can run on a host. This resource is
created by clients and scheduled onto hosts.
FIELDS:
apiVersion <string>
11
OpenShift Container Platform 4.3 CLI tools
...
$ oc logout
Logged "user1" out on "https://openshift.example.com"
This deletes the saved authentication token from the server and removes it from your configuration file.
Prerequisites
Procedure
The following procedure enables tab completion for Bash.
You can also save the file to a local directory and source it from your .bashrc file instead.
You can write a plug-in for the OpenShift Container Platform CLI in any programming language or
12
CHAPTER 1. OPENSHIFT CLI (OC)
You can write a plug-in for the OpenShift Container Platform CLI in any programming language or
script that allows you to write command-line commands. Note that you can not use a plug-in to
overwrite an existing oc command.
IMPORTANT
OpenShift CLI plug-ins are currently a Technology Preview feature. Technology Preview
features are not supported with Red Hat production service level agreements (SLAs),
might not be functionally complete, and Red Hat does not recommend to use them for
production. These features provide early access to upcoming product features, enabling
customers to test functionality and provide feedback during the development process.
See the Red Hat Technology Preview features support scope for more information.
Procedure
This procedure creates a simple Bash plug-in that prints a message to the terminal when the oc foo
command is issued.
The file must begin with oc- or kubectl- in order to be recognized as a plug-in.
The file name determines the command that invokes the plug-in. For example, a plug-in
with the file name oc-foo-bar can be invoked by a command of oc foo bar. You can also use
underscores if you want the command to contain dashes. For example, a plug-in with the file
name oc-foo_bar can be invoked by a command of oc foo-bar.
#!/bin/bash
After you install this plug-in for the OpenShift Container Platform CLI, it can be invoked using the oc
foo command.
Additional resources
Review the Sample plug-in repository for an example of a plug-in written in Go.
13
OpenShift Container Platform 4.3 CLI tools
Review the CLI runtime repository for a set of utilities to assist in writing plug-ins in Go.
IMPORTANT
OpenShift CLI plug-ins are currently a Technology Preview feature. Technology Preview
features are not supported with Red Hat production service level agreements (SLAs),
might not be functionally complete, and Red Hat does not recommend to use them for
production. These features provide early access to upcoming product features, enabling
customers to test functionality and provide feedback during the development process.
See the Red Hat Technology Preview features support scope for more information.
Prerequisites
You must have a CLI plug-in file that begins with oc- or kubectl-.
Procedure
$ chmod +x <plugin_file>
$ oc plugin list
The following compatible plugins are available:
/usr/local/bin/<plugin_file>
If your plug-in is not listed here, verify that the file begins with oc- or kubectl-, is executable,
and is on your PATH.
$ oc ns
Note that the command to invoke the plug-in depends on the plug-in file name. For example, a
plug-in with the file name of oc-foo-bar is invoked by the oc foo bar command.
14
CHAPTER 1. OPENSHIFT CLI (OC)
1.4.1.1. explain
$ oc explain pods
1.4.1.2. login
Log in to the OpenShift Container Platform server and save login information for subsequent use.
$ oc login
$ oc login -u user1
1.4.1.3. new-app
$ oc new-app .
$ oc new-app https://github.com/sclorg/cakephp-ex
1.4.1.4. new-project
Create a new project and switch to it as the default project in your configuration.
$ oc new-project myproject
1.4.1.5. project
15
OpenShift Container Platform 4.3 CLI tools
$ oc project test-project
1.4.1.6. projects
Display information about the current active project and existing projects on the server.
$ oc projects
1.4.1.7. status
$ oc status
1.4.2.1. cancel-build
$ oc cancel-build python-1
1.4.2.2. import-image
Import the latest tag and image information from an image repository.
$ oc import-image my-ruby
1.4.2.3. new-build
$ oc new-build .
16
CHAPTER 1. OPENSHIFT CLI (OC)
$ oc new-build https://github.com/sclorg/cakephp-ex
1.4.2.4. rollback
$ oc rollback php
1.4.2.5. rollout
Start a new rollout, view its status or history, or roll back to a previous revision of your application.
Example: Start a new rollout for a DeploymentConfig with its latest state
1.4.2.6. start-build
$ oc start-build python
$ oc start-build --from-build=python-1
1.4.2.7. tag
Example: Configure the ruby image’s latest tag to refer to the image for the 2.0 tag
17
OpenShift Container Platform 4.3 CLI tools
1.4.3.1. annotate
1.4.3.2. apply
Apply a configuration to a resource by file name or standard in (stdin) in JSON or YAML format.
$ oc apply -f pod.json
1.4.3.3. autoscale
1.4.3.4. create
$ oc create -f pod.json
1.4.3.5. delete
Delete a resource.
$ oc delete pod/parksmap-katacoda-1-qfqz4
18
CHAPTER 1. OPENSHIFT CLI (OC)
1.4.3.6. describe
$ oc describe deployment/example
$ oc describe pods
1.4.3.7. edit
Edit a resource.
$ oc edit deploymentconfig/parksmap-katacoda
1.4.3.8. expose
$ oc expose service/parksmap-katacoda
1.4.3.9. get
19
OpenShift Container Platform 4.3 CLI tools
1.4.3.10. label
Example: Update the python-1-mz2rf Pod with the label status set to unhealthy
1.4.3.11. scale
1.4.3.12. secrets
Example: Allow my-pull-secret to be used as an image pull secret by the default service
account
1.4.3.13. serviceaccounts
Get a token assigned to a service account or create a new token or kubeconfig file for a service
account.
1.4.3.14. set
1.4.4.1. attach
20
CHAPTER 1. OPENSHIFT CLI (OC)
Example: Get output from the python container from Pod python-1-mz2rf
1.4.4.2. cp
Example: Copy a file from the python-1-mz2rf Pod to the local file system
$ oc cp default/python-1-mz2rf:/opt/app-root/src/README.md ~/mydirectory/.
1.4.4.3. debug
$ oc debug deploymentconfig/python
1.4.4.4. exec
Example: Execute the ls command in the python container from Pod python-1-mz2rf
1.4.4.5. logs
Retrieve the log output for a specific build, BuildConfig, DeploymentConfig, or Pod.
$ oc logs -f deploymentconfig/python
1.4.4.6. port-forward
Example: Listen on port 8888 locally and forward to port 5000 in the Pod
1.4.4.7. proxy
21
OpenShift Container Platform 4.3 CLI tools
Example: Run a proxy to the API server on port 8011 serving static content from ./local/www/
1.4.4.8. rsh
Example: Open a shell session on the first container in the python-1-mz2rf Pod
$ oc rsh python-1-mz2rf
1.4.4.9. rsync
Copy contents of a directory to or from a running Pod container. Only changed files are copied using the
rsync command from your operating system.
1.4.4.10. run
Create and run a particular image. By default, this creates a DeploymentConfig to manage the created
containers.
1.4.4.11. wait
NOTE
1.4.5.1. api-resources
Display the full list of API resources that the server supports.
22
CHAPTER 1. OPENSHIFT CLI (OC)
$ oc api-resources
1.4.5.2. api-versions
Display the full list of API versions that the server supports.
$ oc api-versions
1.4.5.3. auth
Example: Check whether the current user can read Pod logs
1.4.5.4. cluster-info
$ oc cluster-info
1.4.5.5. convert
Convert a YAML or JSON configuration file to a different API version and print to standard output
(stdout).
$ oc convert -f pod.yaml
1.4.5.6. extract
Extract the contents of a ConfigMap or secret. Each key in the ConfigMap or secret is created as a
separate file with the name of the key.
Example: Download the contents of the ruby-1-ca ConfigMap to the current directory
$ oc extract configmap/ruby-1-ca
23
OpenShift Container Platform 4.3 CLI tools
1.4.5.7. idle
Idle scalable resources. An idled Service will automatically become unidled when it receives traffic or it
can be manually unidled using the oc scale command.
$ oc idle ruby-app
1.4.5.8. image
1.4.5.9. observe
$ oc observe services
1.4.5.10. patch
Updates one or more fields of an object using strategic merge patch in JSON or YAML format.
NOTE
If you must patch a Custom Resource Definition, you must include the --type merge
option in the command.
1.4.5.11. policy
Example: Add the edit role to user1 for the current project
1.4.5.12. process
24
CHAPTER 1. OPENSHIFT CLI (OC)
1.4.5.13. registry
$ oc registry info
1.4.5.14. replace
Modify an existing object based on the contents of the specified configuration file.
$ oc replace -f pod.json
1.4.6.1. completion
$ oc completion bash
1.4.6.2. config
$ oc config view
1.4.6.3. logout
25
OpenShift Container Platform 4.3 CLI tools
$ oc logout
1.4.6.4. whoami
$ oc whoami
1.4.7.1. help
Display general help information for the CLI and a list of available commands.
$ oc help
$ oc help new-project
1.4.7.2. plugin
$ oc plugin list
1.4.7.3. version
$ oc version
For cluster administrators, the OpenShift Container Platform server version is also displayed.
1.5.1.1. inspect
NOTE
Example: Collect debugging data for the OpenShift API server cluster Operator
1.5.1.2. must-gather
Bulk collect data about the current state of your cluster to debug issues.
NOTE
$ oc adm must-gather
1.5.1.3. top
1.5.2.1. cordon
Mark a node as unschedulable. Manually marking a node as unschedulable blocks any new pods from
being scheduled on the node, but does not affect existing pods on the node.
1.5.2.2. drain
27
OpenShift Container Platform 4.3 CLI tools
1.5.2.3. node-logs
1.5.2.4. taint
Example: Remove the taints with key dedicated from node node1
1.5.2.5. uncordon
1.5.3.1. certificate
1.5.3.2. groups
1.5.3.3. new-project
28
CHAPTER 1. OPENSHIFT CLI (OC)
1.5.3.4. pod-network
1.5.3.5. policy
1.5.4.1. migrate
Migrate resources on the cluster to a new version or format depending on the subcommand used.
1.5.4.2. prune
Example: Prune older builds including those whose BuildConfigs no longer exist
1.5.5.1. create-api-client-config
29
OpenShift Container Platform 4.3 CLI tools
Create a client configuration for connecting to the server. This creates a folder containing a client
certificate, a client key, a server certificate authority, and a kubeconfig file for connecting to the master
as the provided user.
$ oc adm create-api-client-config \
--certificate-authority='/etc/origin/master/proxyca.crt' \
--client-dir='/etc/origin/master/proxy' \
--signer-cert='/etc/origin/master/proxyca.crt' \
--signer-key='/etc/origin/master/proxyca.key' \
--signer-serial='/etc/origin/master/proxyca.serial.txt' \
--user='system:proxy'
1.5.5.2. create-bootstrap-policy-file
Example: Create a file called policy.json with the default bootstrap policy
1.5.5.3. create-bootstrap-project-template
1.5.5.4. create-error-template
$ oc adm create-error-template
1.5.5.5. create-kubeconfig
$ oc adm create-kubeconfig \
--client-certificate=/path/to/client.crt \
--client-key=/path/to/client.key \
--certificate-authority=/path/to/ca.crt
1.5.5.6. create-login-template
30
CHAPTER 1. OPENSHIFT CLI (OC)
$ oc adm create-login-template
1.5.5.7. create-provider-selection-template
$ oc adm create-provider-selection-template
1.5.6.1. build-chain
1.5.6.2. completion
Output shell completion code for the oc adm commands for the specified shell.
1.5.6.3. config
Manage the client configuration files. This command has the same behavior as the oc config command.
1.5.6.4. release
Manage various aspects of the OpenShift Container Platform release process, such as viewing
information about a release or inspecting the contents of a release.
31
OpenShift Container Platform 4.3 CLI tools
1.5.6.5. verify-image-signature
Verify the image signature of an image imported to the internal registry using the local public GPG key.
$ oc adm verify-image-signature \
sha256:2bba968aedb7dd2aafe5fa8c7453f5ac36a0b9639f1bf5b03f95de325238b288 \
--expected-identity 172.30.1.1:5000/openshift/nodejs:latest \
--public-key /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release \
--save
Authentication
The oc binary offers a built-in login command that allows authentication and enables you to
work with OpenShift Container Platform projects, which map Kubernetes namespaces to
authenticated users. See Understanding authentication for more information.
Additional commands
The additional command oc new-app, for example, makes it easier to get new applications
started using existing source code or pre-built images. Similarly, the additional command oc
new-project makes it easier to start a project that you can switch to as your default.
32
CHAPTER 2. OPENSHIFT DO DEVELOPER CLI (ODO)
Existing tools such as oc are more 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.
Simple syntax and design centered around concepts familiar to developers, such as projects,
applications, and components.
Completely client based. No server is required within the OpenShift Container Platform cluster
for deployment.
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 OpenShift Container Platform cluster.
33
OpenShift Container Platform 4.3 CLI tools
rhoar-nodejs/nodejs-8 NPM
bucharestgold/centos7-s2i- NPM
nodejs
rhscl/nodejs-8-rhel7 NPM
rhscl/nodejs-10-rhel7 NPM
NOTE
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:
2. List the available odo supported and unsupported components and corresponding container
images:
The TAGS column represents the available image versions, for example, 10 represents the
rhoar-nodejs/nodejs-10 container image.
34
CHAPTER 2. OPENSHIFT DO DEVELOPER CLI (ODO)
odo works on Windows, macOS, and Linux operating systems and from any terminal. odo provides
autocompletion for bash and zsh command line shells.
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.
2.2.3.1.1. copy-supervisord
The copy-supervisord Init container copies necessary files onto an emptyDir Volume. The main
application container utilizes these files from 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 the SupervisorD 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.
35
OpenShift Container Platform 4.3 CLI tools
Configuration files:
supervisor.conf is the configuration file necessary for the SupervisorD daemon to start.
Scripts:
Run is an OpenShift S2I concept of executing the assembled source code. The run script
executes the assembled code created by the assemble-and-restart script.
s2i-setup is a script that creates files and directories which are necessary for the
assemble-and-restart and run scripts to execute successfully. The script is executed
whenever the application container starts.
Directories:
language-scripts: Openshift S2I allows custom assemble and run scripts. A few language
specific custom scripts are present in the language-scripts directory. The custom scripts
provide additional configuration to make odo debug work.
The emtpyDir 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
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 PersistentVolume on /opt/app-root the data in this directory is lost when
PersistentVolumeClaim is mounted at the same location.
The PVC is mounted at the /mnt mount point inside the Init container.
Application container is the main container inside of which the user-source code executes.
go-init is executed as the first process inside the application container. The go-init process then starts
the SupervisorD daemon.
SupervisorD executes and monitores the user assembled source code. If the user process crashes,
SupervisorD restarts it.
36
CHAPTER 2. OPENSHIFT DO DEVELOPER CLI (ODO)
The copy-files-to-volume Init container copies necessary files onto the PersistentVolume. The main
application container utilizes these files at runtime for execution.
copy-files-to-volume /mnt
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.
copy-supervisord /opt/odo
2.2.3.5. Service
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.
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.
1. Creating resources
If not already created, odo push creates the following OpenShift Container Platform resources:
The application container starts. The first process in the application container is the go-
init process with PID=1.
37
OpenShift Container Platform 4.3 CLI tools
NOTE
The user application code has not been copied into the application
container yet, so the SupervisorD daemon does not execute the run
script.
Service
Secrets
PersistentVolumeClaim
2. 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.
3. Pushing code
Local code is copied into the application container, usually under /tmp/src.
4. Executing assemble-and-restart
On a successful copy of the source code, the assemble-and-restart script is executed inside
the running application container.
NOTE
# curl -L https://mirror.openshift.com/pub/openshift-v4/clients/odo/latest/odo-linux-amd64 -o
/usr/local/bin/odo
# chmod +x /usr/local/bin/odo
38
CHAPTER 2. OPENSHIFT DO DEVELOPER CLI (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'
# chmod +x /usr/local/bin/odo
4. From the menu on the left, select the Advanced systems settings and click the Environment
Variables button at the bottom.
6. Click New and type C:\go-bin into the field or click Browse and select the directory, and click
OK.
4. Click New and type C:\go-bin into the field or click Browse and select the directory, and click
OK.
# curl -L https://mirror.openshift.com/pub/openshift-v4/clients/odo/latest/odo-darwin-amd64 -o
/usr/local/bin/odo
# chmod +x /usr/local/bin/odo
39
OpenShift Container Platform 4.3 CLI tools
# 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'
# chmod +x /usr/local/bin/odo
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
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.
Prerequisites
Access to an OpenShift Container Platform restricted cluster with a configured internal registry
or a mirror registry.
Depending on your operating system, you can push the odo init image to a cluster with a mirror registry
as follows:
Procedure
1. Use base64 to encode the root certification authority (CA) content of your mirror registry:
40
CHAPTER 2. OPENSHIFT DO DEVELOPER CLI (ODO)
3. 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>
5. Override the default odo init image path by setting the ODO_BOOTSTRAPPER_IMAGE
environment variable:
$ export ODO_BOOTSTRAPPER_IMAGE=<mirror-registry>:5000/openshiftdo/odo-init-
image-rhel7:<tag>
Procedure
1. Use base64 to encode the root certification authority (CA) content of your mirror registry:
4. Override the default odo init image path by setting the ODO_BOOTSTRAPPER_IMAGE
environment variable:
$ export ODO_BOOTSTRAPPER_IMAGE=<mirror-registry>:5000/openshiftdo/odo-init-
image-rhel7:<tag>
41
OpenShift Container Platform 4.3 CLI tools
Procedure
1. Use base64 to encode the root certification authority (CA) content of your mirror registry:
3. Trust a CA in your client platform and log into the OpenShift Container Platform mirror registry:
5. Override the default odo init image path by setting the ODO_BOOTSTRAPPER_IMAGE
environment variable:
PS C:\> $env:ODO_BOOTSTRAPPER_IMAGE="<mirror-registry>:5000/openshiftdo/odo-
init-image-rhel7:<tag>"
If your cluster allows images to be pushed to the internal registry directly, push the odo init image to the
registry as follows:
Procedure
42
CHAPTER 2. OPENSHIFT DO DEVELOPER CLI (ODO)
metadata:
[...]
type: kubernetes.io/tls
3. Use base64 to encode the root certification authority (CA) content of your mirror registry:
7. Override the default odo init image path by setting the ODO_BOOTSTRAPPER_IMAGE
environment variable:
$ export ODO_BOOTSTRAPPER_IMAGE=<registry_path>/openshiftdo/odo-init-image-
rhel7:1.0.1
Procedure
43
OpenShift Container Platform 4.3 CLI tools
kind: Secret
metadata:
[...]
type: kubernetes.io/tls
3. Use base64 to encode the root certification authority (CA) content of your mirror registry:
7. Override the default odo init image path by setting the ODO_BOOTSTRAPPER_IMAGE
environment variable:
$ export ODO_BOOTSTRAPPER_IMAGE=<registry_path>/openshiftdo/odo-init-image-
rhel7:1.0.1
Procedure
44
CHAPTER 2. OPENSHIFT DO DEVELOPER CLI (ODO)
kind: Secret
metadata:
[...]
type: kubernetes.io/tls
3. Use base64 to encode the root certification authority (CA) content of your mirror registry:
7. Override the default odo init image path by setting the ODO_BOOTSTRAPPER_IMAGE
environment variable:
PS C:\> $env:ODO_BOOTSTRAPPER_IMAGE="<registry_path>/openshiftdo/odo-init-
image-rhel7:<tag>"
Prerequisites
Access to an OpenShift Container Platform restricted cluster with a configured internal registry
or a mirror registry.
45
OpenShift Container Platform 4.3 CLI tools
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
10
tagged from <mirror-registry>:<port>/rhoar-nodejs/nodejs-10
prefer registry pullthrough when referencing this tag
Build and run Node.js 10 applications on RHEL 7. For more information about using this
builder image, including OpenShift considerations, see https://github.com/nodeshift/centos7-
s2i-nodejs.
Tags: builder, nodejs, hidden
Example Repo: https://github.com/sclorg/nodejs-ex.git
10-SCL (latest)
tagged from <mirror-registry>:<port>/rhscl/nodejs-10-rhel7
prefer registry pullthrough when referencing this tag
Build and run Node.js 10 applications on RHEL 7. For more information about using this
builder image, including OpenShift considerations, see https://github.com/nodeshift/centos7-
s2i-nodejs.
Tags: builder, nodejs
Example Repo: https://github.com/sclorg/nodejs-ex.git
[...]
46
CHAPTER 2. OPENSHIFT DO DEVELOPER CLI (ODO)
You must periodically re-import the image. The --scheduled flag enables automatic re-import
of the image.
4. Verify that the images with the given tag have been imported:
Build and run Node.js 10 applications on RHEL 7. For more information about using this
builder image, including OpenShift considerations, see https://github.com/nodeshift/centos7-
s2i-nodejs.
Tags: builder, nodejs
Example Repo: https://github.com/sclorg/nodejs-ex.git
* <mirror-registry>:<port>/rhscl/nodejs-10-
rhel7@sha256:d669ecbc11ac88293de50219dae8619832c6a0f5b04883b480e073590fab7c54
3 minutes ago
[...]
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
Procedure
$ cd <directory-name>
47
OpenShift Container Platform 4.3 CLI tools
NOTE
By default, the latest image is used. You can also explicitly specify an image
version by using odo create openshift/nodejs:8.
$ odo push
4. Create a URL and add an entry in the local configuration file as follows:
$ odo push
6. List the URLs to check the desired URL for the component.
$ curl <URL>
Prerequisites
odo is installed.
You have a running OpenShift Container Platform cluster. You can use CodeReady Containers
(CRC) to deploy a local OpenShift Container Platform cluster quickly.
Procedure
$ mkdir my_components
$ cd my_components
48
CHAPTER 2. OPENSHIFT DO DEVELOPER CLI (ODO)
Procedure
$ cd <directory-name>
NOTE
By default, the latest image is used. You can also explicitly specify an image
version by using odo create openshift/nodejs:8.
$ odo push
4. Create a URL and add an entry in the local configuration file as follows:
$ odo push
6. List the URLs to check the desired URL for the component.
$ curl <URL>
You can modify your application code and have the changes applied to your application on OpenShift
Container Platform.
1. Edit one of the layout files within the Node.js directory with your preferred text editor.
$ odo push
Procedure
The following example demonstrates the successful import and use of the redhat-openjdk-18 image:
Prerequisites
Procedure
$ oc import-image openjdk18 \
--from=registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift \
--confirm
Prerequisites
Procedure
IMPORTANT
Deleting an application will delete all components associated with the application.
Procedure
2. List the components associated with the applications. These components will be deleted with
the application:
4. Confirm the deletion with Y. You can suppress the confirmation prompt using the -f flag.
51
OpenShift Container Platform 4.3 CLI tools
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.
Prerequisites
odo is installed.
You have a running OpenShift Container Platform cluster. Developers can use CodeReady
Containers (CRC) to deploy a local OpenShift Container Platform cluster quickly.
Maven is installed.
Procedure
$ mkdir my_components
$ cd my_components
Procedure
$ oc import-image openjdk18 \
--from=registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift --confirm
52
CHAPTER 2. OPENSHIFT DO DEVELOPER CLI (ODO)
4. Change directory to the back-end source directory and check that you have the correct files in
the directory:
$ cd <directory-name>
$ ls
debug.sh pom.xml src
5. Build the back-end source files with Maven to create a JAR file:
$ mvn package
...
[INFO] --------------------------------------
[INFO] BUILD SUCCESS
[INFO] --------------------------------------
[INFO] Total time: 2.635 s
[INFO] Finished at: 2019-09-30T16:11:11-04:00
[INFO] Final Memory: 30M/91M
[INFO] --------------------------------------
Now the configuration file config.yaml is in the local directory of the back-end component that
contains information about the component for deployment.
7. Check the configuration settings of the back-end component in the config.yaml file using:
53
OpenShift Container Platform 4.3 CLI tools
DebugPort
Ignore
MinCPU
MaxCPU
$ odo push
Validation
✓ Checking component [6ms]
Configuration changes
✓ Initializing component
✓ Creating component [124ms]
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 the backend component.
9. Validate:
odo log -f
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)
$ odo list
APP NAME TYPE SOURCE STATE
app backend openjdk18 file://target/wildwest-1.0.jar Pushed
Procedure
$ cd <directory-name>
2. List the contents of the directory to see that the front end is a Node.js application.
$ ls
assets bin index.html kwww-frontend.iml package.json package-lock.json playfield.png
README.md server.js
NOTE
54
CHAPTER 2. OPENSHIFT DO DEVELOPER CLI (ODO)
NOTE
$ odo push
Validation
✓ Checking component [8ms]
Configuration changes
✓ Initializing component
✓ Creating component [83ms]
Procedure
$ odo list
APP NAME TYPE SOURCE STATE
app backend openjdk18 file://target/wildwest-1.0.jar Pushed
app frontend nodejs file://./ Pushed
55
OpenShift Container Platform 4.3 CLI tools
Procedure
$ cd frontend
$ odo url create frontend --port 8080
✓ URL frontend created for component: frontend
$ odo push
Validation
✓ Checking component [21ms]
Configuration changes
✓ Retrieving component data [35ms]
✓ Applying configuration [29ms]
NOTE
To resolve this error, add permissions for the Service Account role:
Procedure
56
CHAPTER 2. OPENSHIFT DO DEVELOPER CLI (ODO)
$ cd ~/frontend
$ odo watch
3. Edit the index.html file to change the displayed name for the game.
NOTE
odo pushes the changes to the front-end component and prints its status to the terminal:
4. Refresh the application page in the web browser. The new name is now displayed.
IMPORTANT
Deleting an application will delete all components associated with the application.
Procedure
2. List the components associated with the applications. These components will be deleted with
the application:
57
OpenShift Container Platform 4.3 CLI tools
4. Confirm the deletion with Y. You can suppress the confirmation prompt using the -f flag.
Prerequisites
odo is installed.
oc client is installed.
You have a running OpenShift Container Platform cluster. Developers can use CodeReady
Containers (CRC) to deploy a local OpenShift Container Platform cluster quickly.
Procedure
$ mkdir my_components
$ cd my_components
Procedure
$ cd <directory-name>
2. List the contents of the directory to see that the front end is a Node.js application.
58
CHAPTER 2. OPENSHIFT DO DEVELOPER CLI (ODO)
$ ls
assets bin index.html kwww-frontend.iml package.json package-lock.json playfield.png
README.md server.js
NOTE
$ odo push
Validation
✓ Checking component [7ms]
Configuration changes
✓ Initializing component
✓ Creating component [134ms]
Procedure
59
OpenShift Container Platform 4.3 CLI tools
NOTE
2. Choose the mongodb-persistent type of service and see the required parameters:
60
CHAPTER 2. OPENSHIFT DO DEVELOPER CLI (ODO)
| (default: '1Gi')
----------------- | -----------------
Optional Params | MONGODB_ADMIN_PASSWORD,
| NAMESPACE, MONGODB_PASSWORD,
| MONGODB_USER
3. Pass the required parameters as flags and wait for the deployment of the database:
2. See the environment variables of the application and the database in the Pod:
$ oc get pods
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
$ oc rsh nodejs-nodejs-ex-mhbb-app-4-vkn9l
sh-4.3$ env
uri=mongodb://172.30.126.3:27017
password=dHIOpYneSkX3rTLn
database_name=sampledb
username=user43U
admin_password=NCn41tqmx7RIqmfv
sh-4.3$
3. Open the URL in the browser and notice the database configuration in the bottom right:
Request information
Page view count: 24
DB Connection Info:
Type: MongoDB
URL: mongodb://172.30.126.3:27017/sampledb
61
OpenShift Container Platform 4.3 CLI tools
IMPORTANT
Deleting an application will delete all components associated with the application.
Procedure
2. List the components associated with the applications. These components will be deleted with
the application:
4. Confirm the deletion with Y. You can suppress the confirmation prompt using the -f flag.
NOTE
For odo 1.1.0 Java and Node.js are the officialy supported component types. Run odo
catalog list components to verify the officially supported component types.
62
CHAPTER 2. OPENSHIFT DO DEVELOPER CLI (ODO)
In order to access the component over the web, create a URL using odo url create.
2.8.1.1. httpd
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.
2.8.1.2. java
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.
2.8.1.3. nodejs
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 .
2.8.1.4. perl
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.
2.8.1.5. php
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.
2.8.1.6. python
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.
63
OpenShift Container Platform 4.3 CLI tools
2.8.1.7. ruby
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 .
2.8.1.8. wildfly
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.
2.8.2.1. java
2.8.2.2. wildfly
IMPORTANT
For more information about the support scope of Red Hat Technology Preview features,
see https://access.redhat.com/support/offerings/techpreview/.
64
CHAPTER 2. OPENSHIFT DO DEVELOPER CLI (ODO)
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).
Procedure
1. After an application is deployed, start the port forwarding for your component to debug the
application:
2. Attach the debugger bundled in your IDE to the component. Instructions vary depending on your
IDE.
Procedure
To set a remote port on which the debugging agent should run, run:
NOTE
You must redeploy your component for this value to be reflected on the
component.
NOTE
The local port value does not persist. You must provide it every time you need to
change the port.
65
OpenShift Container Platform 4.3 CLI tools
Procedure
NOTE
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
1. Run:
$ odo --complete
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:
1. Run:
$ odo --uncomplete
NOTE
66
CHAPTER 2. OPENSHIFT DO DEVELOPER CLI (ODO)
NOTE
Re-enable command completion if you either rename the odo executable or move it to a
different directory.
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/
2.12.1.1. app
2.12.1.2. catalog
67
OpenShift Container Platform 4.3 CLI tools
# Describe a service
odo catalog describe service mysql-persistent
2.12.1.3. component
2.12.1.4. config
68
CHAPTER 2. OPENSHIFT DO DEVELOPER CLI (ODO)
Ref Git ref to use for creating component from git source
69
OpenShift Container Platform 4.3 CLI tools
2.12.1.5. create
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.
# Create new Node.js component named 'frontend' with the source in './frontend' directory
odo create nodejs frontend --context ./frontend
# Create new Wildfly component with binary named sample.war in './downloads' directory
odo create wildfly wildfly --binary ./downloads/sample.war
# Create new Node.js component with source from remote git repository
odo create nodejs --git https://github.com/openshift/nodejs-ex.git
# Create new Node.js git component while specifying a branch, tag or commit ref
odo create nodejs --git https://github.com/openshift/nodejs-ex.git --ref master
# Create new Node.js component with the source in current directory and ports 8080-tcp,8100-tcp
and 9100-udp exposed
odo create nodejs --port 8080,8100/tcp,9100/udp
# Create new Node.js component with the source in current directory and env variables key=value
and key1=value1 exposed
70
CHAPTER 2. OPENSHIFT DO DEVELOPER CLI (ODO)
2.12.1.6. delete
2.12.1.7. describe
2.12.1.8. link
# Link current component to the 'backend' component (backend must have a single exposed port)
odo link backend
# Link current component to port 8080 of the 'backend' component (backend must have port 8080
exposed)
odo link backend --port 8080
71
OpenShift Container Platform 4.3 CLI tools
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.12.1.9. list
2.12.1.10. log
2.12.1.11. login
# Log in interactively
odo login
# Log in to the given server with the given certificate authority file
odo login localhost:8443 --certificate-authority=/path/to/cert.crt
# Log in to the given server with the given credentials (basic auth)
odo login localhost:8443 --username=myuser --password=mypass
2.12.1.12. logout
# Log out
odo logout
2.12.1.13. preference
Modify odo specific configuration settings within the global preference file.
72
CHAPTER 2. OPENSHIFT DO DEVELOPER CLI (ODO)
NOTE
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"
2.12.1.14. project
# Delete a project
odo project delete myproject
73
OpenShift Container Platform 4.3 CLI tools
2.12.1.15. push
2.12.1.16. service
# Create new postgresql service from service catalog using dev plan and name my-postgresql-db.
odo service create dh-postgresql-apb my-postgresql-db --plan dev -p postgresql_user=luke -p
postgresql_password=secret
2.12.1.17. storage
2.12.1.18. unlink
For this command to be successful, the service or component must have been linked prior to the
invocation using odo link.
74
CHAPTER 2. OPENSHIFT DO DEVELOPER CLI (ODO)
# Unlink the 'backend' component from the current component (backend must have a single
exposed port)
odo unlink backend
2.12.1.19. update
# Change the source code path of a currently active component to local (use the current directory as
a source)
odo update --local
# Change the source code path of the frontend component to local with source in ./frontend directory
odo update frontend --local ./frontend
# Change the source code path of the component named node-ex to git
odo update node-ex --git https://github.com/openshift/nodejs-ex.git
# Change the source code path of the component named wildfly to a binary named sample.war in
./downloads directory
odo update wildfly --binary ./downloads/sample.war
2.12.1.20. url
# Create a URL with a specific name by automatic detection of port (only for components which
75
OpenShift Container Platform 4.3 CLI tools
# Create a URL with a specific name and port for component frontend
odo url create example --port 8080 --component frontend
# Create a URL in the configuration and apply the changes to the cluster
odo url create --now
The URLs that are generated using this command can be used to access the deployed components from
outside the cluster.
2.12.1.21. utils
2.12.1.22. version
2.12.1.23. watch
odo starts watching for changes and updates the component upon a change automatically.
76
CHAPTER 2. OPENSHIFT DO DEVELOPER CLI (ODO)
odo catalog has been improved to provide more useful output information.
Information prompts have been added to the odo service create command, providing possible
next step scenarios.
Use odo preference set PushTimeout <seconds> to specify the number of seconds odo
waits for a component Pod to be deployed before the command fails.
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, encountered a bug, or have suggestions for improving the functionality of odo, file
an issue in Bugzilla. Choose the Red Hat odo for OpenShift Container Platformproduct type.
Bug 1760578 The odo watch command does not fail with an error message for Git-based
components, but it should.
Bug 1760583 The odo config unset command does not unset an environment variable, but
says it did.
Bug 1760585 The odo delete --all command deletes the $HOME/.odo folder when run from
$HOME.
Bug 1760589 Autocompletion does not work for the --context flag in odo push.
Bug 1761442 The component create command fails when used with the --context flag and --
binary flag if the binary is located in a temporary folder.
Bug 1783179 When you set an environment variable, create a URL route, and then change the
source code of the component, the URL route becomes inaccessible.
77
OpenShift Container Platform 4.3 CLI tools
Bug 1760575 The odo app delete command removes application components but not Services.
Bug 1760577 The odo push command does not delete the OpenShift objects when the
component name is changed.
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.
odo debug is a feature that allows users to attach a local debugger to a component running in the Pod
on OpenShift Container Platform.
IMPORTANT
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/.
Use the odo config set DebugPort 9292 command to specify the remote port that the
debugging agent should run on.
Use the odo debug port-forward --local-port 9292 command to specify the local port for port
forwarding.
78
CHAPTER 3. HELM CLI
IMPORTANT
For more information about the support scope of Red Hat Technology Preview features,
see https://access.redhat.com/support/offerings/techpreview/.
Create your own charts with OpenShift Container Platform or Kubernetes resources.
Prerequisites
3.1.2.1. On Linux
# curl -L https://mirror.openshift.com/pub/openshift-v4/clients/helm/latest/helm-linux-amd64 -
o /usr/local/bin/helm
# chmod +x /usr/local/bin/helm
79
OpenShift Container Platform 4.3 CLI tools
$ helm version
version.BuildInfo{Version:"v3.0",
GitCommit:"b31719aab7963acf4887a1c1e6d5e53378e34d93", GitTreeState:"clean",
GoVersion:"go1.13.4"}
1. Download the latest .exe file and put in a directory of your preference.
4. From the menu on the left, select Advanced systems settings and click Environment
Variables at the bottom.
6. Click New and type the path to the folder with the .exe file into the field or click Browse and
select the directory, and click OK.
3.1.2.3. On Windows 10
1. Download the latest .exe file and put in a directory of your preference.
5. Click New and type the path to the directory with the exe file into the field or click Browse and
select the directory, and click OK.
3.1.2.4. On MacOS
# curl -L https://mirror.openshift.com/pub/openshift-v4/clients/helm/latest/helm-darwin-amd64
-o /usr/local/bin/helm
# chmod +x /usr/local/bin/helm
$ helm version
version.BuildInfo{Version:"v3.0",
GitCommit:"b31719aab7963acf4887a1c1e6d5e53378e34d93", GitTreeState:"clean",
GoVersion:"go1.13.4"}
80
CHAPTER 3. HELM CLI
Prerequisites
You have a running OpenShift Container Platform cluster and you have logged into it.
Procedure
$ oc new-project mysql
$ helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
example-mysql mysql 1 2019-12-05 15:06:51.379134163 -0500 EST deployed mysql-1.5.0
5.7.27
Procedure
$ oc new-project nodejs-ex-k
2. Download an example Node.js chart that contains OpenShift Container Platform objects:
$ cd redhat-helm-charts/alpha/nodejs-ex-k/
81
OpenShift Container Platform 4.3 CLI tools
apiVersion: v2 1
name: nodejs-ex-k 2
description: A Helm chart for OpenShift 3
icon: https://static.redhat.com/libs/redhat/brand-assets/latest/corp/logo.svg 4
1 The chart API version. It should be v2 for Helm charts that require at least Helm 3.
$ helm lint
[INFO] Chart.yaml: icon is recommended
$ cd ..
$ helm install nodejs-chart nodejs-ex-k
$ helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
nodejs-chart nodejs-ex-k 1 2019-12-05 15:06:51.379134163 -0500 EST deployed nodejs-
0.1.0 1.16.0
82