2.14. odo CLI 参考指南
2.14.1. 基本 odo CLI 命令
2.14.1.1. app
执行与 OpenShift Container Platform 项目相关的应用程序操作。
使用 app 的示例
# Delete the application odo app delete myapp # Describe 'webapp' application, odo app describe webapp # List all applications in the current project odo app list # List all applications in the specified project odo app list --project myproject
2.14.1.2. catalog
执行与目录相关的操作。
使用 catalog 的示例
# Get the supported components odo catalog list components # Get the supported services from service catalog odo catalog list services # Search for a component odo catalog search component python # Search for a service odo catalog search service mysql # Describe a service odo catalog describe service mysql-persistent
2.14.1.3. component
管理应用程序的组件。
使用 component 的示例
# 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
在 config
文件中修改与 odo
相关的设置。
使用 config 的示例
# For viewing the current local configuration odo config view # Set a configuration value in the local configuration odo config set Type java odo config set Name test odo config set MinMemory 50M odo config set MaxMemory 500M odo config set Memory 250M odo config set Ignore false odo config set MinCPU 0.5 odo config set MaxCPU 2 odo config set CPU 1 # Set an environment variable in the local configuration odo config set --env KAFKA_HOST=kafka --env KAFKA_PORT=6639 # Create a local configuration and apply the changes to the cluster immediately odo config set --now # Unset a configuration value in the local config odo config unset Type odo config unset Name odo config unset MinMemory odo config unset MaxMemory odo config unset Memory odo config unset Ignore odo config unset MinCPU odo config unset MaxCPU odo config unset CPU # Unset an env variable in the local config odo config unset --env KAFKA_HOST --env KAFKA_PORT
Application | Application 是应用程序名称,组件需要作为此应用程序的一部分 |
CPU | 组件可消耗的最少和最多 CPU |
Ignore | 进行 push 和 watch 时使用 .odoignore 文件 |
Application(应用程序) | 组件需要成为其一部分的应用程序名称 |
CPU | 组件可消耗的最少和最多 CPU |
Ignore |
进行 push 和 watch 时是否使用 |
MaxCPU | 组件可消耗的最多 CPU |
MaxMemory | 组件可消耗的最大内存 |
Memory | 组件可消耗的最小和最大内存 |
MinCPU | 组件可消耗的最小 CPU |
MinMemory | 组件提供的最小内存 |
名称 | 组件的名称 |
Ports | 要在组件中打开的端口 |
Project(项目) | 组件所属项目的名称 |
Ref | 用于从 git 源创建组件的 git ref |
SourceLocation | 该路径表示二进制文件或者 git 源的位置 |
SourceType | 组件源的类型 - git/binary/local |
存储 | 组件的存储 |
类型 | 组件的类型 |
URL | 访问该组件的 URL |
2.14.1.5. create
创建描述在 OpenShift Container Platform 中部署的组件的配置。如果没有提供组件名称,它会被自动生成。
默认情况下,构建者镜像是从当前命名空间中使用的。如果要明确指定一个命名空间,使用:odo create namespace/name:version
。如果没有指定版本,则默认为 latest
。
使用 odo catalog list
查看可以部署的完整组件类型列表。
使用 create 的示例
# Create new Node.js component with the source in current directory. odo create nodejs # Create new Node.js component and push it to the cluster immediately. odo create nodejs --now # A specific image version may also be specified odo create nodejs:latest # Create new Node.js component named 'frontend' with the source in './frontend' directory odo create nodejs frontend --context ./frontend # Create a new Node.js component of version 6 from the 'openshift' namespace odo create openshift/nodejs:6 --context /nodejs-ex # 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 git component while specifying a tag odo create nodejs --git https://github.com/openshift/nodejs-ex.git --ref v1.0.1 # 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 odo create nodejs --env key=value,key1=value1 # For more examples, visit: https://github.com/openshift/odo/blob/master/docs/examples.adoc odo create python --git https://github.com/openshift/django-ex.git # Passing memory limits odo create nodejs --memory 150Mi odo create nodejs --min-memory 150Mi --max-memory 300 Mi # Passing cpu limits odo create nodejs --cpu 2 odo create nodejs --min-cpu 200m --max-cpu 2
2.14.1.6. debug
调试组件。
# Displaying information about the state of debugging odo debug info # Starting the port forwarding for a component to debug the application odo debug port-forward # Setting a local port to port forward odo debug port-forward --local-port 9292
2.14.1.7. delete
删除一个现有组件。
使用 delete 的示例
# Delete component named 'frontend'. odo delete frontend odo delete frontend --all-apps
2.14.1.8. describe
描述指定组件。
使用 describe 的示例
# Describe nodejs component odo describe nodejs
2.14.1.9. link
将组件链接到服务或组件。
使用 link 的示例
# Link the current component to the 'my-postgresql' service odo link my-postgresql # Link component 'nodejs' to the 'my-postgresql' service odo link my-postgresql --component nodejs # Link current component to the 'backend' component (backend must have a single exposed port) odo link backend # Link component 'nodejs' to the 'backend' component odo link backend --component nodejs # Link current component to port 8080 of the 'backend' component (backend must have port 8080 exposed) odo link backend --port 8080
link 会把适当的 secret 添加到源组件的环境中。然后源组件就可以使用 secret 条目作为环境变量。如果没有提供源组件,则会假定当前活跃的组件。
2.14.1.10. list
列出当前应用程序中的所有组件。
使用 list 的示例
# List all components in the application odo list
2.14.1.11. log
获取指定组件的日志。
使用 log 的示例
# Get the logs for the nodejs component odo log nodejs
2.14.1.12. login
登录到集群。
使用 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 # Log in to the given server with the given credentials (token) odo login localhost:8443 --token=xxxxxxxxxxxxxxxxxxxxxxx
2.14.1.13. logout
登出当前 OpenShift Container Platform 会话。
使用 logout 的示例
# Log out odo logout
2.14.1.14. preference
在全局首选项文件中修改与 odo
相关的配置设置。
使用 preference 的示例
# For viewing the current preferences odo preference view # Set a preference value in the global preference odo preference set UpdateNotification false odo preference set NamePrefix "app" odo preference set Timeout 20 # Enable experimental mode odo preference set experimental true # Unset a preference value in the global preference odo preference unset UpdateNotification odo preference unset NamePrefix odo preference unset Timeout # Disable experimental mode odo preference set experimental false
默认情况下,全局首选项文件的路径为 ~/.odo/preferece.yaml
,它被存储在环境变量 GLOBALODOCONFIG
中。您可以通过为环境变量设置一个新的值来指定一个新的自定义的首选项路径,例如: GLOBALODOCONFIG="new_path/preference.yaml"
NamePrefix | 默认前缀是当前目录的名称。使用这个值设置默认名称前缀。 |
Timeout | OpenShift Container Platform 服务器的连接检查超时时间(以秒为单位)。 |
UpdateNotification | 控制是否显示更新通知。 |
2.14.1.15. project
执行项目操作。
使用 project 示例
# Set the active project odo project set # Create a new project odo project create myproject # List all the projects odo project list # Delete a project odo project delete myproject # Get the active project odo project get
2.14.1.16. push
将源代码推送到组件中。
使用 push 的示例
# Push source code to the current component odo push # Push data to the current component from the original source. odo push # Push source code in ~/mycode to component called my-component odo push my-component --context ~/mycode
2.14.1.17. service
执行服务目录操作。
使用 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 # Delete the service named 'mysql-persistent' odo service delete mysql-persistent # List all services in the application odo service list
2.14.1.18. storage
执行存储操作。
使用 storage 的示例
# Create storage of size 1Gb to a component odo storage create mystorage --path=/opt/app-root/src/storage/ --size=1Gi # Delete storage mystorage from the currently active component odo storage delete mystorage # Delete storage mystorage from component 'mongodb' odo storage delete mystorage --component mongodb # List all storage attached or mounted to the current component and # all unattached or unmounted storage in the current application odo storage list # Set the `-o json` flag to get a JSON formatted output odo storage list -o json
2.14.1.19. unlink
取消链接组件或服务。
要使这个命令成功,服务或组件需要在使用 odo link
前已被链接。
使用 unlink 的示例
# Unlink the 'my-postgresql' service from the current component odo unlink my-postgresql # Unlink the 'my-postgresql' service from the 'nodejs' component odo unlink my-postgresql --component nodejs # Unlink the 'backend' component from the current component (backend must have a single exposed port) odo unlink backend # Unlink the 'backend' service from the 'nodejs' component odo unlink backend --component nodejs # Unlink the backend's 8080 port from the current component odo unlink backend --port 8080
2.14.1.20. update
更新组件的源代码路径
使用 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 a currently active component to git odo update --git https://github.com/openshift/nodejs-ex.git # 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.14.1.21. url
向外界开放一个组件。
使用 url 的示例
# Create a URL for the current component with a specific port odo url create --port 8080 # Create a URL with a specific name and port odo url create example --port 8080 # Create a URL with a specific name by automatic detection of port (only for components which expose only one service port) odo url create example # Create a URL with a specific name and port for component frontend odo url create example --port 8080 --component frontend # Delete a URL to a component odo url delete myurl # List the available URLs odo url list # Create a URL in the configuration and apply the changes to the cluster odo url create --now # Create an HTTPS URL odo url create --secure
使用这个命令生成的 URL 可以从集群外访问部署的组件。
2.14.1.22. utils
终端命令和修改 odo 配置的工具。
使用 utils 的示例
# Bash terminal PS1 support source <(odo utils terminal bash) # Zsh terminal PS1 support source <(odo utils terminal zsh)
2.14.1.23. version
打印客户端版本信息。
使用 version 的示例
# Print the client version of odo odo version
2.14.1.24. watch
odo 启动更改监控,并在出现更改时自动更新组件。
使用 watch 的示例
# Watch for changes in directory for current component odo watch # Watch for changes in directory for component called frontend odo watch frontend