CLI 工具

OpenShift Container Platform 4.2

如何使用 OpenShift Container Platform 的命令行工具

Red Hat OpenShift Documentation Team

摘要

本文档提供有关安装、配置和使用 OpenShift Container Platform 命令行工具的信息。它还包含 CLI 命令的参考信息,以及如何使用它们的示例。

第 1 章 OpenShift CLI (oc)

1.1. CLI 入门

1.1.1. 关于 CLI

使用 OpenShift Container Platform 命令行界面(CLI),您可以通过终端创建应用程序并管理OpenShift Container Platform 项目。CLI 适用于以下情况:

  • 直接使用项目源代码。
  • 使用脚本进行 OpenShift Container Platform 的相关操作。
  • 受带宽资源限制,无法使用 Web 控制台。

1.1.2. 安装 CLI

为了可以使用命令行界面与 OpenShift Container Platform 进行交互,您需要安装 CLI。

重要

如果安装了旧版本的 oc,则无法使用 OpenShift Container Platform 4.2 中的所有命令。下载并安装新版本的 oc

流程

  1. 在 Red Hat OpenShift Cluster Manager 站点的 Infrastructure Provider 页面中导航至您的安装类型页面,并点击 Download Command-line Tools
  2. 点您的操作系统和系统架构的文件夹,然后点压缩文件。

    注意

    您可在 Linux 、Windows 或 macOS 上安装 oc

  3. 将文件保存到文件系统。
  4. 展开压缩文件。
  5. 把它放到 PATH 中的一个目录下。

安装 CLI 后,就可以使用oc命令:

$ oc <command>

1.1.3. 登录到 CLI

您可以登录到oc CLI 以访问和管理您的群集。

先决条件

  • 有访问 OpenShift Container Platform 集群的权限。
  • 已安装CLI。

流程

  • 使用oc login命令登录到 CLI,根据提示输入所需信息。

    $ 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
    
    Authentication required for https://openshift.example.com:6443 (openshift)
    Username: user1 3
    Password: 4
    Login successful.
    
    You don't have any projects. You can try to create a new project, by running
    
        oc new-project <projectname>
    
    Welcome! See 'oc help' to get started.
    1
    输入 OpenShift Container Platform 服务器的 URL。
    2
    输入是否使用不安全的连接。
    3
    输入要登录的用户名。
    4
    输入用户密码。

您现在可以创建项目或执行其他命令来管理集群。

1.1.4. 使用 CLI

参阅以下部分以了解如何使用 CLI 完成常见任务。

1.1.4.1. 创建一个项目

使用oc new-project命令创建新项目。

$ oc new-project my-project
Now using project "my-project" on server "https://openshift.example.com:6443".

1.1.4.2. 创建一个新的应用程序

使用oc new-app命令创建新应用程序。

$ 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"

...

    Run 'oc status' to view your app.

1.1.4.3. 查看 pod

使用oc get pods命令查看当前项目的 pod。

$ oc get pods -o wide
NAME                  READY   STATUS      RESTARTS   AGE     IP            NODE                           NOMINATED NODE
cakephp-ex-1-build    0/1     Completed   0          5m45s   10.131.0.10   ip-10-0-141-74.ec2.internal    <none>
cakephp-ex-1-deploy   0/1     Completed   0          3m44s   10.129.2.9    ip-10-0-147-65.ec2.internal    <none>
cakephp-ex-1-ktz97    1/1     Running     0          3m33s   10.128.2.11   ip-10-0-168-105.ec2.internal   <none>

1.1.4.4. 查看 pod 日志

使用oc logs命令查看特定 pod 的日志。

$ oc logs cakephp-ex-1-deploy
--> Scaling cakephp-ex-1 to 1
--> Success

1.1.4.5. 查看当前项目

使用oc project命令查看当前项目。

$ oc project
Using project "my-project" on server "https://openshift.example.com:6443".

1.1.4.6. 查看当前项目的状态

使用oc status命令查看有关当前项目的信息,例如 Services,DeploymentConfigs 和BuildConfigs。

$ oc status
In project my-project on server https://openshift.example.com:6443

svc/cakephp-ex - 172.30.236.80 ports 8080, 8443
  dc/cakephp-ex deploys istag/cakephp-ex:latest <-
    bc/cakephp-ex source builds https://github.com/sclorg/cakephp-ex on openshift/php:7.2
    deployment #1 deployed 2 minutes ago - 1 pod

3 infos identified, use 'oc status --suggest' to see details.

1.1.4.7. 列出支持的 API 资源

使用oc api-resources命令查看服务器上支持的 API 资源列表。

$ oc api-resources
NAME                                  SHORTNAMES       APIGROUP                              NAMESPACED   KIND
bindings                                                                                     true         Binding
componentstatuses                     cs                                                     false        ComponentStatus
configmaps                            cm                                                     true         ConfigMap
...

1.1.5. 获得帮助

您可以通过以下方式获得有关 CLI 命令和 OpenShift Container Platform 资源的帮助信息。

  • 使用oc help获取所有可用 CLI 命令的列表和描述:

    示例:获取 CLI 的常规帮助信息

    $ 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
    
    ...

  • 使用--help标志获取有关特定CLI命令的帮助信息:

    示例:获取oc create命令的帮助信息

    $ oc create --help
    Create a resource by filename or stdin
    
    JSON and YAML formats are accepted.
    
    Usage:
      oc create -f FILENAME [flags]
    
    ...

  • 使用oc explain命令查看特定资源的描述信息和项信息:

    示例:查看Pod资源的文档

    $ 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>
         APIVersion defines the versioned schema of this representation of an
         object. Servers should convert recognized schemas to the latest internal
         value, and may reject unrecognized values. More info:
         https://git.k8s.io/community/contributors/devel/api-conventions.md#resources
    
    ...

1.1.6. 注销 CLI

您可以注销CLI以结束当前会话。

  • 使用oc logout命令。

    $ oc logout
    Logged "user1" out on "https://openshift.example.com"

这将从服务器中删除已保存的身份验证令牌,并将其从配置文件中删除。

1.2. 配置CLI

1.2.1. 启用 tab 自动完成功能

在安装oc CLI工具后,可以启用 tab 自动完成功能,以便在按 Tab 键时自动完成oc命令或显示建议选项。

先决条件

  • 已安装oc CLI工具。

流程

以下过程为 Bash 启用 tab 自动完成功能。

  1. 将Bash完成代码保存到一个文件中。

    $ oc completion bash > oc_bash_completion
  2. 将文件复制到/etc/bash_completion.d/

    $ sudo cp oc_bash_completion /etc/bash_completion.d/

    您也可以将文件保存到一个本地目录,并从您的.bashrc文件中 source 这个文件。

开新终端时 tab 自动完成功能将被启用。

1.3. 使用插件扩展CLI

您可以针对默认的oc命令编写并安装插件,从而可以使用OpenShift Container Platform CLI执行新的及更复杂的任务。

1.3.1. 编写CLI插件

您可以使用任何可以编写命令行命令的编程语言或脚本为OpenShift Container Platform CLI编写插件。请注意,您不能使用插件来覆盖现有的oc命令。

重要

OpenShift CLI插件目前是技术预览功能。技术预览功能不包括在红帽生产服务级别协议(SLA)中,且其功能可能并不完善。因此,红帽不建议在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关详细信息,请参阅红帽技术预览功能支持范围

流程

此过程创建一个简单的Bash插件,它的功能是在执行oc foo命令时将消息输出到终端。

  1. 创建一个名为oc-foo的文件。

    在命名插件文件时,请记住以下几点:

    • 文件必须以oc-kubectl-开始。
    • 文件名决定了调用这个插件的命令。例如,oc foo bar命令将会调用文件名为oc-foo-bar的插件。如果希望命令中包含破折号,也可以使用下划线。例如,可以通过oc foo-bar命令调用文件名为oc-foo_bar的插件。
  2. 将以下内容添加到该文件中。

    #!/bin/bash
    
    # optional argument handling
    if [[ "$1" == "version" ]]
    then
        echo "1.0.0"
        exit 0
    fi
    
    # optional argument handling
    if [[ "$1" == "config" ]]
    then
        echo $KUBECONFIG
        exit 0
    fi
    
    echo "I am a plugin named kubectl-foo"

为OpenShift Container Platform CLI安装此插件后,可以使用oc foo命令调用它。

其它资源

1.3.2. 安装和使用CLI插件

为OpenShift Container Platform CLI编写自定义插件后,必须安装它以使用它提供的功能。

重要

OpenShift CLI插件目前是技术预览功能。技术预览功能不包括在红帽生产服务级别协议(SLA)中,且其功能可能并不完善。因此,红帽不建议在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关详细信息,请参阅红帽技术预览功能支持范围

先决条件

  • 已安装oc CLI工具。
  • 有一个 CLI 插件文件,其文件名以 oc-kubectl-开始。

流程

  1. 将插件文件设置为可执行文件。

    $ chmod +x <plugin_file>
  2. 将文件放在PATH中的任何位置,例如/usr/local/bin/

    $ sudo mv <plugin_file> /usr/local/bin/.
  3. 运行 oc plugin list 以确认插件可以被列出。

    $ oc plugin list
    The following compatible plugins are available:
    
    /usr/local/bin/<plugin_file>

    如果您的插件没有被列出,检查文件是否以OC-kubectl-开始,是否可执行,并在您的PATH中。

  4. 调用插件引入的新命令或选项。

    例如,如果您从 Sample plug-in repository 构建并安装了kubectl-ns插件,则可以使用以下命令查看当前命名空间。

    $ oc ns

    请注意,调用插件的命令取决于插件的文件名。例如,文件名为 oc-foo-bar的插件会被 oc foo bar 命令调用。

1.4. 开发人员CLI命令

1.4.1. 基本CLI命令

1.4.1.1. explain

显示特定资源的文档。

示例:显示Pod的文档

$ oc explain pods

1.4.1.2. login

登录OpenShift Container Platform服务器并保存登录信息以供后续使用。

示例:交互式登录

$ oc login

示例:指定用户名进行登陆

$ oc login -u user1

1.4.1.3. new-app

通过指定源代码,模板或镜像来创建新应用程序。

示例:从本地Git仓库创建新应用程序

$ oc new-app .

示例:从远程Git仓库创建新应用程序

$ oc new-app https://github.com/sclorg/cakephp-ex

示例:从远程的一个私有Git仓库创建新应用程序

$ oc new-app https://github.com/youruser/yourprivaterepo --source-secret=yoursecret

1.4.1.4. new-project

创建一个新项目,并切换到这个项目作为配置中的默认项目。

示例:创建一个新项目

$ oc new-project myproject

1.4.1.5. project

切换到另一个项目,并使其成为配置中的默认项目。

示例:切换到另外一个项目

$ oc project test-project

1.4.1.6. projects

