7.3. 从 OLM 1.0 中的目录安装 Operator (技术预览)


集群管理员可向其集群添加 目录、或策展 Operator 和 Kubernetes 扩展集合。Operator 作者将其产品发布到这些目录中。当您向集群添加目录时,您可以访问发布到目录中的 Operator 和扩展的版本、补丁和无线更新。

在 Operator Lifecycle Manager (OLM) 1.0 的当前技术预览版本中,您可以使用自定义资源(CR)从 CLI 以声明性方式管理目录和 Operator。

重要

OLM 1.0 只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

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

7.3.1. 先决条件

  • 使用具有 cluster-admin 权限的账户访问 OpenShift Container Platform 集群

    注意

    对于 OpenShift Container Platform 4.14,适用于 OLM 1.0 的流程仅基于 CLI。另外,管理员也可以使用普通方法(如 Import YAMLSearch 页面)在 web 控制台中创建和查看相关对象。但是,现有的 OperatorHubInstalled Operators 页面还不会显示 OLM 1.0 组件。

  • 在集群中启用 TechPreviewNoUpgrade 功能集

    警告

    启用 TechPreviewNoUpgrade 功能集将无法撤消,并防止次版本更新。不建议在生产环境集群中使用这些功能集。

  • 在您的工作站上安装的 OpenShift CLI (oc)

7.3.2. 关于 OLM 1.0 中的目录

您可以使用 catalogd 组件查询 Kubernetes 扩展的目录,如 Operator 和控制器,从而发现可安装的内容。Catalogd 是一个 Kubernetes 扩展,为集群客户端解包目录内容,并是微服务的 Operator Lifecycle Manager (OLM) 1.0 套件的一部分。目前,catalogd 解包要打包并分发为容器镜像的目录内容。

其他资源

7.3.2.1. OLM 1.0 中红帽提供的 Operator 目录

Operator Lifecycle Manager (OLM) 1.0 默认不包括红帽提供的 Operator 目录。如果要在集群中添加红帽提供的目录,请为目录创建一个自定义资源 (CR),并将其应用到集群。以下自定义资源 (CR) 示例演示了如何为 OLM 1.0 创建目录资源。

Red Hat Operator 目录示例

apiVersion: catalogd.operatorframework.io/v1alpha1
kind: Catalog
metadata:
  name: redhat-operators
spec:
  source:
    type: image
    image:
      ref: registry.redhat.io/redhat/redhat-operator-index:v4.14

认证的 Operator 目录示例

apiVersion: catalogd.operatorframework.io/v1alpha1
kind: Catalog
metadata:
  name: certified-operators
spec:
  source:
    type: image
    image:
      ref: registry.redhat.io/redhat/certified-operator-index:v4.14

Community Operators 目录示例

apiVersion: catalogd.operatorframework.io/v1alpha1
kind: Catalog
metadata:
  name: community-operators
spec:
  source:
    type: image
    image:
      ref: registry.redhat.io/redhat/community-operator-index:v4.14

以下命令在集群中添加目录:

命令语法

$ oc apply -f <catalog_name>.yaml 1

1
指定目录 CR,如 redhat-operators.yaml
注意

以下流程使用 Red Hat Operator 目录和 Quay Operator 作为示例。

7.3.3. 关于 OLM 1.0 中的目标版本

在 Operator Lifecycle Manager(OLM)1.0 中,集群管理员在 Operator 的自定义资源(CR)中以声明性方式设置 Operator 的目标版本。

如果在 Operator 的 CR 中指定频道,OLM 1.0 会从指定频道安装最新版本。当向指定的频道发布更新时,OLM 1.0 会自动更新至该频道的最新发行版本。

带有指定频道的 CR 示例

apiVersion: operators.operatorframework.io/v1alpha1
kind: Operator
metadata:
  name: quay-example
spec:
  packageName: quay-operator
  channel: stable-3.8 1

1
安装发布至指定频道的最新发行版本。对频道的更新会自动安装。

如果在 CR 中指定 Operator 的目标版本,OLM 1.0 将安装指定的版本。当在 Operator 的 CR 中指定目标版本时,OLM 1.0 在向目录发布更新时不会更改目标版本。

