5.2. 使用 OpenShift Container Platform CLI 将命名空间订阅到 Operator

使用这个流程为 Operator 订阅命名空间。

流程

  1. 为 operator 创建项目

    oc new-project ansible-automation-platform
  2. 创建名为 sub.yaml 的文件。
  3. 将以下 YAML 代码添加到 sub.yaml 文件中。

    ---
    apiVersion: v1
    kind: Namespace
    metadata:
      labels:
        openshift.io/cluster-monitoring: "true"
      name: ansible-automation-platform
    ---
    apiVersion: operators.coreos.com/v1
    kind: OperatorGroup
    metadata:
      name: ansible-automation-platform-operator
      namespace: ansible-automation-platform
    spec:
      targetNamespaces:
        - ansible-automation-platform
    ---
    apiVersion: operators.coreos.com/v1alpha1
    kind: Subscription
    metadata:
      name: ansible-automation-platform
      namespace: ansible-automation-platform
    spec:
      channel: 'stable-2.4'
      installPlanApproval: Automatic
      name: ansible-automation-platform-operator
      source: redhat-operators
      sourceNamespace: openshift-marketplace
    ---
    apiVersion: automationcontroller.ansible.com/v1beta1
    kind: AutomationController
    metadata:
      name: example
      namespace: ansible-automation-platform
    spec:
      replicas: 1

    此文件创建一个名为 ansible-automation-platform 的 Subscription 对象,它将 ansible-automation-platform 命名空间订阅到 ansible-automation-platform-operator operator。

    然后,它会在 ansible-automation-platform 命名空间中创建一个名为 exampleAutomationController 对象。

    要从示例更改 Automation 控制器名称,请编辑 sub.yamlkind: AutomationController 部分中的 name 字段,并将 <automation_controller_name> 替换为您要使用的名称:

    apiVersion: automationcontroller.ansible.com/v1beta1
    kind: AutomationController
    metadata:
      name: <automation_controller_name>
      namespace: ansible-automation-platform
  4. 运行 oc apply 命令来创建 sub.yaml 文件中指定的对象:

    oc apply -f sub.yaml

要验证命名空间是否已成功订阅到 ansible-automation-platform-operator operator,请运行 oc get subs 命令:

$ oc get subs -n ansible-automation-platform

如需有关将命名空间订阅到 Operator 的更多信息,请参阅 Red Hat OpenShift Container Platform Operator 指南中的使用 CLI 从 OperatorHub 安装

您可以使用 OpenShift Container Platform CLI 获取您创建的自动化控制器的 Web 地址和密码。