显示服务器上当前活动项目和现有项目的信息。

示例:列出所有项目

$ oc projects

1.4.1.7. status

显示当前项目的概况信息。

示例:显示当前项目的状态

$ oc status

1.4.2. 构建和部署CLI命令

1.4.2.1. cancel-build

取消正在运行,待处理或新的构建。

示例:取消一个构建

$ oc cancel-build python-1

示例:从python BuildConfig中取消所有待处理的构建

$ oc cancel-build buildconfig/python --state=pending

1.4.2.2. import-image

从镜像仓库中导入最新的 tag 和镜像信息。

示例:导入最新的镜像信息

$ oc import-image my-ruby

1.4.2.3. new-build

从源代码创建一个新的BuildConfig

示例:从本地Git仓库创建一个新的 BuildConfig

$ oc new-build .

示例:从本地Git仓库创建一个新的 BuildConfig

$ oc new-build https://github.com/sclorg/cakephp-ex

1.4.2.4. rollback

将应用程序还原回以前的部署。

示例:回滚到上次成功的部署

$ oc rollback php

示例:回滚到一个特定版本

$ oc rollback php --to-version=3

1.4.2.5. rollout

开始一个新的 rollout 操作,查看它的状态或历史信息,或回滚到应用程序的一个以前的版本。

示例:回滚到上次成功的部署

$ oc rollout undo deploymentconfig/php

示例:使用最新状态启动一个新的 DeploymentConfig rollout 操作

$ oc rollout latest deploymentconfig/php

1.4.2.6. start-build

从一个BuildConfig启动构建或复制现有的一个构建。

示例:从指定的BuildConfig启动构建

$ oc start-build python

示例:从以前的一个构建版本开始进行构建

$ oc start-build --from-build=python-1

示例:为当前构建设置要使用的环境变量

$ oc start-build python --env=mykey=myvalue

1.4.2.7. tag

将存在的镜像 tag 为镜像流(imagestream)。

示例:配置ruby镜像的latest tag 指向2.0 tag

$ oc tag ruby:latest ruby:2.0

1.4.3. 应用程序管理CLI命令

1.4.3.1. annotate

更新一个或多个资源上的注解。

示例:为 Route 添加一个注解

$ oc annotate route/test-route haproxy.router.openshift.io/ip_whitelist="192.168.1.10"

示例:从Route中删除注释

$ oc annotate route/test-route haproxy.router.openshift.io/ip_whitelist-

1.4.3.2. apply

通过文件名或标准输入(stdin)以JSON或YAML格式将配置应用于资源。

示例:将pod.json中的配置应用于一个Pod

$ oc apply -f pod.json

1.4.3.3. autoscale

自动缩放一个 DeploymentConfig 或 ReplicationController。

示例:自动缩放至最少两个,最多五个Pod

$ oc autoscale deploymentconfig/parksmap-katacoda --min=2 --max=5

1.4.3.4. create

通过文件名或标准输入(stdin)使用 JSON 或 YAML 格式创建一个资源。

示例:使用pod.json的内容创建一个Pod

$ oc create -f pod.json

1.4.3.5. delete

删除一个资源。

示例:删除名为parksmap-katacoda-1-qfqz4的Pod

$ oc delete pod/parksmap-katacoda-1-qfqz4

示例:删除所有带有app=parksmap-katacoda标签的Pod

$ oc delete pods -l app=parksmap-katacoda

1.4.3.6. describe

获得有关一个特定对象的详细信息。

示例:获得名为example的部署的详细信息

$ oc describe deployment/example

示例:获得所有Pod的详细信息

$ oc describe pods

1.4.3.7. edit

编辑一个资源。

示例:使用默认编辑器编辑DeploymentConfig

$ oc edit deploymentconfig/parksmap-katacoda

示例:使用其他编辑器编辑DeploymentConfig

$ OC_EDITOR="nano" oc edit deploymentconfig/parksmap-katacoda

示例:编辑一个 JSON 格式的 DeploymentConfig

$ oc edit deploymentconfig/parksmap-katacoda -o json

1.4.3.8. expose

把一个 Service 作为一个 Route 向外部开放。

示例:开放一个 Service

$ oc expose service/parksmap-katacoda

示例:开放一个 Service 并指定主机名

$ oc expose service/parksmap-katacoda --hostname=www.my-host.com

1.4.3.9. get

显示一个或多个资源。

示例:列出 default 命名空间中的 pod

$ oc get pods -n default

示例:获取JSON格式的python DeploymentConfig的详细信息

$ oc get deploymentconfig/python -o json

1.4.3.10. label

更新一个或多个资源上的标签。

示例:更新python-1-mz2rf Pod 的标签,把status设置为unhealthy

$ oc label pod/python-1-mz2rf status=unhealthy

1.4.3.11. scale

为ReplicationController或DeploymentConfig设置所需的副本数。

示例:将ruby-app DeploymentConfig扩展为三个Pod

$ oc scale deploymentconfig/ruby-app --replicas=3

1.4.3.12. secrets

管理项目中的 secret

示例:default 服务账户(service account)使用 my-pull-secret作为 image pull 操作的 secret

$ oc secrets link default my-pull-secret --for=pull

1.4.3.13. serviceaccounts

获取分配给服务帐户的令牌或,或为服务帐户创建新令牌或kubeconfig文件。

示例:获取分配给default服务帐户的令牌

$ oc serviceaccounts get-token default

1.4.3.14. set

配置现有应用资源。

示例:设置BuildConfig中的一个 secret 的名称

$ oc set build-secret --source buildconfig/mybc mysecret

1.4.4. 调试CLI命令

1.4.4.1. attach

为正在运行的容器附加一个 shell。

示例:从Pod python-1-mz2rf获取python容器的输出信息

$ oc attach python-1-mz2rf -c python

1.4.4.2. cp

将文件和目录复制到容器或从容器中复制。

示例:将文件从python-1-mz2rf Pod 中复制到本地文件系统

$ oc cp default/python-1-mz2rf:/opt/app-root/src/README.md ~/mydirectory/.

1.4.4.3. debug

启动一个 shell 以调试正在运行的应用程序。

示例:调试python部署

$ oc debug deploymentconfig/python

1.4.4.4. exec

在容器中执行命令。

示例:在 Pod python-1-mz2rfpython容器中执行ls命令

$ oc exec python-1-mz2rf -c python ls

1.4.4.5. logs

获得特定构建,BuildConfig,DeploymentConfig或Pod的日志输出。

示例:从python DeploymentConfig 中获得最新的日志

$ oc logs -f deploymentconfig/python

1.4.4.6. port-forward

将一个或多个本地端口转发到一个Pod。

示例:在本地侦听端口8888并将其数据转发到Pod的端口5000

$ oc port-forward python-1-mz2rf 8888:5000

1.4.4.7. proxy

运行到Kubernetes API服务器的代理。

示例:在端口8011上运行到API服务器的代理,由./local/www/提供静态内容

$ oc proxy --port=8011 --www=./local/www/

1.4.4.8. rsh

打开到容器的远程shell会话。

示例:在python-1-mz2rf Pod中的第一个容器上打开shell会话

$ oc rsh python-1-mz2rf

1.4.4.9. rsync

将目录的内容复制到正在运行的Pod容器或从容器中复制。rsync命令只复制您的操作系统中已更改的文件。

示例:把一个Pod目录与一个本地目录进行同步

$ oc rsync ~/mydirectory/ python-1-mz2rf:/opt/app-root/src/

1.4.4.10. run

创建并运行一个特定镜像。默认情况下,这会创建一个DeploymentConfig来管理创建的容器。

示例:启动具有三个副本的perl镜像实例

$ oc run my-test --image=perl --replicas=3

1.4.4.11. wait

等待一个或多个资源上的特定条件。

示例:等待python-1-mz2rf Pod 被删除

$ oc wait --for=delete pod/python-1-mz2rf

1.4.5. 高级开发人员CLI命令

1.4.5.1. api-resources

显示服务器支持的完整API资源列表。

示例:列出支持的API资源

$ oc api-resources

1.4.5.2. api-versions

显示服务器支持的完整API版本列表。

示例:列出支持的API版本

$ oc api-versions

1.4.5.3. auth

检查权限并协调RBAC角色。

示例:检查当前用户是否可以读取Pod日志

$ oc auth can-i get pods --subresource=log

示例:从一个文件协调RBAC角色和权限

$ oc auth reconcile -f policy.json

1.4.5.4. cluster-info

显示 master 和集群服务的地址。

示例:显示集群信息

$ oc cluster-info

1.4.5.5. convert

将YAML或JSON配置文件转换为一个不同的API版本并打印到标准输出(stdout)。

示例:将pod.yaml转换到最新版本

$ oc convert -f pod.yaml

1.4.5.6. extract

提取 ConfigMap 或 secret 的内容。ConfigMap或secret中的每个关键字(key)都被创建为具有这个关键字名称的单独文件。

示例:将ruby-1-ca ConfigMap的内容下载到当前目录

$ oc extract configmap/ruby-1-ca

示例:将ruby-1-ca ConfigMap的内容输出到stdout

$ oc extract configmap/ruby-1-ca --to=-

1.4.5.7. idle

把可扩展资源设置为空闲。一个空闲的服务在接收到数据时将自动变为非空闲状态,或使用oc scale命令手动把空闲服务变为非空闲。

示例:把ruby-app服务变为空闲状态

$ oc idle ruby-app

1.4.5.8. image

管理OpenShift Container Platform集群中的镜像。

示例:把一个镜像复制到另外一个 tag

$ oc image mirror myregistry.com/myimage:latest myregistry.com/myimage:stable

1.4.5.9. observe

观察资源的变化并对其采取措施。

示例:观察对服务的更改

$ oc observe services

1.4.5.10. patch

使用JSON或YAML格式的策略合并补丁更新对象的一个或多个字段。

示例:将节点node1spec.unschedulable字段更新为true

$ oc patch node/node1 -p '{"spec":{"unschedulable":true}}'

注意

如果需要使用自定义资源定义,则必须在命令中包含--type merge选项。

1.4.5.11. policy

管理授权策略。

示例:将edit角色添加给当前项目的user1用户

$ oc policy add-role-to-user edit user1

1.4.5.12. process

将模板处理为资源列表。

示例:将template.json转换为资源列表并传递给oc create

$ oc process -f template.json | oc create -f -

1.4.5.13. registry

管理OpenShift Container Platform中集成的 registry。

示例:显示集成的 registry 的信息

$ oc registry info

1.4.5.14. replace

根据指定配置文件的内容修改现有对象。

示例:使用pod.json的内容更新Pod

$ oc replace -f pod.json

1.4.6. 设置CLI命令

1.4.6.1. completion

输出指定shell的shell完成代码。

示例:显示Bash的完成代码

$ oc completion bash