如果要更新集群中安装的 Operator 版本,您必须手动更新 Operator 的 CR。指定 Operator 的目标版本将 Operator 的版本固定到指定的发行版本。

指定了目标版本的 CR 示例

apiVersion: operators.operatorframework.io/v1alpha1
kind: Operator
metadata:
  name: quay-example
spec:
  packageName: quay-operator
  version: 3.8.12 1

1
指定目标版本。如果要更新集群中安装的 Operator 版本,您必须手动将这个字段更新为所需的目标版本。

如果要更改 Operator 的安装版本,请将 Operator 的 CR 编辑为所需的目标版本。

警告

在以前的 OLM 版本中,Operator 作者可以定义升级边缘,以防止您升级到不支持的版本。在开发的当前状态中,OLM 1.0 不强制升级边缘定义。您可以指定 Operator 的任何版本,OLM 1.0 会尝试应用更新。

您可以运行以下命令来检查 Operator 的目录内容,包括可用版本和频道:

命令语法

$ oc get package <catalog_name>-<package_name> -o yaml

创建或更新 CR 后,运行以下命令来创建或修改 Operator:

命令语法

$ oc apply -f <extension_name>.yaml

故障排除

  • 如果指定了不存在的目标版本或频道,您可以运行以下命令来检查 Operator 的状态:

    $ oc get operator.operators.operatorframework.io <operator_name> -o yaml

    输出示例

    apiVersion: operators.operatorframework.io/v1alpha1
    kind: Operator
    metadata:
      annotations:
        kubectl.kubernetes.io/last-applied-configuration: |
          {"apiVersion":"operators.operatorframework.io/v1alpha1","kind":"Operator","metadata":{"annotations":{},"name":"quay-example"},"spec":{"packageName":"quay-operator","version":"999.99.9"}}
      creationTimestamp: "2023-10-19T18:39:37Z"
      generation: 3
      name: quay-example
      resourceVersion: "51505"
      uid: 2558623b-8689-421c-8ed5-7b14234af166
    spec:
      packageName: quay-operator
      version: 999.99.9
    status:
      conditions:
      - lastTransitionTime: "2023-10-19T18:50:34Z"
        message: package 'quay-operator' at version '999.99.9' not found
        observedGeneration: 3
        reason: ResolutionFailed
        status: "False"
        type: Resolved
      - lastTransitionTime: "2023-10-19T18:50:34Z"
        message: installation has not been attempted as resolution failed
        observedGeneration: 3
        reason: InstallationStatusUnknown
        status: Unknown
        type: Installed

7.3.4. 在集群中添加目录

要在集群中添加目录,请创建一个目录自定义资源(CR)并将其应用到集群。

流程

  1. 创建目录自定义资源(CR),如下例所示:

    redhat-operators.yaml 示例

    apiVersion: catalogd.operatorframework.io/v1alpha1
    kind: Catalog
    metadata:
      name: redhat-operators
    spec:
      source:
        type: image
        image:
          ref: registry.redhat.io/redhat/redhat-operator-index:v4.14 1

    1
    spec.source.image 字段中指定目录的镜像。
  2. 运行以下命令在集群中添加目录:

    $ oc apply -f redhat-operators.yaml

    输出示例

    catalog.catalogd.operatorframework.io/redhat-operators created

验证

  • 运行以下命令以验证目录的状态:

    1. 运行以下命令检查目录是否可用:

      $ oc get catalog

      输出示例

      NAME                  AGE
      redhat-operators      20s

    2. 运行以下命令,检查目录的状态:

      $ oc get catalogs.catalogd.operatorframework.io -o yaml

      输出示例

      apiVersion: v1
      items:
      - apiVersion: catalogd.operatorframework.io/v1alpha1
        kind: Catalog
        metadata:
          annotations:
            kubectl.kubernetes.io/last-applied-configuration: |
              {"apiVersion":"catalogd.operatorframework.io/v1alpha1","kind":"Catalog","metadata":{"annotations":{},"name":"redhat-operators"},"spec":{"source":{"image":{"ref":"registry.redhat.io/redhat/redhat-operator-index:v4.14"},"type":"image"}}}
          creationTimestamp: "2023-10-16T13:30:59Z"
          generation: 1
          name: redhat-operators
          resourceVersion: "37304"
          uid: cf00c68c-4312-4e06-aa8a-299f0bbf496b
        spec:
          source:
            image:
              ref: registry.redhat.io/redhat/redhat-operator-index:v4.14
            type: image
        status: 1
          conditions:
          - lastTransitionTime: "2023-10-16T13:32:25Z"
            message: successfully unpacked the catalog image "registry.redhat.io/redhat/redhat-operator-index@sha256:bd2f1060253117a627d2f85caa1532ebae1ba63da2a46bdd99e2b2a08035033f" 2
            reason: UnpackSuccessful 3
            status: "True"
            type: Unpacked
          phase: Unpacked 4
          resolvedSource:
            image:
              ref: registry.redhat.io/redhat/redhat-operator-index@sha256:bd2f1060253117a627d2f85caa1532ebae1ba63da2a46bdd99e2b2a08035033f 5
            type: image
      kind: List
      metadata:
        resourceVersion: ""

      1
      描述目录状态的小节。
      2
      输出目录状态的消息。
      3
      显示目录处于当前状态的原因。
      4
      显示安装过程的阶段。
      5
      显示目录的镜像引用。

7.3.5. 从目录查找 Operator

在集群中添加目录后,您可以查询目录以查找要安装的 Operator 和扩展。

前提条件

  • 您已在集群中添加目录。