1.4.6.2. config

管理客户端配置文件。

示例:显示当前配置

$ oc config view

示例:切换到另外一个上下文

$ oc config use-context test-context

1.4.6.3. logout

退出当前会话。

示例:结束当前会话

$ oc logout

1.4.6.4. whoami

显示有关当前会话的信息。

示例:显示当前已验证的用户

$ oc whoami

1.4.7. 其他开发人员CLI命令

1.4.7.1. help

显示CLI的常规帮助信息和可用命令列表。

示例:显示可用命令

$ oc help

示例:显示new-project命令的帮助信息

$ oc help new-project

1.4.7.2. plugin

列出用户PATH中的可用插件。

示例:列出可用的插件

$ oc plugin list

1.4.7.3. version

显示oc客户端和服务器版本。

示例:显示版本信息

$ oc version

对于集群管理员,还会显示OpenShift Container Platform服务器版本。

1.5. 管理员CLI命令

1.5.1. 集群管理CLI命令

1.5.1.1. must-gather

批量收集有关集群当前状态的数据以供进行问题调试。

示例:收集调试信息

$ oc adm must-gather

1.5.1.2. top

显示服务器上资源的使用情况统计信息。

示例:显示Pod的CPU和内存使用情况

$ oc adm top pods

示例:显示镜像的使用情况统计信息

$ oc adm top images

1.5.2. 集群管理CLI命令

1.5.2.1. cordon

将节点标记为不可调度。手动将节点标记为不可调度将会阻止在此节点上调度任何新的pod,但不会影响节点上已存在的pod。

示例:将node1标记为不可调度

$ oc adm cordon node1

1.5.2.2. drain

排空节点以准备进行维护。

示例:排空node1

$ oc adm drain node1

1.5.2.3. node-logs

显示并过滤节点日志。

示例:获取NetworkManager的日志

$ oc adm node-logs --role master -u NetworkManager.service

1.5.2.4. taint

更新一个或多个节点上的污点。

示例:添加污点以为一组用户指定一个节点

$ oc adm taint nodes node1 dedicated=groupName:NoSchedule

示例:使用 dedicated 从节点 node1上删除污点

$ oc adm taint nodes node1 dedicated-

1.5.2.5. uncordon

将节点标记为可调度。

示例:将node1标记为可调度

$ oc adm uncordon node1

1.5.3. 安全和策略CLI命令

1.5.3.1. certificate

批准或拒绝证书签名请求(CSR)。

示例:批准一个 CSR

$ oc adm certificate approve csr-sqgzp

1.5.3.2. groups

管理集群中的组。

示例:创建一个新组

$ oc adm groups new my-group

1.5.3.3. new-project

创建一个新项目并指定管理选项。

示例:使用节点选择器创建新项目

$ oc adm new-project myproject --node-selector='type=user-node,region=east'

1.5.3.4. pod-network

管理集群中的Pod网络。

示例:将project1和project2与其他非全局项目隔离

$ oc adm pod-network isolate-projects project1 project2

1.5.3.5. policy

管理集群上的角色和策略。

示例:为user1用户添加所有项目的edit角色

$ oc adm policy add-cluster-role-to-user edit user1

示例:把 privileged安全上下文限制(scc)添加给一个服务账户

$ oc adm policy add-scc-to-user privileged -z myserviceaccount

1.5.4. 维护CLI命令

1.5.4.1. migrate

根据使用的子命令,将集群上的资源迁移到新版本或格式。

示例:执行所有存储对象的更新

$ oc adm migrate storage

示例:仅执行Pod的更新

$ oc adm migrate storage --include=pods

1.5.4.2. prune

从服务器中删除旧版本的资源。

示例:删除旧版本的构建,包括那些BuildConfigs已不存在的版本

$ oc adm prune builds --orphans

1.5.5. 配置CLI命令

1.5.5.1. create-api-client-config

创建用于连接服务器的客户端配置。这将创建一个文件夹,其中包含客户端证书,客户端密钥,服务器证书颁发机构和用于以提供的用户身份连接到主服务器(master)的kubeconfig文件。

示例:为代理生成客户端证书

$ 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

创建默认引导策略。

示例:创建一个带有默认引导策略的名为policy.json的文件

$ oc adm create-bootstrap-policy-file --filename=policy.json

1.5.5.3. create-bootstrap-project-template

创建引导程序项目模板。

示例:将YAML格式的引导项目模板输出到stdout

$ oc adm create-bootstrap-project-template -o yaml

1.5.5.4. create-error-template

创建用于自定义错误页面的模板。

示例:创建输出到stdout的错误页模板

$ oc adm create-error-template

1.5.5.5. create-kubeconfig

基于客户端证书创建基本的.kubeconfig文件。

示例:使用提供的客户端证书创建.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

创建用于自定义登陆页面的模板。

示例:创建输出到stdout的登陆页模板

$ oc adm create-login-template

1.5.5.7. create-provider-selection-template

创建用于自定义供应商选择页面的模板。

示例:创建输出到stdout的供应商选择页模板

$ oc adm create-provider-selection-template

1.5.6. 其他管理员CLI命令

1.5.6.1. build-chain

输出构建的输入和依赖项。

示例: 输出perl镜像流的依赖项

$ oc adm build-chain perl

1.5.6.2. completion

输出指定 shell 的 oc adm 命令的 shell 完成代码。

示例:显示Bash的oc adm完成代码

$ oc adm completion bash

1.5.6.3. config

管理客户端配置文件。此命令与oc config命令具有相同的作用。

示例:显示当前配置

$ oc adm config view

示例:切换到另外一个上下文

$ oc adm config use-context test-context

1.5.6.4. release

管理OpenShift Container Platform发布过程的各个方面,例如查看有关发布的信息或检查发布的内容。

示例:生成两个版本之间的 changelog 信息,并保存到changelog.md

$ oc adm release info --changelog=/tmp/git \
    quay.io/openshift-release-dev/ocp-release:4.2.0-rc.7 \
    quay.io/openshift-release-dev/ocp-release:4.2.0 \
    > changelog.md

1.5.6.5. verify-image-signature

使用本地公共GPG密钥验证导入到内部 registry 的一个镜像的镜像签名。

示例:验证nodejs镜像签名

$ 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

1.6. oc 和 kubectl 命令的使用方法

Kubernetes 的命令行界面 (CLI) kubectl 可以用来对 Kubernetes 集群运行命令。由于 OpenShift Container Platform 是经过认证的 Kubernetes 发行版本,因此您可以使用 OpenShift Container Platform 附带的受支持的 kubectl 二进制文件,或者使用 oc 二进制文件来获得扩展的功能。

1.6.1. oc 二进制文件

oc 二进制文件提供与 kubectl 二进制文件相同的功能,但它经过扩展,可原生支持额外的 OpenShift Container Platform 功能,包括:

  • 对 OpenShift Container Platform 资源的完整支持

    DeploymentConfig、BuildConfig、Route、ImageStream 和 ImageStreamTag 等资源特定于各种 OpenShift Container Platform 发行版本,并基于标准的 Kubernetes 原语构建。

  • 身份验证

    oc 二进制文件提供了一个内置 login 命令,此命令可进行身份验证,并让您处理 OpenShift Container Platform 项目,这会将 Kubernetes 命名空间映射到经过身份验证的用户。如需更多信息,请参阅了解身份验证

  • 附加命令

    例如,借助附加命令 oc new-app 可以更轻松地使用现有源代码或预构建镜像来启动新的应用程序。同样,附加命令 oc new-project 让您可以更轻松地启动一个项目并切换到该项目作为您的默认项目。

1.6.2. kubectl 二进制文件

提供 kubectl 二进制文件的目的是为来自标准 Kubernetes 环境的新 OpenShift Container Platform 用户或者希望使用 kubectl CLI 的用户支持现有工作流和脚本。kubectl 的现有用户可以继续使用二进制文件与 Kubernetes 原语交互,而不需要对 OpenShift Container Platform 集群进行任何更改。

如需更多信息,请参阅 kubectl 文档

第 2 章 OpenShift Do developer CLI (odo)

2.1. 了解 OpenShift Do

OpenShift Do (odo) 是一个在 OpenShift Container Platform 上创建应用程序的快速、易用的 CLI 工具。通过使用 odo,开发人员可以集中精力创建应用程序,而无需管理 OpenShift Container Platform 集群。odo 会自动创建部署配置、构建配置、服务路由和其他 OpenShift Container Platform 元素。

现有工具,如 oc 更加注重操作,需要对 Kubernetes 和 OpenShift Container Platform 概念有深入了解。odo 会处理与 Kubernetes 和 OpenShift Container Platform 相关的复杂概念,从而使开发人员可以把主要精力专注于最重要的内容:代码。

2.1.1. 主要特性

odo 的设计是简单而简洁的,其主要特性如下:

  • 简单的语法,围绕开发人员熟悉的概念(比如项目、应用程序和组件)进行设计。
  • 完全基于客户端。OpenShift Container Platform 集群中不需要用于部署的服务器。
  • 对 Node.js 和 Java 组件的官方支持。
  • 与各种语言和框架兼容,比如 Ruby 、Perl 、PHP 和 Python 部分兼容。
  • 它会检测本地代码的更改,并自动将其部署到集群中,为验证更改提供即时反馈。
  • 列出 OpenShift Container Platform 集群中的所有可用组件和服务。

2.1.2. 核心概念

project
项目是一个用来对源代码、测试和库进行管理的独立空间。
Application
应用程序是为最终用户设计的程序。应用程序由多个微服务或组件组成,它们单独用来构建整个应用程序。应用程序示例:视频游戏、媒体播放器、网页浏览器。
组件
组件就是一组 Kubernetes 资源,用于托管代码或数据。每个组件可以单独运行和部署。组件示例:Node.js、Perl、PHP、Python、Ruby。
Service
服务是您的组件链接到或依赖的软件。服务示例:MariaDB、Jenkins、MySQL。在 odo 中,服务从 OpenShift Service Catalog 置备,且必须在集群中启用。

2.1.2.1. 官方支持的语言和相应的容器镜像

表 2.1. 支持的语言、容器镜像和软件包管理器

语言容器镜像软件包管理器

Node.js

centos/nodejs-8-centos7

NPM

 

rhoar-nodejs/nodejs-8

NPM

 

bucharestgold/centos7-s2i-nodejs

NPM

 

rhscl/nodejs-8-rhel7

NPM

 

rhscl/nodejs-10-rhel7

NPM

Java

redhat-openjdk-18/openjdk18-openshift

Maven,Gradle

 

openjdk/openjdk-11-rhel8

Maven,Gradle

 

openjdk/openjdk-11-rhel7

Maven,Gradle

2.1.2.1.1. 列出可用的容器镜像
注意

可用的容器镜像列表从集群的内部容器 registry 以及与集群关联的外部 registry 提供。

要列出集群的可用组件和相关容器镜像,请执行以下操作:

  1. 使用 odo 登录 OpenShift Container Platform 集群。

    $ odo login -u developer -p developer
  2. 要列出可用的 odo 支持和不支持的组件以及相应的容器镜像,请执行以下操作:

    $ odo catalog list components
    Odo Supported OpenShift Components:
    NAME        PROJECT      TAGS
    java       openshift     8,latest
    nodejs     openshift     10,8,8-RHOAR,latest
    
    Odo Unsupported OpenShift Components:
    NAME                      PROJECT       TAGS
    dotnet                    openshift     1.0,1.1,2.1,2.2,latest
    fuse7-eap-openshift       openshift     1.3

    TAGS 列代表可用镜像版本,例如:10 代表 rhoar-nodejs/nodejs-10 容器镜像。

2.2. odo 架构

本节论述了 odo 架构以及 odo 如何在集群中管理 OpenShift Container Platform 资源。

2.2.1. 开发者设置

使用 odo,您可以在 OpenShift Container Platform 集群中从终端创建和部署应用程序。代码编辑器插件使用 odo,让用户可以从其 IDE 终端与 OpenShift Container Platform 集群交互。使用 odo 的插件示例:VS Code Openshift Connector、Openshift Connector for Intellij、Codewind for Eclipse Che。

odo 可在 Windows、macOS 和 Linux 操作系统上以及从任意终端运行。odo 为 bash 和 zsh 命令行 shell 提供自动完成功能。

odo 1.0 支持 Node.js 和 Java 组件。

2.2.2. OpenShift source-to-image

OpenShift Source-to-Image (S2I) 是一个开源项目,可帮助从源代码构建工件并将其注入容器镜像。S2I 通过构建源代码来生成可随时运行的镜像,无需 Dockerfile。odo 使用 S2I 构建器镜像来执行容器内的开发者源代码。

2.2.3. OpenShift 集群对象

2.2.3.1. Init 容器

Init 容器是应用程序容器启动前运行的专用容器,为应用程序容器的运行配置必要的环境。Init 容器可以包含应用程序镜像没有的文件,例如设置脚本。Init 容器始终需要运行完毕,如果任何 init 容器失败,应用程序容器就不会启动。

由 odo 创建的 Pod 执行两个 Init 容器:

  • copy-supervisord Init 容器。
  • copy-files-to-volume Init 容器。
2.2.3.1.1. copy-supervisord

copy-supervisord Init 容器会将必要的文件复制到 emptyDir 卷中。主应用程序容器从 emptyDir 卷中使用这些文件。

复制到 emptyDir 卷中的文件:

  • 二进制文件:

    • go-init 是一个最小的 init 系统。它作为应用程序容器中的第一个进程 (PID 1) 运行。go-init 会启动运行开发者代码的 SupervisorD 守护进程。处理孤立进程需要用到 go-init。
    • SupervisorD 是一个进程控制系统。它监控配置的进程并确保它们正在运行。如果需要,它也会重启服务。对于 odo,SupervisorD 会执行并监控开发者代码。
  • 配置文件:

    • supervisor.conf 是 SupervisorD 守护进程启动时所必需的配置文件。
  • 脚本:

    • 在 OpenShift S2I 概念中,assemble-and-restart 用于构建和部署用户源代码。assemble-and-restart 脚本首先在应用程序容器中编译用户源代码,然后重启 SupervisorD 来使用户更改生效。
    • 在 OpenShift S2I 概念中,Run 用于执行所编译的源代码。run 脚本执行 assemble-and-restart 脚本创建的编译代码。
    • s2i-setup 是一个脚本,它可创建 assemble-and-restart 和 run 脚本成功执行所需的文件和目录。每次应用程序容器启动时都会执行此脚本。
  • 目录:

    • language-scripts:OpenShift S2I 允许使用自定义 assemblerun 脚本。language-scripts 目录中有几个特定语言的自定义脚本。自定义脚本提供额外的配置,以使 odo debug 正常工作。

emtpyDir Volume 会同时挂载于 Init 容器和应用程序容器的 /opt/odo 挂载点。

2.2.3.1.2. copy-files-to-volume

copy-files-to-volume Init 容器将位于 S2I 构建器镜像中的 /opt/app-root 的文件复制到持久性卷中。然后该卷会挂载于应用程序容器中的同一位置 (/opt/app-root)。

如果 /opt/app-root 上没有 PersistentVolume,则当 PersistentVolumeClaim 挂载于同一位置时,此目录中的数据会丢失。

PVC 挂载于 Init 容器中的 /mnt 挂载点。

2.2.3.2. 应用程序容器

应用程序容器是执行用户源代码的主要容器。

应用程序容器挂载了两个卷:

  • 挂载于 /opt/odoemptyDir
  • 挂载于 /opt/app-rootPersistentVolume

go-init 作为应用程序容器内的第一个进程执行。然后,go-init 进程启动 SupervisorD 守护进程。

SupervisorD 执行并监控用户编译的源代码。如果用户进程崩溃,SupervisorD 会重新启动它。

2.2.3.3. PersistentVolumePersistentVolumeClaim

PersistentVolumeClaim (PVC) 是在 Kubernetes 中置备 PersistentVolume 的卷类型。PersistentVolume 的生命周期独立于 Pod 生命周期。PersistentVolume 上的数据会在 Pod 重启后保留。

copy-files-to-volume Init 容器会将必要的文件复制到 PersistentVolume 上。主应用程序容器在运行时使用这些文件来执行。

PersistentVolume 的命名规则为 <component-name>-s2iData。

ContainerPVC 挂载于

copy-files-to-volume

/mnt

应用程序容器

/opt/app-root

2.2.3.4. emptyDir

当 Pod 分配给节点时,会创建一个 emptyDir 卷,只要该 Pod 在节点上运行,该卷即会一直存在。如果容器被重启或移动,则 emptyDir 的内容会被删除,Init 容器会将数据重新恢复为 emptyDiremptyDir 最初为空。

copy-supervisord Init 容器会将必要的文件复制到 emptyDir 卷中。然后,主应用程序容器会在运行时使用这些文件来执行。

ContaineremptyDir Volume 挂在于

copy-supervisord

/opt/odo

应用程序容器

/opt/odo

2.2.3.5. Service

服务是一个 Kubernetes 概念,它抽象地代表了与一组 Pod 的通信方式。

odo 为每个应用程序 Pod 创建一个服务,使其可访问以进行通信。

2.2.4. odo push 工作流

本节论述了 odo push 工作流。odo push 会使用所有必要的 OpenShift Container Platform 资源在 OpenShift Container Platform 集群中部署用户代码。

  1. 创建资源

    如果尚未创建,odo push 会创建以下 OpenShift Container Platform 资源:

    • 部署配置 (DC):

      • 执行两个 init 容器:copy-supervisordcopy-files-to-volume。init 容器将文件复制到 emptyDirPersistentVolume 类型的卷上。
      • 应用程序容器启动。应用程序容器中的第一个进程是 PID=1 的 go-init 进程。
      • go-init 进程启动 SupervisorD 守护进程。

        注意

        用户应用程序代码尚未复制到应用程序容器中,因此 SupervisorD 守护进程没有执行 run 脚本。

    • Service
    • Secrets
    • PersistentVolumeClaim
  2. 文件索引

    • 文件索引器会将源代码目录中的文件编成索引。索引器会以递归方式遍历源代码目录,并找到已创建、删除或重命名的文件。
    • 文件索引器在 .odo 目录下的 odo index 文件中维护索引信息。
    • 如果 odo index 文件不存在,这意味着文件索引程序是首次执行,并会创建新的 odo index JSON 文件。odo index JSON 文件包含文件映射 - 已遍历文件的相对文件路径以及已更改和已删除文件的绝对路径。
  3. 推送代码

    本地代码被复制到应用程序容器中,通常位于 /tmp/src 下。

  4. 执行 assemble-and-restart

    源代码成功复制后,会在运行的应用程序容器中执行 assemble-and-restart 脚本。

2.3. 安装 odo

下面的部分论述了如何在不同的平台中安装 odo

注意

目前,odo 不支持在限制的网络环境中安装。

2.3.1. 在 Linux 中安装 odo

2.3.1.1. 二进制安装

# 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

2.3.1.2. 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'
# chmod +x /usr/local/bin/odo

2.3.2. 在 Windows 中安装 odo

2.3.2.1. 二进制安装

  1. 下载最新的 odo.exe 文件。
  2. odo.exe 所在位置添加到 GOPATH/bin 目录中。
为 Windows 7/8 设置 PATH 变量

以下示例演示了如何设置路径变量。您的二进制文件可以位于任何位置,在本例中使用 C:\go-bin。

  1. C:\go-bin创建一个文件夹。
  2. 右键点击 Start 并点击 Control Panel
  3. 选择 系统和安全性 ,然后点击 系统
  4. 在左侧的菜单中选择高级系统设置并点击底部的环境变量按钮。
  5. 变量部分选择路径并点编辑
  6. 新建并输入C:\go-bin ,或者点击 浏览 并选择目录,然后点击 确定
为 Windows 10 设置 PATH 变量

使用搜索编辑 环境变量

  1. 点击 搜索 并输入 env 或者 environment
  2. 选择为您的帐户编辑环境变量
  3. 变量部分选择路径并点编辑
  4. 新建并输入C:\go-bin ,或者点击 浏览 并选择目录,然后点击 确定

2.3.3. 在 macOS 中安装 odo

2.3.3.1. 二进制安装

# 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

2.3.3.2. 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'
# chmod +x /usr/local/bin/odo

2.4. 在受限环境中使用 odo

2.4.1. 受限环境中的 odo

要在断开连接的 OpenShift Container Platform 集群或受限环境中置备的集群中运行 odo ,集群管理员需要创建带有registry 镜像(mirror)的集群。

要在断开连接的集群中工作,必须首先将 odo init 镜像推送到集群的 registry 中,然后使用 ODO_BOOTSTRAPPER_IMAGE 环境变量覆盖 odo init 镜像路径。

在推送 odo init镜像后,您需要为 registry 中的支持的构建程序镜像(builder image)在本地创建一个镜像(mirror)覆盖 registry 镜像(mirror),然后创建您的应用程序。构建程序镜像是为应用程序配置运行时环境所必需的,它还包含构建应用程序所需的构建工具,例如:用于 Node.js 的 npm 或用于 Java 的 Maven。一个 registry 镜像(mirror)会包含应用程序所需的所有依赖项。

2.4.2. 将 odo init 镜像推送到受限集群的 registry 中

根据集群和操作系统的配置,您可以将 odo init 镜像推送到一个 registry 镜像(mirror)中,或直接推送到内部 registry。