流程

  1. 运行以下命令,获取目录中的 Operator 扩展列表:

    $ oc get packages

    例 7.1. 输出示例

    NAME                                                        AGE
    redhat-operators-3scale-operator                            5m27s
    redhat-operators-advanced-cluster-management                5m27s
    redhat-operators-amq-broker-rhel8                           5m27s
    redhat-operators-amq-online                                 5m27s
    redhat-operators-amq-streams                                5m27s
    redhat-operators-amq7-interconnect-operator                 5m27s
    redhat-operators-ansible-automation-platform-operator       5m27s
    redhat-operators-ansible-cloud-addons-operator              5m27s
    redhat-operators-apicast-operator                           5m27s
    redhat-operators-aws-efs-csi-driver-operator                5m27s
    redhat-operators-aws-load-balancer-operator                 5m27s
    ...
  2. 运行以下命令,检查 Operator 或扩展的自定义资源 (CR) 的内容:

    $ oc get package <catalog_name>-<package_name> -o yaml

    示例命令

    $ oc get package redhat-operators-quay-operator -o yaml

    例 7.2. 输出示例

    apiVersion: catalogd.operatorframework.io/v1alpha1
    kind: Package
    metadata:
      creationTimestamp: "2023-10-06T01:14:04Z"
      generation: 1
      labels:
        catalog: redhat-operators
      name: redhat-operators-quay-operator
      ownerReferences:
      - apiVersion: catalogd.operatorframework.io/v1alpha1
        blockOwnerDeletion: true
        controller: true
        kind: Catalog
        name: redhat-operators
        uid: 403004b6-54a3-4471-8c90-63419f6a2c3e
      resourceVersion: "45196"
      uid: 252cfe74-936d-44fc-be5d-09a7be7e36f5
    spec:
      catalog:
        name: redhat-operators
      channels:
      - entries:
        - name: quay-operator.v3.4.7
          skips:
          - red-hat-quay.v3.3.4
          - quay-operator.v3.4.6
          - quay-operator.v3.4.5
          - quay-operator.v3.4.4
          - quay-operator.v3.4.3
          - quay-operator.v3.4.2
          - quay-operator.v3.4.1
          - quay-operator.v3.4.0
        name: quay-v3.4
      - entries:
        - name: quay-operator.v3.5.7
          replaces: quay-operator.v3.5.6
          skipRange: '>=3.4.x <3.5.7'
        name: quay-v3.5
      - entries:
        - name: quay-operator.v3.6.0
          skipRange: '>=3.3.x <3.6.0'
        - name: quay-operator.v3.6.1
          replaces: quay-operator.v3.6.0
          skipRange: '>=3.3.x <3.6.1'
        - name: quay-operator.v3.6.10
          replaces: quay-operator.v3.6.9
          skipRange: '>=3.3.x <3.6.10'
        - name: quay-operator.v3.6.2
          replaces: quay-operator.v3.6.1
          skipRange: '>=3.3.x <3.6.2'
        - name: quay-operator.v3.6.4
          replaces: quay-operator.v3.6.2
          skipRange: '>=3.3.x <3.6.4'
        - name: quay-operator.v3.6.5
          replaces: quay-operator.v3.6.4
          skipRange: '>=3.3.x <3.6.5'
        - name: quay-operator.v3.6.6
          replaces: quay-operator.v3.6.5
          skipRange: '>=3.3.x <3.6.6'
        - name: quay-operator.v3.6.7
          replaces: quay-operator.v3.6.6
          skipRange: '>=3.3.x <3.6.7'
        - name: quay-operator.v3.6.8
          replaces: quay-operator.v3.6.7
          skipRange: '>=3.3.x <3.6.8'
        - name: quay-operator.v3.6.9
          replaces: quay-operator.v3.6.8
          skipRange: '>=3.3.x <3.6.9'
        name: stable-3.6
      - entries:
        - name: quay-operator.v3.7.10
          replaces: quay-operator.v3.7.9
          skipRange: '>=3.4.x <3.7.10'
        - name: quay-operator.v3.7.11
          replaces: quay-operator.v3.7.10
          skipRange: '>=3.4.x <3.7.11'
        - name: quay-operator.v3.7.12
          replaces: quay-operator.v3.7.11
          skipRange: '>=3.4.x <3.7.12'
        - name: quay-operator.v3.7.13
          replaces: quay-operator.v3.7.12
          skipRange: '>=3.4.x <3.7.13'
        - name: quay-operator.v3.7.14
          replaces: quay-operator.v3.7.13
          skipRange: '>=3.4.x <3.7.14'
        name: stable-3.7
      - entries:
        - name: quay-operator.v3.8.0
          skipRange: '>=3.5.x <3.8.0'
        - name: quay-operator.v3.8.1
          replaces: quay-operator.v3.8.0
          skipRange: '>=3.5.x <3.8.1'
        - name: quay-operator.v3.8.10
          replaces: quay-operator.v3.8.9
          skipRange: '>=3.5.x <3.8.10'
        - name: quay-operator.v3.8.11
          replaces: quay-operator.v3.8.10
          skipRange: '>=3.5.x <3.8.11'
        - name: quay-operator.v3.8.12
          replaces: quay-operator.v3.8.11
          skipRange: '>=3.5.x <3.8.12'
        - name: quay-operator.v3.8.2
          replaces: quay-operator.v3.8.1
          skipRange: '>=3.5.x <3.8.2'
        - name: quay-operator.v3.8.3
          replaces: quay-operator.v3.8.2
          skipRange: '>=3.5.x <3.8.3'
        - name: quay-operator.v3.8.4
          replaces: quay-operator.v3.8.3
          skipRange: '>=3.5.x <3.8.4'
        - name: quay-operator.v3.8.5
          replaces: quay-operator.v3.8.4
          skipRange: '>=3.5.x <3.8.5'
        - name: quay-operator.v3.8.6
          replaces: quay-operator.v3.8.5
          skipRange: '>=3.5.x <3.8.6'
        - name: quay-operator.v3.8.7
          replaces: quay-operator.v3.8.6
          skipRange: '>=3.5.x <3.8.7'
        - name: quay-operator.v3.8.8
          replaces: quay-operator.v3.8.7
          skipRange: '>=3.5.x <3.8.8'
        - name: quay-operator.v3.8.9
          replaces: quay-operator.v3.8.8
          skipRange: '>=3.5.x <3.8.9'
        name: stable-3.8
      - entries:
        - name: quay-operator.v3.9.0
          skipRange: '>=3.6.x <3.9.0'
        - name: quay-operator.v3.9.1
          replaces: quay-operator.v3.9.0
          skipRange: '>=3.6.x <3.9.1'
        - name: quay-operator.v3.9.2
          replaces: quay-operator.v3.9.1
          skipRange: '>=3.6.x <3.9.2'
        name: stable-3.9
      defaultChannel: stable-3.9
      description: ""
      icon:
        data: PD94bWwgdmVyc2lvbj ...
        mediatype: image/svg+xml
      packageName: quay-operator
    status: {}