先决条件

  • 在客户端操作系统上安装 oc
  • 在客户端操作系统中安装 odo
  • 访问带有已配置的内部 registry 或 registry 镜像(mirror)的 OpenShift Container Platform 受限集群。

2.4.2.1. 将 odo init 镜像推送到镜像 (mirror) registry

根据您的操作系统,您可以将 odo init 镜像推送到带有 registry 镜像(mirror)的集群中,如下所示:

2.4.2.1.1. 将 init 镜像推送到 Linux 上的镜像 registry

流程

  1. 使用 base64 对您的镜像 registry 的 root 认证授权 (CA) 内容进行编码:

    $ echo <content_of_additional_ca> | base64 -d > disconnect-ca.crt
  2. 将编码的 root CA 证书复制到适当的位置:

    $ sudo cp ./disconnect-ca.crt /etc/pki/ca-trust/source/anchors/<mirror-registry>.crt
  3. 信任客户端平台中的 CA,并登录 OpenShift Container Platform 镜像 registry:

    $ sudo update-ca-trust enable && sudo systemctl daemon-reload && sudo systemctl restart / docker && docker login <mirror-registry>:5000 -u <username> -p <password>
  4. odo init 镜像进行镜像(mirror):

    $ oc image mirror registry.access.redhat.com/openshiftdo/odo-init-image-rhel7:<tag> <mirror-registry>:5000/openshiftdo/odo-init-image-rhel7:<tag>
  5. 设置 ODO_BOOTSTRAPPER_IMAGE 环境变量来覆盖默认的 odo init 镜像路径:

    $ export ODO_BOOTSTRAPPER_IMAGE=<mirror-registry>:5000/openshiftdo/odo-init-image-rhel7:<tag>
2.4.2.1.2. 将 init 镜像推送到 MacOS 上的镜像 registry

流程

  1. 使用 base64 对您的镜像 registry 的 root 认证授权 (CA) 内容进行编码:

    $ echo <content_of_additional_ca> | base64 -d > disconnect-ca.crt
  2. 将编码的 root CA 证书复制到适当的位置:

    1. 使用 Docker UI 重启 Docker。
    2. 运行以下命令:

      $ docker login <mirror-registry>:5000 -u <username> -p <password>
  3. odo init 镜像进行镜像(mirror):

    $ oc image mirror registry.access.redhat.com/openshiftdo/odo-init-image-rhel7:<tag> <mirror-registry>:5000/openshiftdo/odo-init-image-rhel7:<tag>
  4. 设置 ODO_BOOTSTRAPPER_IMAGE 环境变量来覆盖默认的 odo init 镜像路径:

    $ export ODO_BOOTSTRAPPER_IMAGE=<mirror-registry>:5000/openshiftdo/odo-init-image-rhel7:<tag>
2.4.2.1.3. 将 init 镜像推送到 Windows 上的镜像 registry

流程

  1. 使用 base64 对您的镜像 registry 的 root 认证授权 (CA) 内容进行编码:

    PS C:\> echo <content_of_additional_ca> | base64 -d > disconnect-ca.crt
  2. 作为管理员,请执行以下命令将编码的 root CA 证书复制到适当的位置:

    PS C:\WINDOWS\system32> certutil -addstore -f "ROOT" disconnect-ca.crt
  3. 信任客户端平台中的 CA,并登录 OpenShift Container Platform 镜像 registry:

    1. 使用 Docker UI 重启 Docker。
    2. 运行以下命令:

      PS C:\WINDOWS\system32> docker login <mirror-registry>:5000 -u <username> -p <password>
  4. odo init 镜像进行镜像(mirror):

    PS C:\> oc image mirror registry.access.redhat.com/openshiftdo/odo-init-image-rhel7:<tag> <mirror-registry>:5000/openshiftdo/odo-init-image-rhel7:<tag>
  5. 设置 ODO_BOOTSTRAPPER_IMAGE 环境变量来覆盖默认的 odo init 镜像路径:

    PS C:\> $env:ODO_BOOTSTRAPPER_IMAGE="<mirror-registry>:5000/openshiftdo/odo-init-image-rhel7:<tag>"

2.4.2.2. 将 odo init 镜像直接推送到内部 registry

如果集群允许镜像直接推送到内部 registry,请将 odo init 镜像推送到 registry:

2.4.2.2.1. 在 Linux 中直接推送 init 镜像

流程

  1. 启用默认路由:

    $ oc patch configs.imageregistry.operator.openshift.io cluster -p '{"spec":{"defaultRoute":true}}' --type='merge' -n openshift-image-registry
  2. 获取通配符路由 CA:

    $ oc get secret router-certs-default -n openshift-ingress -o yaml
    apiVersion: v1
    data:
      tls.crt: **************************
      tls.key: ##################
    kind: Secret
    metadata:
      [...]
    type: kubernetes.io/tls
  3. 使用 base64 对您的镜像 registry 的 root 认证授权 (CA) 内容进行编码:

    $ echo <tls.crt> | base64 -d > ca.crt
  4. 在客户端平台中信任 CA:

    $ 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
  5. 登录到内部 registry:

    $ 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)
  6. 推送 odo init 镜像:

    $ 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>
  7. 设置 ODO_BOOTSTRAPPER_IMAGE 环境变量来覆盖默认的 odo init 镜像路径:

    $ export ODO_BOOTSTRAPPER_IMAGE=<registry_path>/openshiftdo/odo-init-image-rhel7:1.0.1
2.4.2.2.2. 在 MacOS 上直接推送 init 镜像

流程

  1. 启用默认路由:

    $ oc patch configs.imageregistry.operator.openshift.io cluster -p '{"spec":{"defaultRoute":true}}' --type='merge' -n openshift-image-registry
  2. 获取通配符路由 CA:

    $ oc get secret router-certs-default -n openshift-ingress -o yaml
    apiVersion: v1
    data:
      tls.crt: **************************
      tls.key: ##################
    kind: Secret
    metadata:
      [...]
    type: kubernetes.io/tls
  3. 使用 base64 对您的镜像 registry 的 root 认证授权 (CA) 内容进行编码:

    $ echo <tls.crt> | base64 -d > ca.crt
  4. 在客户端平台中信任 CA:

    $ sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ca.crt
  5. 登录到内部 registry:

    $ 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)
  6. 推送 odo init 镜像:

    $ 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>
  7. 设置 ODO_BOOTSTRAPPER_IMAGE 环境变量来覆盖默认的 odo init 镜像路径:

    $ export ODO_BOOTSTRAPPER_IMAGE=<registry_path>/openshiftdo/odo-init-image-rhel7:1.0.1
2.4.2.2.3. 在 Windows 上直接推送 init 镜像

流程

  1. 启用默认路由:

    PS C:\> oc patch configs.imageregistry.operator.openshift.io cluster -p '{"spec":{"defaultRoute":true}}' --type='merge' -n openshift-image-registry
  2. 获取通配符路由 CA:

    PS C:\> oc get secret router-certs-default -n openshift-ingress -o yaml
    apiVersion: v1
    data:
      tls.crt: **************************
      tls.key: ##################
    kind: Secret
    metadata:
      [...]
    type: kubernetes.io/tls
  3. 使用 base64 对您的镜像 registry 的 root 认证授权 (CA) 内容进行编码:

    PS C:\> echo <tls.crt> | base64 -d > ca.crt
  4. 作为管理员,请执行以下命令在客户端平台中信任 CA:

    PS C:\WINDOWS\system32> certutil -addstore -f "ROOT" ca.crt
  5. 登录到内部 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)
  6. 推送 odo init 镜像:

    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>
  7. 设置 ODO_BOOTSTRAPPER_IMAGE 环境变量来覆盖默认的 odo init 镜像路径:

    PS C:\> $env:ODO_BOOTSTRAPPER_IMAGE="<registry_path>/openshiftdo/odo-init-image-rhel7:<tag>"

2.4.3. 在断开连接的集群中创建和部署组件

init 镜像推送到具有镜像(mirror) registry 的集群中后,您必须使用 oc 工具为应用程序所需的构建程序镜像创建一个镜像(mirror),使用环境变量覆盖镜像 registry,然后创建组件。

先决条件

2.4.3.1. 为支持的构建器镜像创建一个镜像(mirror)

要使用 Node.js 依赖项的 npm 软件包及 Java 依赖项的 Maven 软件包,并为应用程序配置运行时环境,您必须从镜像 registry 中镜像相应的构建器镜像。

流程

  1. 验证所需镜像标签没有导入:

    $ oc describe is nodejs -n openshift
    Name:                   nodejs
    Namespace:              openshift
    [...]
    
    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
    
      ! error: Import failed (NotFound): dockerimage.image.openshift.io "<mirror-registry>:<port>/rhoar-nodejs/nodejs-10:latest" not found
          About an hour ago
    
    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
    
      ! error: Import failed (NotFound): dockerimage.image.openshift.io "<mirror-registry>:<port>/rhscl/nodejs-10-rhel7:latest" not found
          About an hour ago
    
    [...]
  2. 将支持的镜像标签镜像到私有 registry:

    $ oc image mirror registry.access.redhat.com/rhscl/nodejs-10-rhel7:<tag> <private_registry>/rhscl/nodejs-10-rhel7:<tag>
  3. 导入镜像:

    $ oc tag <mirror-registry>:<port>/rhscl/nodejs-10-rhel7:<tag> nodejs-10-rhel7:latest --scheduled

    您必须定期重新导入镜像。--scheduled 标志启用镜像自动重新导入。

  4. 验证带有指定标签的镜像已被导入:

    $ oc describe is nodejs -n openshift
    Name:                   nodejs
    [...]
    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
    
      * <mirror-registry>:<port>/rhscl/nodejs-10-rhel7@sha256:d669ecbc11ac88293de50219dae8619832c6a0f5b04883b480e073590fab7c54
          3 minutes ago
    
    [...]

2.4.3.2. mirror registry 介绍

要从私有 mirror registry 中为 Node.js 依赖项下载 npm 软件包,及为 Java 依赖项下载 Maven 软件包,您必须在集群中创建并配置 mirror npm 或 Maven registry。然后您可以覆盖现有组件上的 mirror registry,或覆盖创建新组件时的 mirror registry。

流程

  • 覆盖现有组件上的 mirror registry:

    $ odo config set --env NPM_MIRROR=<npm_mirror_registry>
  • 覆盖创建组件时的 mirror registry:

    $ odo component create nodejs --env NPM_MIRROR=<npm_mirror_registry>

2.4.3.3. 使用 odo 创建 Node.js 应用程序

要创建一个 Node.js 组件,请下载 Node.js 应用程序并使用 odo将源代码推送到您的集群中。