7.3.6. 安装 Operator

您可以通过创建 Operator 自定义资源(CR)并将其应用到集群来从目录安装 Operator。

前提条件

  • 您已在集群中添加目录。
  • 您已检查了 Operator 的详情,以查找您要安装的版本。

流程

  1. 创建一个 Operator CR,类似以下示例:

    test-operator.yaml CR 示例

    apiVersion: operators.operatorframework.io/v1alpha1
    kind: Operator
    metadata:
      name: quay-example
    spec:
      packageName: quay-operator
      version: 3.8.12

  2. 运行以下命令,将 Operator CR 应用到集群:

    $ oc apply -f test-operator.yaml

    输出示例

    operator.operators.operatorframework.io/quay-example created

验证

  1. 运行以下命令,以 YAML 格式查看 Operator 的 CR:

    $ oc get operator.operators.operatorframework.io/quay-example -o yaml

    输出示例

    apiVersion: operators.operatorframework.io/v1alpha1
    kind: Operator
    metadata:
      annotations:
        kubectl.kubernetes.io/last-applied-configuration: |
          {"apiVersion":"operators.operatorframework.io/v1alpha1","kind":"Operator","metadata":{"annotations":{},"name":"quay-example"},"spec":{"packageName":"quay-operator","version":"3.8.12"}}
      creationTimestamp: "2023-10-19T18:39:37Z"
      generation: 1
      name: quay-example
      resourceVersion: "45663"
      uid: 2558623b-8689-421c-8ed5-7b14234af166
    spec:
      packageName: quay-operator
      version: 3.8.12
    status:
      conditions:
      - lastTransitionTime: "2023-10-19T18:39:37Z"
        message: resolved to "registry.redhat.io/quay/quay-operator-bundle@sha256:bf26c7679ea1f7b47d2b362642a9234cddb9e366a89708a4ffcbaf4475788dc7"
        observedGeneration: 1
        reason: Success
        status: "True"
        type: Resolved
      - lastTransitionTime: "2023-10-19T18:39:46Z"
        message: installed from "registry.redhat.io/quay/quay-operator-bundle@sha256:bf26c7679ea1f7b47d2b362642a9234cddb9e366a89708a4ffcbaf4475788dc7"
        observedGeneration: 1
        reason: Success
        status: "True"
        type: Installed
      installedBundleResource: registry.redhat.io/quay/quay-operator-bundle@sha256:bf26c7679ea1f7b47d2b362642a9234cddb9e366a89708a4ffcbaf4475788dc7
      resolvedBundleResource: registry.redhat.io/quay/quay-operator-bundle@sha256:bf26c7679ea1f7b47d2b362642a9234cddb9e366a89708a4ffcbaf4475788dc7

  2. 运行以下命令,获取 Operator 的控制器管理器 pod 的信息:

    $ oc get pod -n quay-operator-system

    输出示例

    NAME                                     READY   STATUS    RESTARTS   AGE
    quay-operator.v3.8.12-6677b5c98f-2kdtb   1/1     Running   0          2m28s

7.3.7. 更新 Operator

您可以通过编辑 Operator 的自定义资源(CR)并应用更改来更新 Operator。

先决条件

  • 已安装目录。
  • 已安装 Operator。