流程

  1. 将当前目录变为您的应用程序的目录:

    $ cd <directory name>
  2. 将类型 Node.js 的组件添加到应用程序中:

    $ odo create nodejs
    注意

    默认情况下使用最新的镜像。也可以使用 odo create openshift/nodejs:8 明确指定一个镜像版本。

  3. 将初始源代码推送到组件中:

    $ odo push

    现在,您的组件已被部署到 OpenShift Container Platform 中。

  4. 创建一个 URL,按以下方法在本地配置文件中添加条目:

    $ odo url create --port 8080
  5. 推送更改。这会在集群中创建一个 URL。

    $ odo push
  6. 列出用于检查组件所需 URL 的 URL。

    $ odo url list
  7. 使用生成的 URL 查看部署的应用程序。

    $ curl <URL>

2.5. 使用 odo 创建单组件应用程序

使用 odo,您可以在 OpenShift Container Platform 集群中从终端创建和部署应用程序。

先决条件

  • 已安装了 odo
  • 有一个正在运行的 OpenShift Container Platform 集群。您可以使用 CodeReady Containers (CRC) 来快速部署一个本地的 OpenShift Container Platform 集群。

2.5.1. 创建一个项目

创建一个项目来在一个独立的空间内保存源代码、测试并对库进行管理。

流程

  1. 登陆到一个OpenShift Container Platform集群。

    $ odo login -u developer -p developer
  2. 创建一个项目:

    $ odo project create myproject
     ✓  Project 'myproject' is ready for use
     ✓  New project created and now using project : myproject

2.5.2. 使用 odo 创建 Node.js 应用程序

要创建一个 Node.js 组件,请下载 Node.js 应用程序并使用 odo将源代码推送到您的集群中。

流程

  1. 为您的组件创建一个新目录:

    $ mkdir my_components $$ cd my_components
  2. 下载示例 Node.js 应用程序:

    $ git clone https://github.com/openshift/nodejs-ex
  3. 将当前目录变为您的应用程序的目录:

    $ cd <directory name>
  4. 将类型 Node.js 的组件添加到应用程序中:

    $ odo create nodejs
    注意

    默认情况下使用最新的镜像。也可以使用 odo create openshift/nodejs:8 明确指定一个镜像版本。

  5. 将初始源代码推送到组件中:

    $ odo push

    现在,您的组件已被部署到 OpenShift Container Platform 中。

  6. 创建一个 URL,按以下方法在本地配置文件中添加条目:

    $ odo url create --port 8080
  7. 推送更改。这会在集群中创建一个 URL。

    $ odo push
  8. 列出用于检查组件所需 URL 的 URL。

    $ odo url list
  9. 使用生成的 URL 查看部署的应用程序。

    $ curl <URL>

2.5.3. 修改应用程序代码

您可以修改应用程序代码,并将更改应用于 OpenShift Container Platform 上的应用程序。

  1. 使用文本编辑器编辑 Node.js 目录中的一个布局文件。
  2. 更新您的组件:

    $ odo push
  3. 刷新浏览器中的应用程序查看更改。

2.5.4. 在应用程序组件中添加存储

持久性存储会保留 odo 重启期间的数据。您可以使用 odo storage 命令在组件中添加存储。

流程

  • 在组件中添加存储:

    $ odo storage create nodestorage --path=/opt/app-root/src/storage/ --size=1Gi

您的组件现在有 1 GB 存储。

2.5.5. 添加自定义构建者来指定构建镜像

在 OpenShift Container Platform 中,您可以添加自定义镜像来缩小创建自定义镜像间的差距。

以下示例显示 redhat-openjdk-18 镜像已被成功导入并使用:

先决条件

  • 安装了 OpenShift CLI (oc) 。

流程

  1. 将镜像导入 OpenShift Container Platform:

    $ oc import-image openjdk18 \
    --from=registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift \
    --confirm
  2. 标记(tag)镜像使其可以被 odo 访问:

    $ oc annotate istag/openjdk18:latest tags=builder
  3. 使用 odo 部署镜像:

    $ odo create openjdk18 --git \
    https://github.com/openshift-evangelists/Wild-West-Backend

2.5.6. 使用 OpenShift Service Catalog 将应用程序连接到多个服务

OpenShift Service Catalog 是 Kubernetes 的 Open Service Broker API (OSB API) 的一个实现。您可以使用它将部署在 OpenShift Container Platform 中的应用程序连接到各种服务。

先决条件

  • 有一个正在运行的 OpenShift Container Platform 集群。
  • 在集群中安装并启用该 service catalog。

流程

  • 要列出服务,请使用:

    $ odo catalog list services
  • 要使用 service catalog 相关的操作:

    $ odo service <verb> <servicename>

2.5.7. 删除应用程序

重要

删除应用程序将删除与应用程序关联的所有组件。

流程

  1. 列出当前项目中的应用程序:

    $ odo app list
        The project '<project_name>' has the following applications:
        NAME
        app
  2. 列出与应用程序关联的组件。这些组件将随应用程序一起删除:

    $ odo component list
        APP     NAME                      TYPE       SOURCE        STATE
        app     nodejs-nodejs-ex-elyf     nodejs     file://./     Pushed
  3. 删除应用程序:

    $ odo app delete <application_name>
        ? Are you sure you want to delete the application: <application_name> from project: <project_name>
  4. 使用 Y 确认删除。您可以使用 -f 标记来阻止确认提示。

2.6. 使用 odo 创建多组件应用程序

通过使用 odo,可以创建多组件应用程序,修改该应用程序,并以方便和自动的方式链接其组件。

这个例子描述了如何部署多组件应用程序 - 一个射击游戏。应用程序由一个前端 Node.js 组件和一个后端 Java 组件组成。

先决条件

  • 已安装了 odo
  • 有一个正在运行的 OpenShift Container Platform 集群。开发人员可以使用 CodeReady Containers (CRC) 来快速部署一个本地的 OpenShift Container Platform 集群。
  • 已安装 Maven。

2.6.1. 创建一个项目

创建一个项目来在一个独立的空间内保存源代码、测试并对库进行管理。

流程

  1. 登陆到一个OpenShift Container Platform集群。

    $ odo login -u developer -p developer
  2. 创建一个项目:

    $ odo project create myproject
     ✓  Project 'myproject' is ready for use
     ✓  New project created and now using project : myproject

2.6.2. 部署后端组件

要创建一个 Java 组件,请导入 Java 构建器镜像(builder image),下载 Java 应用程序并使用 odo将源代码推送到您的集群中。

流程

  1. openjdk18 导入集群:

    $ oc import-image openjdk18 \
    --from=registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift --confirm
  2. 将镜像标记为 builder,使它可以被 odo 访问:

    $ oc annotate istag/openjdk18:latest tags=builder
  3. 运行 odo catalog list components 查看创建的镜像:

    $ odo catalog list components
    Odo Supported OpenShift Components:
    NAME          PROJECT       TAGS
    nodejs        openshift     10,8,8-RHOAR,latest
    openjdk18     myproject     latest
  4. 为您的组件创建一个新目录:

    $ mkdir my_components $$ cd my_components
  5. 下载后端应用程序示例:

    $ git clone https://github.com/openshift-evangelists/Wild-West-Backend backend
  6. 将目录改为后端源目录,检查目录中有正确的文件:

    $ cd backend
    $ ls
    debug.sh  pom.xml  src
  7. 使用 Maven 构建后端源文件以创建一个 JAR 文件:

    $ 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] --------------------------------------
  8. 创建名为 backend的 Java 组件类型组件配置:

    $ odo create openjdk18 backend --binary target/wildwest-1.0.jar
     ✓  Validating component [1ms]
     Please use `odo push` command to create the component with source deployed

    现在,配置文件 config.yaml 位于后端组件的本地目录中,其中包含用于部署的组件信息。

  9. 使用以下方法检查 config.yaml 文件中后端组件的配置设置:

    $ odo config view
    COMPONENT SETTINGS
    ------------------------------------------------
    PARAMETER         CURRENT_VALUE
    Type              openjdk18
    Application       app
    Project           myproject
    SourceType        binary
    Ref
    SourceLocation    target/wildwest-1.0.jar
    Ports             8080/TCP,8443/TCP,8778/TCP
    Name              backend
    MinMemory
    MaxMemory
    DebugPort
    Ignore
    MinCPU
    MaxCPU
  10. 将组件推送到 OpenShift Container Platform 集群。

    $ odo push
    Validation
     ✓  Checking component [6ms]
    
    Configuration changes
     ✓  Initializing component
     ✓  Creating component [124ms]
    
    Pushing to component backend of type binary
     ✓  Checking files for pushing [1ms]
     ✓  Waiting for component to start [48s]
     ✓  Syncing files to the component [811ms]
     ✓  Building component [3s]

    使用 odo push,OpenShift Container Platform 创建一个容器来托管后端组件,将容器部署到运行在 OpenShift Container Platform 集群上的 Pod 中,并启动 backend 组件。

  11. 验证:

    • odo 中操作的状态:

      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

2.6.3. 部署前端组件

要创建并部署前端组件,请下载 Node.js 应用程序并使用 odo将源代码推送到集群中。

流程

  1. 下载前端应用程序示例:

    $ git clone https://github.com/openshift/nodejs-ex
  2. 将当前目录改为前端目录:

    $ cd <directory-name>
  3. 列出目录的内容,以查看前端是一个 Node.js 应用程序。

    $ ls
    assets  bin  index.html  kwww-frontend.iml  package.json  package-lock.json  playfield.png  README.md  server.js
    注意

    前端组件使用解释语言 (Node.js) 编写,不需要构建它。

  4. 创建名为 frontend的 Node.js 组件类型组件配置:

    $ odo create nodejs frontend
     ✓  Validating component [5ms]
    Please use `odo push` command to create the component with source deployed
  5. 将组件推送到正在运行的容器中。

    $ odo push
    Validation
     ✓  Checking component [8ms]
    
    Configuration changes
     ✓  Initializing component
     ✓  Creating component [83ms]
    
    Pushing to component frontend of type local
     ✓  Checking files for pushing [2ms]
     ✓  Waiting for component to start [45s]
     ✓  Syncing files to the component [3s]
     ✓  Building component [18s]
     ✓  Changes successfully pushed to component

2.6.4. 连接两个组件

集群中运行的组件需要连接才能进行交互。OpenShift Container Platform 提供了链接机制以发布一个程序到其客户端的通信绑定。

流程

  1. 列出在集群中运行的所有组件:

    $ odo list
    APP     NAME         TYPE          SOURCE                             STATE
    app     backend      openjdk18     file://target/wildwest-1.0.jar     Pushed
    app     frontend     nodejs        file://./                          Pushed
  2. 将当前的前端组件链接到后端:

    $ odo link backend --port 8080
     ✓  Component backend has been successfully linked from the component frontend
    
    Following environment variables were added to frontend component:
    - COMPONENT_BACKEND_HOST
    - COMPONENT_BACKEND_PORT

    后端组件的配置信息被添加到前端组件中,前端组件重新启动。

2.6.5. 公开组件

流程

  1. 为应用程序创建一个外部 URL:

    $ cd frontend
    $ odo url create frontend --port 8080
     ✓  URL frontend created for component: frontend
    
    To create URL on the OpenShift  cluster, use `odo push`
  2. 应用更改:

    $ odo push
    Validation
     ✓  Checking component [21ms]
    
    Configuration changes
     ✓  Retrieving component data [35ms]
     ✓  Applying configuration [29ms]
    
    Applying URL changes
     ✓  URL frontend: http://frontend-app-myproject.192.168.42.79.nip.io created
    
    Pushing to component frontend of type local
     ✓  Checking file changes for pushing [1ms]
     ✓  No file changes detected, skipping build. Use the '-f' flag to force the build.
  3. 在一个浏览器中使用 URL 来查看应用程序。
注意

如果一个应用程序需要一个有效的服务账户( Service Account)来访问 OpenShift Container Platform 命名空间并删除活跃的 pod 时,后端组件的 odo log 中可能会出现以下错误:

Message: Forbidden!Configured service account doesn’t have access.Service account may have been revoked

要解决这个错误,请为 Service Account 角色添加权限:

$ oc policy add-role-to-group view system:serviceaccounts -n <project>
$ oc policy add-role-to-group edit system:serviceaccounts -n <project>

不要在生产环境集群中使用它。

2.6.6. 修改正在运行的应用程序

流程

  1. 将本地目录改为前端目录:

    $ cd ~/frontend
  2. 使用以下方法监控文件系统中的更改:

    $ odo watch
  3. 编辑 index.html 文件,为游戏更改显示的名称。

    注意

    在 odo 可以识别更改前可能会有一些延迟。

    odo 将更改推送到前端组件,并将其状态输出到终端:

    File /root/frontend/index.html changed
    File  changed
    Pushing files...
     ✓  Waiting for component to start
     ✓  Copying files to component
     ✓  Building component
  4. 在浏览器中刷新应用程序页面。现在会显示新名称。

2.6.7. 删除应用程序

重要

删除应用程序将删除与应用程序关联的所有组件。

流程

  1. 列出当前项目中的应用程序:

    $ odo app list
        The project '<project_name>' has the following applications:
        NAME
        app
  2. 列出与应用程序关联的组件。这些组件将随应用程序一起删除:

    $ odo component list
        APP     NAME                      TYPE       SOURCE        STATE
        app     nodejs-nodejs-ex-elyf     nodejs     file://./     Pushed
  3. 删除应用程序:

    $ odo app delete <application_name>
        ? Are you sure you want to delete the application: <application_name> from project: <project_name>
  4. 使用 Y 确认删除。您可以使用 -f 标记来阻止确认提示。

2.7. 创建带有数据库的应用程序

这个示例描述了如何部署和连接数据库到前端应用程序。

先决条件

  • 已安装了 odo
  • 已安装oc 客户端。
  • 有一个正在运行的 OpenShift Container Platform 集群。开发人员可以使用 CodeReady Containers (CRC) 来快速部署一个本地的 OpenShift Container Platform 集群。
  • 服务目录被启用。

2.7.1. 创建一个项目

创建一个项目来在一个独立的空间内保存源代码、测试并对库进行管理。

流程

  1. 登陆到一个OpenShift Container Platform集群。

    $ odo login -u developer -p developer
  2. 创建一个项目:

    $ odo project create myproject
     ✓  Project 'myproject' is ready for use
     ✓  New project created and now using project : myproject

2.7.2. 部署前端组件

要创建并部署前端组件,请下载 Node.js 应用程序并使用 odo将源代码推送到集群中。

流程

  1. 下载前端应用程序示例:

    $ git clone https://github.com/openshift/nodejs-ex
  2. 将当前目录改为前端目录:

    $ cd <directory-name>
  3. 列出目录的内容,以查看前端是一个 Node.js 应用程序。

    $ ls
    assets  bin  index.html  kwww-frontend.iml  package.json  package-lock.json  playfield.png  README.md  server.js
    注意

    前端组件使用解释语言 (Node.js) 编写,不需要构建它。

  4. 创建名为 frontend的 Node.js 组件类型组件配置:

    $ odo create nodejs frontend
     ✓  Validating component [5ms]
    Please use `odo push` command to create the component with source deployed
  5. 创建一个 URL 来访问前台接口。

    $ odo url create myurl
     ✓  URL myurl created for component: nodejs-nodejs-ex-pmdp
  6. 将组件推送到 OpenShift Container Platform 集群。

    $ odo push
    Validation
     ✓  Checking component [7ms]
    
     Configuration changes
     ✓  Initializing component
     ✓  Creating component [134ms]
    
     Applying URL changes
     ✓  URL myurl: http://myurl-app-myproject.192.168.42.79.nip.io created
    
     Pushing to component nodejs-nodejs-ex-mhbb of type local
     ✓  Checking files for pushing [657850ns]
     ✓  Waiting for component to start [6s]
     ✓  Syncing files to the component [408ms]
     ✓  Building component [7s]
     ✓  Changes successfully pushed to component

2.7.3. 以互动模式部署数据库

odo 提供了一个简化部署的命令行互动模式。

流程

  • 运行互动模式并回答提示:

    $ odo service create
    ? Which kind of service do you wish to create database
    ? Which database service class should we use mongodb-persistent
    ? Enter a value for string property DATABASE_SERVICE_NAME (Database Service Name): mongodb
    ? Enter a value for string property MEMORY_LIMIT (Memory Limit): 512Mi
    ? Enter a value for string property MONGODB_DATABASE (MongoDB Database Name): sampledb
    ? Enter a value for string property MONGODB_VERSION (Version of MongoDB Image): 3.2
    ? Enter a value for string property VOLUME_CAPACITY (Volume Capacity): 1Gi
    ? Provide values for non-required properties No
    ? How should we name your service  mongodb-persistent
    ? Output the non-interactive version of the selected options No
    ? Wait for the service to be ready No
     ✓  Creating service [32ms]
     ✓  Service 'mongodb-persistent' was created
    Progress of the provisioning will not be reported and might take a long time.
    You can see the current status by executing 'odo service list'
注意

您的密码或用户名将作为环境变量传递给前端的应用程序。

2.7.4. 手动部署数据库

  1. 列出可用服务:

    $ odo catalog list services
    NAME                         PLANS
    django-psql-persistent       default
    jenkins-ephemeral            default
    jenkins-pipeline-example     default
    mariadb-persistent           default
    mongodb-persistent           default
    mysql-persistent             default
    nodejs-mongo-persistent      default
    postgresql-persistent        default
    rails-pgsql-persistent       default
  2. 选择 mongodb-persistent 服务类型,并查看所需参数:

    $ odo catalog describe service mongodb-persistent
      ***********************        | *****************************************************
      Name                           | default
      -----------------              | -----------------
      Display Name                   |
      -----------------              | -----------------
      Short Description              | Default plan
      -----------------              | -----------------
      Required Params without a      |
      default value                  |
      -----------------              | -----------------
      Required Params with a default | DATABASE_SERVICE_NAME
      value                          | (default: 'mongodb'),
                                     | MEMORY_LIMIT (default:
                                     | '512Mi'), MONGODB_VERSION
                                     | (default: '3.2'),
                                     | MONGODB_DATABASE (default:
                                     | 'sampledb'), VOLUME_CAPACITY
                                     | (default: '1Gi')
      -----------------              | -----------------
      Optional Params                | MONGODB_ADMIN_PASSWORD,
                                     | NAMESPACE, MONGODB_PASSWORD,
                                     | MONGODB_USER
  3. 指定所需参数,并等待数据库部署:

    $ 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

2.7.5. 将数据库连接到前端应用程序

  1. 将数据库连接到前端服务中:

    $ odo link mongodb-persistent
     ✓  Service mongodb-persistent has been successfully linked from the component nodejs-nodejs-ex-mhbb
    
    Following environment variables were added to nodejs-nodejs-ex-mhbb component:
    - database_name
    - password
    - uri
    - username
    - admin_password
  2. 查看 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.2$ env
    uri=mongodb://172.30.126.3:27017
    password=dHIOpYneSkX3rTLn
    database_name=sampledb
    username=user43U
    admin_password=NCn41tqmx7RIqmfv
    sh-4.2$
  3. 在浏览器中打开 URL ,并在右下角记录数据库配置:

    $ odo url list
    Request information
    Page view count: 24
    
    DB Connection Info:
    Type:	MongoDB
    URL:	mongodb://172.30.126.3:27017/sampledb

2.7.6. 删除应用程序

重要

删除应用程序将删除与应用程序关联的所有组件。

流程

  1. 列出当前项目中的应用程序:

    $ odo app list
        The project '<project_name>' has the following applications:
        NAME
        app
  2. 列出与应用程序关联的组件。这些组件将随应用程序一起删除:

    $ odo component list
        APP     NAME                      TYPE       SOURCE        STATE
        app     nodejs-nodejs-ex-elyf     nodejs     file://./     Pushed
  3. 删除应用程序:

    $ odo app delete <application_name>
        ? Are you sure you want to delete the application: <application_name> from project: <project_name>
  4. 使用 Y 确认删除。您可以使用 -f 标记来阻止确认提示。

2.8. 示例应用程序

odo 提供与 OpenShift 组件类型目录中列出的语言或运行时的部分兼容性。例如:

NAME        PROJECT       TAGS
dotnet      openshift     2.0,latest
httpd       openshift     2.4,latest
java        openshift     8,latest
nginx       openshift     1.10,1.12,1.8,latest
nodejs      openshift     0.10,4,6,8,latest
perl        openshift     5.16,5.20,5.24,latest
php         openshift     5.5,5.6,7.0,7.1,latest
python      openshift     2.7,3.3,3.4,3.5,3.6,latest
ruby        openshift     2.0,2.2,2.3,2.4,latest
wildfly     openshift     10.0,10.1,8.1,9.0,latest
注意

对于 odo 1.0,Java 和 Node.js 是官方支持的组件类型。运行 odo catalog list components 来验证官方支持的组件类型。

要通过 web 访问该组件,请使用 odo url create 创建一个 URL。

2.8.1. Git 软件仓库示例

2.8.1.1. httpd

这个示例在 CentOS 7 上使用 httpd 构建并提供静态内容。有关使用这个构建器镜像的更多信息,包括 OpenShift Container Platform 的注意事项,请查看 Apache HTTP 服务器容器镜像存储库

$ odo create httpd --git https://github.com/openshift/httpd-ex.git

2.8.1.2. java

这个示例在 CentOS 7 上构建并运行 fat JAR Java 应用程序。有关使用这个构建器镜像的更多信息,包括 OpenShift Container Platform 的注意事项,请参见 Java S2I Builder image