流程

  1. 运行以下命令,检查 Operator 的软件包内容以查找哪些频道和版本可用于更新:

    $ oc get package <catalog_name>-<package_name> -o yaml

    示例命令

    $ oc get package redhat-operators-quay-operator -o yaml

  2. 编辑 Operator 的 CR,将版本更新至 3.9.1,如下例所示:

    test-operator.yaml CR 示例

    apiVersion: operators.operatorframework.io/v1alpha1
    kind: Operator
    metadata:
      name: quay-example
    spec:
      packageName: quay-operator
      version: 3.9.1 1

    1
    将版本更新至 3.9.1
  3. 运行以下命令,将更新应用到集群:

    $ oc apply -f test-operator.yaml

    输出示例

    operator.operators.operatorframework.io/quay-example configured

    提示

    您可以运行以下命令来通过 CLI 对 Operator 版本进行补丁并应用对 Operator 版本的更改:

    $ oc patch operator.operators.operatorframework.io/quay-example -p \
      '{"spec":{"version":"3.9.1"}}' \
      --type=merge

    输出示例

    operator.operators.operatorframework.io/quay-example patched

验证

  • 运行以下命令验证频道和版本更新是否已应用:

    $ oc get operator.operators.operatorframework.io/quay-example -o yaml

    输出示例

    apiVersion: operators.operatorframework.io/v1alpha1
    kind: Operator
    metadata:
      annotations:
        kubectl.kubernetes.io/last-applied-configuration: |
          {"apiVersion":"operators.operatorframework.io/v1alpha1","kind":"Operator","metadata":{"annotations":{},"name":"quay-example"},"spec":{"packageName":"quay-operator","version":"3.9.1"}}
      creationTimestamp: "2023-10-19T18:39:37Z"
      generation: 2
      name: quay-example
      resourceVersion: "47423"
      uid: 2558623b-8689-421c-8ed5-7b14234af166
    spec:
      packageName: quay-operator
      version: 3.9.1 1
    status:
      conditions:
      - lastTransitionTime: "2023-10-19T18:39:37Z"
        message: resolved to "registry.redhat.io/quay/quay-operator-bundle@sha256:4864bc0d5c18a84a5f19e5e664b58d3133a2ac2a309c6b5659ab553f33214b09"
        observedGeneration: 2
        reason: Success
        status: "True"
        type: Resolved
      - lastTransitionTime: "2023-10-19T18:39:46Z"
        message: installed from "registry.redhat.io/quay/quay-operator-bundle@sha256:4864bc0d5c18a84a5f19e5e664b58d3133a2ac2a309c6b5659ab553f33214b09"
        observedGeneration: 2
        reason: Success
        status: "True"
        type: Installed
      installedBundleResource: registry.redhat.io/quay/quay-operator-bundle@sha256:4864bc0d5c18a84a5f19e5e664b58d3133a2ac2a309c6b5659ab553f33214b09
      resolvedBundleResource: registry.redhat.io/quay/quay-operator-bundle@sha256:4864bc0d5c18a84a5f19e5e664b58d3133a2ac2a309c6b5659ab553f33214b09

    1
    验证版本是否已更新至 3.9.1

7.3.8. 删除 Operator

您可以通过删除 Operator 的自定义资源(CR)来删除 Operator 及其自定义资源定义(CRD)。

先决条件

  • 已安装目录。
  • 已安装 Operator。

流程

  • 运行以下命令来删除 Operator 及其 CRD:

    $ oc delete operator.operators.operatorframework.io quay-example

    输出示例

    operator.operators.operatorframework.io "quay-example" deleted

验证

  • 运行以下命令验证您的 Operator 及其资源已被删除:

    • 运行以下命令验证 Operator 已被删除:

      $ oc get operator.operators.operatorframework.io

      输出示例

      No resources found

    • 运行以下命令验证 Operator 的系统命名空间是否已删除:

      $ oc get ns quay-operator-system

      输出示例

      Error from server (NotFound): namespaces "quay-operator-system" not found

7.3.9. 删除目录

您可以通过删除其自定义资源 (CR) 来删除目录。

先决条件

  • 已安装目录。

流程

  • 运行以下命令来删除目录:

    $ oc delete catalog <catalog_name>

    输出示例

    catalog.catalogd.operatorframework.io "my-catalog" deleted

验证

  • 运行以下命令验证目录是否已删除:

    $ oc get catalog
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.