$ odo create java --git https://github.com/spring-projects/spring-petclinic.git

2.8.1.3. nodejs

在 CentOS 7 中构建并运行 Node.js 应用程序。有关使用这个构建器镜像的更多信息,包括 OpenShift Container Platform 的注意事项,请参见 Node.js 8 container image

$ odo create nodejs --git https://github.com/openshift/nodejs-ex.git

2.8.1.4. Perl

这个示例在 CentOS 7 中构建并运行 Perl 应用程序。有关使用这个构建器镜像的更多信息,包括 OpenShift Container Platform 的注意事项,请查看 Perl 5.26 容器镜像

$ odo create perl --git https://github.com/openshift/dancer-ex.git

2.8.1.5. php

这个示例在 CentOS 7 中构建并运行 PHP 应用程序。有关使用这个构建器镜像的更多信息,包括 OpenShift Container Platform 的注意事项,请参见 PHP 7.1 Docker image

$ odo create php --git https://github.com/openshift/cakephp-ex.git

2.8.1.6. Python

这个示例在 CentOS 7 中构建并运行 Python 应用程序。有关使用这个构建器镜像的更多信息,包括 OpenShift Container Platform 的注意事项,请查看 Python 3.6 容器镜像

$ odo create python --git https://github.com/openshift/django-ex.git

2.8.1.7. Ruby

这个示例在 CentOS 7 中构建并运行 Ruby 应用程序。有关使用这个构建器镜像的更多信息,包括 OpenShift Container Platform 的注意事项,请参见 Ruby 2.5 container image

$ odo create ruby --git https://github.com/openshift/ruby-ex.git

2.8.1.8. WildFly

这个示例在 CentOS 7 中构建并运行 WildFly 应用程序。有关使用这个构建器镜像的更多信息,包括 OpenShift Container Platform 的注意事项,请 查看 Wilfly - OpenShift 的 CentOS Docker 镜像

$ odo create wildfly --git https://github.com/openshift/openshift-jee-sample.git

2.8.2. 二进制示例

2.8.2.1. java

Java 可以用来部署二进制工件,如下:

$ 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.8.2.2. WildFly

WildFly 可以用来部署二进制应用程序,如下:

$ git clone https://github.com/openshiftdemos/os-sample-java-web.git
$ cd os-sample-java-web
$ mvn package
$ cd ..
$ mkdir example && cd example
$ mv ../os-sample-java-web/target/ROOT.war example.war
$ odo create wildfly --binary example.war

2.9. 管理环境变量

odoconfig 文件中存储特定于组件的配置和环境变量。您可以使用 odo config 命令为组件设置、取消设置和列出环境变量,而无需修改 config 文件。

2.9.1. 设置和取消设置环境变量

流程

  • 在组件中设置环境变量:

    $ odo config set --env <variable>=<value>
  • 在组件中取消设置环境变量:

    $ odo config unset --env <variable>
  • 列出组件中的所有环境变量:

    $ odo config view

2.10. 配置 odo CLI

2.10.1. 使用命令完成

注意

目前只有 bash 、zsh 和 shell 支持命令完成。

odo 提供基于用户输入的智能命令参数完成功能。要做到这一点,odo 需要与执行 shell 集成。

流程

  • 要自动安装命令完成:

    1. 运行:

      $ odo --complete
    2. 提示安装完成 hook 时按 y 键。
  • 要手动安装完成 hook,请在 shell 配置文件中添加 complete -o nospace -C <full path to your odo binary> odo 。在修改了 shell 配置文件后,重启 shell。
  • 禁用完成:

    1. 运行:

      $ odo --uncomplete
    2. 提示后按 y 卸载完成 hook。
注意

如果您重命名 odo 可执行文件或将其移动到其他目录中,请重新启用命令完成。

2.10.2. 忽略文件或特征

您可以通过修改应用程序根目录中的 .odoignore 文件来配置要忽略的文件或模式列表。这适用于 odo pushodo watch

如果 .odoignore 文件 存在,则会使用 .gitignore 文件来忽略特定的文件和文件夹。

要忽略 .git 文件、任意带有 .js 扩展名的文件,以及 tests 目录,在 .odoignore.gitignore 文件中添加以下内容:

.git
*.js
tests/

.odoignore 文件 允许任何 glob 表达式。

2.11. odo CLI 参考指南

2.11.1. 基本 odo CLI 命令

2.11.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.11.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.11.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.11.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
  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 文件

表 2.2. 可用的本地参数:

Application

组件需要成为其一部分的应用程序名称

CPU

组件可消耗的最少和最多 CPU

Ignore

进行 push 和 watch 时是否使用 .odoignore 文件

MaxCPU

组件可消耗的最多 CPU

MaxMemory

组件可消耗的最大内存

Memory

组件可消耗的最小和最大内存

MinCPU

组件可消耗的最小 CPU

MinMemory

组件提供的最小内存

名称

组件的名称

Ports

要在组件中打开的端口

project

组件所属项目的名称

Ref

用于从 git 源创建组件的 git ref

SourceLocation

该路径表示二进制文件或者 git 源的位置

SourceType

组件源的类型 - git/binary/local

存储

组件的存储

类型

组件的类型

URL

访问该组件的 URL

2.11.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

  # 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.11.1.6. delete

删除一个现有组件。

使用 delete 的示例

  # Delete component named 'frontend'.
  odo delete frontend
  odo delete frontend --all

2.11.1.7. describe

描述指定组件。

使用 describe 的示例

  # Describe nodejs component
  odo describe nodejs

2.11.1.9. list

列出当前应用程序中的所有组件。

使用 list 的示例

  # List all components in the application
  odo list

2.11.1.10. log

获取指定组件的日志。

使用 log 的示例

  # Get the logs for the nodejs component
  odo log nodejs

2.11.1.11. 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.11.1.12. logout

登出当前 OpenShift Container Platform 会话。

使用 logout 的示例

  # Log out
  odo logout

2.11.1.13. 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

  # Unset a preference value in the global preference
  odo preference unset  UpdateNotification
  odo preference unset  NamePrefix
  odo preference unset  Timeout

注意

默认情况下,全局首选项文件的路径为 ~/.odo/preferece.yaml,它被存储在环境变量 GLOBALODOCONFIG 中。您可以通过为环境变量设置一个新的值来指定一个新的自定义的首选项路径,例如: GLOBALODOCONFIG="new_path/preference.yaml"

表 2.3. 可用参数:

NamePrefix

默认前缀是当前目录的名称。使用这个值设置默认名称前缀。

timeout

OpenShift Container Platform 服务器的连接检查超时时间(以秒为单位)。

UpdateNotification

控制是否显示更新通知。

2.11.1.14. 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.11.1.15. 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.11.1.16. 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.11.1.17. 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

2.11.1.19. 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.11.1.20. 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

使用这个命令生成的 URL 可以从集群外访问部署的组件。

2.11.1.21. utils

终端命令和修改 odo 配置的工具。

使用 utils 的示例

  # Bash terminal PS1 support
  source <(odo utils terminal bash)

  # Zsh terminal PS1 support
  source <(odo utils terminal zsh)

2.11.1.22. version

打印客户端版本信息。

使用 version 的示例

  # Print the client version of odo
  odo version

2.11.1.23. 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

2.12. odo 1.0 发行注记

2.12.1. odo 1.0 中的主要特性

odo 1.0 提供了在 OpenShift Container Platform 上开发应用程序的简单方法。odo 完全基于客户端,且不需要 OpenShift Container Platform 集群中的服务器。

odo 1.0 具有以下特点:

  • 简单的语法,围绕开发人员熟悉的概念(比如项目、应用程序和组件)进行设计。
  • 与组件类型的 OpenShift 目录中的任何语言或运行兼容。
  • 使用自定义镜像构建器添加自定义组件类型。
  • Java 和 Node.js 组件类型的官方支持。
  • 服务目录(Service catalog)允许用户将部署在 OpenShift Container Platform 集群中的应用程序连接到 Template Service Broker。
  • odo service create - 一个互动模式,它可指导用户完成创建应用程序的过程。
  • odo watch - 自动检测本地代码更改并实时应用组件更改的功能。

2.12.2. 获得支持

文档

如果您在文档中发现错误或者有改进文档的建议,请在 Bugzilla中提交问题。选择 OpenShift Container Platform 产品类型和 Documentation 组件类型。

产品

如果您发现了错误,遇到问题或者有改进 odo 功能的建议,请在 Bugzilla中提交问题。选择 OpenShift Container Platform 产品类型和 odo 组件类型。

请尽量提供描述此问题的更多细节。

2.12.3. odo 1.1.0 中的技术预览功能

注意

技术预览功能没有被完全支持,可能无法正常工作,且不适用于在生产环境中部署。我们鼓励用户在技术预览功能获得全面支持前提供反馈意见和功能建议。

  • odo debug 可让用户为 OpenShift Container Platform 上运行的 Pod 中运行的组件附加一个本地调试程序。

    使用 odo debug port-forward 启动端口转发。

    使用 odo config set DebugPort 9292 指定调试代理应该运行的远程端口。

    使用 odo debug port-forward --local-port 9292 指定端口转发的本地端口。

2.12.4. 已知问题

  • Bug 1760573 活跃的指针没有指向当前活跃的项目。
  • Bug 1760574 已删除的命名空间仍然在 odo project get 命令中列出。
  • Bug 1760575 odo app delete 删除应用程序组件而没有删除服务。
  • Bug 1760577 odo push 在组件名已改变的情况下不会删除 OpenShift 对象。
  • Bug 1760580 catalog list components 不列出指定命名空间的组件。
  • Bug 1760583 odo config unset 没有取消设置一个环境变量,但显示已进行了这个操作。
  • Bug 1760585 当从 $HOME 中运行时,odo delete --all 会删除 `$HOME/.odo` 目录。
  • Bug 1760586 odo delete 在项目被删除及一个组件名称被设置后,会出现一个死循环。
  • Bug 1760587 当一个不存在的命令被使用时,odo 会报告一个无效的 flag。
  • Bug 1760588 odo service create 在 Cygwin 中运行时会崩溃。
  • Bug 1760589 对于 odo push 中的 --context,自动完成功能无法正常工作。
  • Bug 1760590 在 Git BASH for Windows 中,odo login -u developer 在请求时没有隐藏输入的密码。
  • Bug 1761440 在一个项目中不可能创建同一类型的两个服务。
  • Bug 1761442 如果二进制代码位于一个临时文件夹,component create 在使用 --context--binary 时会失败。
  • Bug 1761443 删除的文件不会从 Java 组件中删除。
------------------------ 最后更新:2020 年 5 月 31 日 ------------------------

法律通告

Copyright © 2020 Red Hat, Inc.
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.
Java® is a registered trademark of Oracle and/or its affiliates.
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.
All other trademarks are the property of their respective owners.