4.2. 在裸机上部署托管的 control plane


您可以通过将集群配置为充当管理集群来部署托管的 control plane。管理集群是托管 control plane 的 OpenShift Container Platform 集群。在某些上下文中,管理集群也称为托管集群。

注意

受管集群与受管集群不同。受管集群是 hub 集群管理的集群。

托管的 control plane 功能默认启用。

multicluster engine Operator 只支持默认的 local-cluster,它是管理的 hub 集群,而 hub 集群作为管理集群。如果安装了 Red Hat Advanced Cluster Management,您可以使用受管 hub 集群(也称为 local-cluster )作为管理集群。

托管的集群 是一个 OpenShift Container Platform 集群,其 API 端点和 control plane 托管在管理集群中。托管的集群包括控制平面和它的对应的数据平面。您可以使用多集群引擎 Operator 控制台或托管的 control plane 命令行界面(hcp)来创建托管集群。

托管的集群自动导入为受管集群。如果要禁用此自动导入功能,请参阅"禁用托管集群自动导入到多集群引擎 Operator"。

4.2.1. 准备在裸机上部署托管的 control plane

当您准备在裸机上部署托管 control plane 时,请考虑以下信息:

  • 在托管 control plane 的同一平台上运行管理集群和 worker。
  • 所有裸机主机都需要手动从中央基础架构管理提供的发现镜像 ISO 开始。您可以使用 Cluster-Baremetal-Operator 手动启动主机或通过自动化来启动主机。每个主机启动后,它会运行一个代理进程来发现主机详情并完成安装。Agent 自定义资源代表每个主机。
  • 当您为托管 control plane 配置存储时,请考虑推荐的 etcd 实践。要确保您满足延迟要求,请将快速存储设备专用于每个 control-plane 节点上运行的所有托管 control plane etcd 实例。您可以使用 LVM 存储为托管的 etcd pod 配置本地存储类。如需更多信息,请参阅"推荐 etcd 实践"和"使用逻辑卷管理器存储的持久性存储"。

4.2.1.1. 配置管理集群的先决条件

  • 您需要为 Kubernetes Operator 2.2 及之后的版本安装在 OpenShift Container Platform 集群上的多集群引擎。您可以从 OpenShift Container Platform OperatorHub 将 multicluster engine Operator 安装为 Operator。
  • multicluster engine Operator 必须至少有一个受管 OpenShift Container Platform 集群。local-cluster 在多集群引擎 Operator 2.2 及更高版本中自动导入。有关 local-cluster 的更多信息,请参阅 Red Hat Advanced Cluster Management 中的高级配置部分。您可以运行以下命令来检查 hub 集群的状态:

    $ oc get managedclusters local-cluster
    Copy to Clipboard Toggle word wrap
  • 您必须将 topology.kubernetes.io/zone 标签添加到管理集群中的裸机主机中。确保每个主机具有 topology.kubernetes.io/zone 的唯一值。否则,所有托管的 control plane pod 都调度到单一节点上,从而导致单点故障。
  • 要在裸机上置备托管的 control plane,您可以使用 Agent 平台。Agent 平台使用中央基础架构管理服务将 worker 节点添加到托管的集群中。如需更多信息,请参阅启用中央基础架构管理服务
  • 您需要安装托管的 control plane 命令行界面。

4.2.1.2. 裸机防火墙、端口和服务要求

您必须满足防火墙、端口和服务要求,以便端口可以在管理集群、control plane 和托管集群之间进行通信。

注意

服务在其默认端口上运行。但是,如果您使用 NodePort 发布策略,服务在由 NodePort 服务分配的端口上运行。

使用防火墙规则、安全组或其他访问控制来仅限制对所需源的访问。除非需要,否则请避免公开公开端口。对于生产环境部署,请使用负载均衡器来简化通过单个 IP 地址的访问。

如果您的 hub 集群有代理配置,请通过将所有托管集群 API 端点添加到 Proxy 对象的 noProxy 字段来确保它可以访问托管集群 API 端点。如需更多信息,请参阅"配置集群范围代理"。

托管 control plane 在裸机上公开以下服务:

  • APIServer

    • APIServer 服务默认在端口 6443 上运行,需要入口访问 control plane 组件之间的通信。
    • 如果使用 MetalLB 负载均衡,允许入口访问用于负载均衡器 IP 地址的 IP 范围。
  • OAuthServer

    • 当使用路由和入口来公开服务时,OAuthServer 服务默认在端口 443 上运行。
    • 如果使用 NodePort 发布策略,请为 OAuthServer 服务使用防火墙规则。
  • Konnectivity

    • 当使用路由和入口来公开服务时,Konnectivity 服务默认在端口 443 上运行。
    • Konnectity 代理建立一个反向隧道,允许 control plane 访问托管集群的网络。代理使用出口连接到 Konnectivity 服务器。服务器通过使用端口 443 上的路由或手动分配的 NodePort 来公开。
    • 如果集群 API 服务器地址是一个内部 IP 地址,允许从工作负载子网访问端口 6443 上的 IP 地址。
    • 如果地址是一个外部 IP 地址,允许从节点通过端口 6443 出口到该外部 IP 地址。
  • Ignition

    • 当使用路由和入口来公开服务时,Ignition 服务默认在端口 443 上运行。
    • 如果使用 NodePort 发布策略,请为 Ignition 服务使用防火墙规则。

在裸机上不需要以下服务:

  • OVNSbDb
  • OIDC

4.2.1.3. 裸机基础架构要求

Agent 平台不会创建任何基础架构,但它对基础架构有以下要求:

  • 代理 : 代理 代表使用发现镜像引导的主机,并准备好置备为 OpenShift Container Platform 节点。
  • DNS :API 和入口端点必须可以被路由。

4.2.2. 裸机上的 DNS 配置

托管集群的 API 服务器作为 NodePort 服务公开。必须存在 api.<hosted_cluster_name>.<base_domain> 的 DNS 条目,它指向可以访问 API 服务器的目标。

DNS 条目可以作为记录,指向运行托管 control plane 管理集群中的一个节点。该条目也可以指向部署的负载均衡器,将传入的流量重定向到入口 pod。

DNS 配置示例

api.example.krnl.es.    IN A 192.168.122.20
api.example.krnl.es.    IN A 192.168.122.21
api.example.krnl.es.    IN A 192.168.122.22
api-int.example.krnl.es.    IN A 192.168.122.20
api-int.example.krnl.es.    IN A 192.168.122.21
api-int.example.krnl.es.    IN A 192.168.122.22
`*`.apps.example.krnl.es. IN A 192.168.122.23
Copy to Clipboard Toggle word wrap

注意

在上例中,*.apps.example.krnl.es。IN A 192.168.122.23 是托管的集群中的节点,如果已经配置了负载均衡器,则是一个负载均衡器。

如果您要为 IPv6 网络上的断开连接的环境配置 DNS,则配置类似以下示例。

IPv6 网络的 DNS 配置示例

api.example.krnl.es.    IN A 2620:52:0:1306::5
api.example.krnl.es.    IN A 2620:52:0:1306::6
api.example.krnl.es.    IN A 2620:52:0:1306::7
api-int.example.krnl.es.    IN A 2620:52:0:1306::5
api-int.example.krnl.es.    IN A 2620:52:0:1306::6
api-int.example.krnl.es.    IN A 2620:52:0:1306::7
`*`.apps.example.krnl.es. IN A 2620:52:0:1306::10
Copy to Clipboard Toggle word wrap

如果您要为双栈网络上的断开连接的环境配置 DNS,请务必包括 IPv4 和 IPv6 的条目。

双栈网络的 DNS 配置示例

host-record=api-int.hub-dual.dns.base.domain.name,192.168.126.10
host-record=api.hub-dual.dns.base.domain.name,192.168.126.10
address=/apps.hub-dual.dns.base.domain.name/192.168.126.11
dhcp-host=aa:aa:aa:aa:10:01,ocp-master-0,192.168.126.20
dhcp-host=aa:aa:aa:aa:10:02,ocp-master-1,192.168.126.21
dhcp-host=aa:aa:aa:aa:10:03,ocp-master-2,192.168.126.22
dhcp-host=aa:aa:aa:aa:10:06,ocp-installer,192.168.126.25
dhcp-host=aa:aa:aa:aa:10:07,ocp-bootstrap,192.168.126.26

host-record=api-int.hub-dual.dns.base.domain.name,2620:52:0:1306::2
host-record=api.hub-dual.dns.base.domain.name,2620:52:0:1306::2
address=/apps.hub-dual.dns.base.domain.name/2620:52:0:1306::3
dhcp-host=aa:aa:aa:aa:10:01,ocp-master-0,[2620:52:0:1306::5]
dhcp-host=aa:aa:aa:aa:10:02,ocp-master-1,[2620:52:0:1306::6]
dhcp-host=aa:aa:aa:aa:10:03,ocp-master-2,[2620:52:0:1306::7]
dhcp-host=aa:aa:aa:aa:10:06,ocp-installer,[2620:52:0:1306::8]
dhcp-host=aa:aa:aa:aa:10:07,ocp-bootstrap,[2620:52:0:1306::9]
Copy to Clipboard Toggle word wrap

4.2.2.1. 定义自定义 DNS 名称

作为集群管理员,您可以使用与用于节点 bootstrap 和 control plane 通信的内部端点不同的外部 API DNS 名称创建托管集群。您可能想要定义不同的 DNS 名称,理由如下:

  • 将面向用户的 TLS 证书替换为公共 CA 中的一个,而不破坏绑定到内部 root CA 的 control plane 功能
  • 支持 split-horizon DNS 和 NAT 场景
  • 为确保与独立 control plane 类似的体验,您可以使用的功能,如 "Show Login Command" 功能,以及正确的 kubeconfig 和 DNS 配置

您可以通过在 HostedCluster 对象的 kubeAPIServerDNSName 字段中输入域名,在初始设置或第 2 天操作期间定义 DNS 名称。

先决条件

  • 您有一个有效的 TLS 证书,其中包含您将在 kubeAPIServerDNSName 字段中设置的 DNS 名称。
  • 您的 DNS 名称是可访问的 URI,并指向正确的地址。

流程

  • HostedCluster 对象的规格中,添加 kubeAPIServerDNSName 字段和域的地址,并指定要使用的证书,如下例所示:

    #...
    spec:
      configuration:
        apiServer:
          servingCerts:
            namedCertificates:
            - names:
              - xxx.example.com
              - yyy.example.com
              servingCertificate:
                name: <my_serving_certificate>
      kubeAPIServerDNSName: <your_custom_address> 
    1
    Copy to Clipboard Toggle word wrap
    1
    kubeAPIServerDNSName 字段的值必须是有效的、可寻址的域。

在定义了 kubeAPIServerDNSName 字段并指定证书后,Control Plane Operator 控制器会创建一个名为 custom-admin- kubeconfig 的 kubeconfig 文件,该文件存储在 HostedControlPlane 命名空间中。证书从 root CA 生成,而 HostedControlPlane 命名空间则管理其过期和续订。

Control Plane Operator 在 HostedControlPlane 命名空间中报告一个名为 CustomKubeconfig 的新 kubeconfig 文件。该文件使用 kubeAPIServerDNSName 字段中定义的新服务器。

自定义 kubeconfig 文件在 status 字段中被引用为 CustomKubeconfigCustomKubeConfig 字段是可选的,只有在 kubeAPIServerDNSName 字段不为空时才可以添加。当设置 CustomKubeConfig 字段时,它会在 HostedCluster 命名空间中触发名为 < hosted_cluster_name>-custom-admin-kubeconfig 的 secret 生成。您可以使用 secret 访问 HostedCluster API 服务器。如果您在第 2 天操作过程中删除 CustomKubeConfig 字段,则会删除所有相关 secret 和状态引用。

注意

此过程不会影响数据平面,因此不会发生任何推出部署。HostedControlPlane 命名空间从 HyperShift Operator 接收更改并删除对应的字段。

如果您从 HostedCluster 对象的规格中删除 kubeAPIServerDNSName 字段,则所有新生成的 secret 和 CustomKubeconfig 引用都会从集群中和 status 字段中删除。

4.2.3. 创建 InfraEnv 资源

在裸机上创建托管集群前,您需要一个 InfraEnv 资源。

4.2.3.1. 创建 InfraEnv 资源并添加节点

在托管的 control plane 上,control-plane 组件作为 pod 在管理集群中作为 pod 运行,而 data plane 在专用节点上运行。您可以使用 Assisted Service 使用发现 ISO 引导硬件,该 ISO 将您的硬件添加到硬件清单中。之后,当您创建托管集群时,使用清单中的硬件来置备 data-plane 节点。用于获取发现 ISO 的对象是一个 InfraEnv 资源。您需要创建一个 BareMetalHost 对象,将集群配置为从发现 ISO 引导裸机节点。

流程

  1. 输入以下命令创建一个命名空间来存储硬件清单:

    $ oc --kubeconfig ~/<directory_example>/mgmt-kubeconfig create \
      namespace <namespace_example>
    Copy to Clipboard Toggle word wrap

    其中:

    <directory_example>
    是保存管理集群的 kubeconfig 文件的目录名称。
    <namespace_example>

    是您要创建的命名空间的名称,如 hardware-inventory

    输出示例

    namespace/hardware-inventory created
    Copy to Clipboard Toggle word wrap

  2. 输入以下命令复制管理集群的 pull secret:

    $ oc --kubeconfig ~/<directory_example>/mgmt-kubeconfig \
      -n openshift-config get secret pull-secret -o yaml \
      | grep -vE "uid|resourceVersion|creationTimestamp|namespace" \
      | sed "s/openshift-config/<namespace_example>/g" \
      | oc --kubeconfig ~/<directory_example>/mgmt-kubeconfig \
      -n <namespace> apply -f -
    Copy to Clipboard Toggle word wrap

    其中:

    <directory_example>
    是保存管理集群的 kubeconfig 文件的目录名称。
    <namespace_example>

    是您要创建的命名空间的名称,如 hardware-inventory

    输出示例

    secret/pull-secret created
    Copy to Clipboard Toggle word wrap

  3. 通过在 YAML 文件中添加以下内容来创建 InfraEnv 资源:

    apiVersion: agent-install.openshift.io/v1beta1
    kind: InfraEnv
    metadata:
      name: hosted
      namespace: <namespace_example>
    spec:
      additionalNTPSources:
      - <ip_address>
      pullSecretRef:
        name: pull-secret
      sshAuthorizedKey: <ssh_public_key>
    # ...
    Copy to Clipboard Toggle word wrap
  4. 输入以下命令将更改应用到 YAML 文件:

    $ oc apply -f <infraenv_config>.yaml
    Copy to Clipboard Toggle word wrap

    <infraenv_config > 替换为您的文件的名称。

  5. 输入以下命令验证 InfraEnv 资源是否已创建:

    $ oc --kubeconfig ~/<directory_example>/mgmt-kubeconfig \
      -n <namespace_example> get infraenv hosted
    Copy to Clipboard Toggle word wrap
  6. 通过以下两种方法之一添加裸机主机:

    • 如果不使用 Metal3 Operator,请从 InfraEnv 资源获取发现 ISO,并完成以下步骤手动引导主机:

      1. 输入以下命令下载 live ISO:

        $ oc get infraenv -A
        Copy to Clipboard Toggle word wrap
        $ oc get infraenv <namespace_example> -o jsonpath='{.status.isoDownloadURL}' -n <namespace_example> <iso_url>
        Copy to Clipboard Toggle word wrap
      2. 引导 ISO。节点与 Assisted Service 通信,并作为代理注册到与 InfraEnv 资源相同的命名空间中。
      3. 对于每个代理,设置安装磁盘 ID 和主机名,并批准它以指示代理可以使用。输入以下命令:

        $ oc -n <hosted_control_plane_namespace> get agents
        Copy to Clipboard Toggle word wrap

        输出示例

        NAME                                   CLUSTER   APPROVED   ROLE          STAGE
        86f7ac75-4fc4-4b36-8130-40fa12602218                        auto-assign
        e57a637f-745b-496e-971d-1abbf03341ba                        auto-assign
        Copy to Clipboard Toggle word wrap

        $ oc -n <hosted_control_plane_namespace> \
          patch agent 86f7ac75-4fc4-4b36-8130-40fa12602218 \
          -p '{"spec":{"installation_disk_id":"/dev/sda","approved":true,"hostname":"worker-0.example.krnl.es"}}' \
          --type merge
        Copy to Clipboard Toggle word wrap
        $ oc -n <hosted_control_plane_namespace> \
          patch agent 23d0c614-2caa-43f5-b7d3-0b3564688baa -p \
          '{"spec":{"installation_disk_id":"/dev/sda","approved":true,"hostname":"worker-1.example.krnl.es"}}' \
          --type merge
        Copy to Clipboard Toggle word wrap
        $ oc -n <hosted_control_plane_namespace> get agents
        Copy to Clipboard Toggle word wrap

        输出示例

        NAME                                   CLUSTER   APPROVED   ROLE          STAGE
        86f7ac75-4fc4-4b36-8130-40fa12602218             true       auto-assign
        e57a637f-745b-496e-971d-1abbf03341ba             true       auto-assign
        Copy to Clipboard Toggle word wrap

    • 如果使用 Metal3 Operator,您可以通过创建以下对象来自动进行裸机主机注册:

      1. 创建 YAML 文件并添加以下内容:

        apiVersion: v1
        kind: Secret
        metadata:
          name: hosted-worker0-bmc-secret
          namespace: <namespace_example>
        data:
          password: <password>
          username: <username>
        type: Opaque
        ---
        apiVersion: v1
        kind: Secret
        metadata:
          name: hosted-worker1-bmc-secret
          namespace: <namespace_example>
        data:
          password: <password>
          username: <username>
        type: Opaque
        ---
        apiVersion: v1
        kind: Secret
        metadata:
          name: hosted-worker2-bmc-secret
          namespace: <namespace_example>
        data:
          password: <password>
          username: <username>
        type: Opaque
        ---
        apiVersion: metal3.io/v1alpha1
        kind: BareMetalHost
        metadata:
          name: hosted-worker0
          namespace: <namespace_example>
          labels:
            infraenvs.agent-install.openshift.io: hosted
          annotations:
            inspect.metal3.io: disabled
            bmac.agent-install.openshift.io/hostname: hosted-worker0
        spec:
          automatedCleaningMode: disabled
          bmc:
            disableCertificateVerification: True
            address: <bmc_address>
            credentialsName: hosted-worker0-bmc-secret
          bootMACAddress: aa:aa:aa:aa:02:01
          online: true
        ---
        apiVersion: metal3.io/v1alpha1
        kind: BareMetalHost
        metadata:
          name: hosted-worker1
          namespace: <namespace_example>
          labels:
            infraenvs.agent-install.openshift.io: hosted
          annotations:
            inspect.metal3.io: disabled
            bmac.agent-install.openshift.io/hostname: hosted-worker1
        spec:
          automatedCleaningMode: disabled
          bmc:
            disableCertificateVerification: True
            address: <bmc_address>
            credentialsName: hosted-worker1-bmc-secret
          bootMACAddress: aa:aa:aa:aa:02:02
          online: true
        ---
        apiVersion: metal3.io/v1alpha1
        kind: BareMetalHost
        metadata:
          name: hosted-worker2
          namespace: <namespace_example>
          labels:
            infraenvs.agent-install.openshift.io: hosted
          annotations:
            inspect.metal3.io: disabled
            bmac.agent-install.openshift.io/hostname: hosted-worker2
        spec:
          automatedCleaningMode: disabled
          bmc:
            disableCertificateVerification: True
            address: <bmc_address>
            credentialsName: hosted-worker2-bmc-secret
          bootMACAddress: aa:aa:aa:aa:02:03
          online: true
        ---
        apiVersion: rbac.authorization.k8s.io/v1
        kind: Role
        metadata:
          name: capi-provider-role
          namespace: <namespace_example>
        rules:
        - apiGroups:
          - agent-install.openshift.io
          resources:
          - agents
          verbs:
          - '*'
        Copy to Clipboard Toggle word wrap

        其中:

        <namespace_example>
        是您的命名空间。
        <password>
        是 secret 的密码。
        <username>
        是 secret 的用户名。
        <bmc_address>

        BareMetalHost 对象的 BMC 地址。

        注意

        应用此 YAML 文件时,会创建以下对象:

        • 带有基板管理控制器(BMC)凭证的 secret
        • BareMetalHost 对象
        • HyperShift Operator 的角色,用于管理代理

        注意如何使用 infraenvs.agent-install.openshift.io: hosted custom 标签在 BareMetalHost 对象中引用 InfraEnv 资源。这样可确保节点使用生成的 ISO 引导。

      2. 输入以下命令将更改应用到 YAML 文件:

        $ oc apply -f <bare_metal_host_config>.yaml
        Copy to Clipboard Toggle word wrap

        <bare_metal_host_config > 替换为您的文件的名称。

  7. 输入以下命令,然后等待几分钟后 BareMetalHost 对象移至 Provisioning 状态:

    $ oc --kubeconfig ~/<directory_example>/mgmt-kubeconfig -n <namespace_example> get bmh
    Copy to Clipboard Toggle word wrap

    输出示例

    NAME             STATE          CONSUMER   ONLINE   ERROR   AGE
    hosted-worker0   provisioning              true             106s
    hosted-worker1   provisioning              true             106s
    hosted-worker2   provisioning              true             106s
    Copy to Clipboard Toggle word wrap

  8. 输入以下命令验证节点是否已引导,并以代理的形式显示。这个过程可能需要几分钟时间,您可能需要多次输入命令。

    $ oc --kubeconfig ~/<directory_example>/mgmt-kubeconfig -n <namespace_example> get agent
    Copy to Clipboard Toggle word wrap

    输出示例

    NAME                                   CLUSTER   APPROVED   ROLE          STAGE
    aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaa0201             true       auto-assign
    aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaa0202             true       auto-assign
    aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaa0203             true       auto-assign
    Copy to Clipboard Toggle word wrap

4.2.3.2. 使用控制台创建 InfraEnv 资源

要使用控制台创建 InfraEnv 资源,请完成以下步骤。

流程

  1. 打开 OpenShift Container Platform Web 控制台,并输入您的管理员凭证登录。有关打开控制台的说明,请参阅"访问 Web 控制台"。
  2. 在控制台标头中,确保选择了 All Clusters
  3. Infrastructure Host inventory Create infrastructure environment
  4. 创建 InfraEnv 资源后,单击 Add hosts 并从可用选项中选择,从 InfraEnv 视图中添加裸机主机。
其他资源

4.2.4. 在裸机上创建托管集群

您可以创建托管集群或导入一个集群。当 Assisted Installer 作为 multicluster engine Operator 的附加组件启用,并使用 Agent 平台创建托管集群时,HyperShift Operator 会在托管的 control plane 命名空间中安装 Agent Cluster API 供应商。

4.2.4.1. 使用 CLI 创建托管集群

要使用命令行界面(CLI)创建托管集群,请完成以下步骤。

先决条件

  • 每个托管集群都必须具有集群范围的唯一名称。托管的集群名称不能与任何现有的受管集群相同,以便多集群引擎 Operator 管理它。
  • 不要使用 clusters 作为托管的集群名称。
  • 无法在多集群引擎 Operator 受管集群的命名空间中创建托管集群。
  • 验证您是否为集群配置了默认存储类。否则,您可能会看到待处理的持久性卷声明(PVC)。
  • 默认情况下,当您使用 hcp create cluster agent 命令时,托管集群会使用节点端口创建。但是,裸机上托管集群的首选发布策略是通过负载均衡器公开服务。如果使用 Web 控制台或使用 Red Hat Advanced Cluster Management 创建托管集群,要为 Kubernetes API 服务器以外的服务设置发布策略,您必须在 HostedCluster 自定义资源中手动指定 servicePublishingStrategy 信息。如需更多信息,请参阅此流程中的步骤 4。
  • 确保您满足"准备在裸机上部署托管 control plane"中所述的要求,其中包括与基础架构、防火墙、端口和服务相关的要求。例如,这些要求描述了如何在管理集群中的裸机主机中添加适当的区标签,如下例所示:

    $ oc label node [compute-node-1] topology.kubernetes.io/zone=zone1
    Copy to Clipboard Toggle word wrap
    $ oc label node [compute-node-2] topology.kubernetes.io/zone=zone2
    Copy to Clipboard Toggle word wrap
    $ oc label node [compute-node-3] topology.kubernetes.io/zone=zone3
    Copy to Clipboard Toggle word wrap
  • 确保您已将裸机节点添加到硬件清单中。

流程

  1. 运行以下命令来创建命名空间:

    $ oc create ns <hosted_cluster_namespace>
    Copy to Clipboard Toggle word wrap

    <hosted_cluster_namespace > 替换为托管集群命名空间的标识符。通常,命名空间由 HyperShift Operator 创建,但在裸机上托管集群创建过程中,会生成一个 Cluster API 供应商角色,需要命名空间已存在。

  2. 输入以下命令为托管集群创建配置文件:

    $ hcp create cluster agent \
      --name=<hosted_cluster_name> \
    1
    
      --pull-secret=<path_to_pull_secret> \
    2
    
      --agent-namespace=<hosted_control_plane_namespace> \
    3
    
      --base-domain=<base_domain> \
    4
    
      --api-server-address=api.<hosted_cluster_name>.<base_domain> \
    5
    
      --etcd-storage-class=<etcd_storage_class> \
    6
    
      --ssh-key=<path_to_ssh_key> \
    7
    
      --namespace=<hosted_cluster_namespace> \
    8
    
      --control-plane-availability-policy=HighlyAvailable \
    9
    
      --release-image=quay.io/openshift-release-dev/ocp-release:<ocp_release_image>-multi \
    10
    
      --node-pool-replicas=<node_pool_replica_count> \
    11
    
      --render \
      --render-sensitive \
      --ssh-key <home_directory>/<path_to_ssh_key>/<ssh_key> > hosted-cluster-config.yaml 
    12
    Copy to Clipboard Toggle word wrap
    1
    指定托管集群的名称。
    2
    指定 pull secret 的路径,例如 /user/name/pullsecret
    3
    指定托管的 control plane 命名空间。要确保代理在这个命名空间中可用,请输入 oc get agent -n <hosted_control_plane_namespace> 命令。
    4
    指定您的基域,如 krnl.es
    5
    --api-server-address 标志定义用于托管集群中的 Kubernetes API 通信的 IP 地址。如果没有设置 --api-server-address 标志,您必须登录以连接到管理集群。
    6
    指定 etcd 存储类名称,如 lvm-storageclass
    7
    指定 SSH 公钥的路径。默认文件路径为 ~/.ssh/id_rsa.pub
    8
    指定托管集群命名空间。
    9
    指定托管 control plane 组件的可用性策略。支持的选项包括 SingleReplicaHighlyAvailable。默认值为 HighlyAvailable
    10
    指定您要使用的 OpenShift Container Platform 版本,例如 4.19.0-multi。如果您使用断开连接的环境,将 <ocp_release_image> 替换为摘要镜像。要提取 OpenShift Container Platform 发行镜像摘要,请参阅"提取发行镜像摘要"。
    11
    指定节点池副本数,例如 3。您必须将副本数指定为 0 或更高,才能创建相同数量的副本。否则,不会创建节点池。
    12
    --ssh-key 标志后,指定 SSH 密钥的路径;例如 user/.ssh/id_rsa
  3. 配置服务发布策略。默认情况下,托管集群使用 NodePort 服务发布策略,因为节点端口始终在没有额外基础架构的情况下可用。但是,您可以将服务发布策略配置为使用负载均衡器。

    • 如果您使用默认的 NodePort 策略,请将 DNS 配置为指向托管的集群计算节点,而不是管理集群节点。如需更多信息,请参阅"裸机上的 DNS 配置"。
    • 对于生产环境,请使用 LoadBalancer 策略,因为它提供证书处理和自动 DNS 解析。要更改服务发布策略 LoadBalancer,在托管集群配置文件中编辑服务发布策略详情:

      ...
      spec:
        services:
        - service: APIServer
          servicePublishingStrategy:
            type: LoadBalancer 
      1
      
        - service: Ignition
          servicePublishingStrategy:
            type: Route
        - service: Konnectivity
          servicePublishingStrategy:
            type: Route
        - service: OAuthServer
          servicePublishingStrategy:
            type: Route
        - service: OIDC
          servicePublishingStrategy:
            type: Route
        sshKey:
          name: <ssh_key>
      ...
      Copy to Clipboard Toggle word wrap
      1
      指定 LoadBalancer 作为 API 服务器类型。对于所有其他服务,将 Route 指定为类型。
  4. 输入以下命令将更改应用到托管集群配置文件:

    $ oc apply -f hosted_cluster_config.yaml
    Copy to Clipboard Toggle word wrap
  5. 输入以下命令来监控托管集群、节点池和 pod 的创建:

    $ oc get hostedcluster \
      <hosted_cluster_namespace> -n \
      <hosted_cluster_namespace> -o \
      jsonpath='{.status.conditions[?(@.status=="False")]}' | jq .
    Copy to Clipboard Toggle word wrap
    $ oc get nodepool \
      <hosted_cluster_namespace> -n \
      <hosted_cluster_namespace> -o \
      jsonpath='{.status.conditions[?(@.status=="False")]}' | jq .
    Copy to Clipboard Toggle word wrap
    $ oc get pods -n <hosted_cluster_namespace>
    Copy to Clipboard Toggle word wrap
  6. 确认托管集群已就绪。当集群的状态为 Available: True 时,节点池状态会显示 AllMachinesReady: True,并且所有集群 Operator 都健康。
  7. 在托管集群中安装 MetalLB:

    1. 从托管集群中提取 kubeconfig 文件,并输入以下命令为托管集群访问设置环境变量:

      $ oc get secret \
        <hosted_cluster_namespace>-admin-kubeconfig \
        -n <hosted_cluster_namespace> \
        -o jsonpath='{.data.kubeconfig}' \
        | base64 -d > \
        kubeconfig-<hosted_cluster_namespace>.yaml
      Copy to Clipboard Toggle word wrap
      $ export KUBECONFIG="/path/to/kubeconfig-<hosted_cluster_namespace>.yaml"
      Copy to Clipboard Toggle word wrap
    2. 通过创建 install-metallb-operator.yaml 文件来安装 MetalLB Operator:

      apiVersion: v1
      kind: Namespace
      metadata:
        name: metallb-system
      ---
      apiVersion: operators.coreos.com/v1
      kind: OperatorGroup
      metadata:
        name: metallb-operator
        namespace: metallb-system
      ---
      apiVersion: operators.coreos.com/v1alpha1
      kind: Subscription
      metadata:
        name: metallb-operator
        namespace: metallb-system
      spec:
        channel: "stable"
        name: metallb-operator
        source: redhat-operators
        sourceNamespace: openshift-marketplace
        installPlanApproval: Automatic
      Copy to Clipboard Toggle word wrap
    3. 输入以下命令应用该文件:

      $ oc apply -f install-metallb-operator.yaml
      Copy to Clipboard Toggle word wrap
    4. 通过创建 deploy-metallb-ipaddresspool.yaml 文件来配置 MetalLB IP 地址池:

      apiVersion: metallb.io/v1beta1
      kind: IPAddressPool
      metadata:
        name: metallb
        namespace: metallb-system
      spec:
        autoAssign: true
        addresses:
        - 10.11.176.71-10.11.176.75
      ---
      apiVersion: metallb.io/v1beta1
      kind: L2Advertisement
      metadata:
        name: l2advertisement
        namespace: metallb-system
      spec:
        ipAddressPools:
        - metallb
      Copy to Clipboard Toggle word wrap
    5. 输入以下命令应用配置:

      $ oc apply -f deploy-metallb-ipaddresspool.yaml
      Copy to Clipboard Toggle word wrap
    6. 通过检查 Operator 状态、IP 地址池和 L2Advertisement 来验证是否安装了 MetalLB。输入以下命令:

      $ oc get pods -n metallb-system
      Copy to Clipboard Toggle word wrap
      $ oc get ipaddresspool -n metallb-system
      Copy to Clipboard Toggle word wrap
      $ oc get l2advertisement -n metallb-system
      Copy to Clipboard Toggle word wrap
  8. 为入口配置负载均衡器:

    1. 创建 ingress-loadbalancer.yaml 文件:

      apiVersion: v1
      kind: Service
      metadata:
        annotations:
          metallb.universe.tf/address-pool: metallb
        name: metallb-ingress
        namespace: openshift-ingress
      spec:
        ports:
          - name: http
            protocol: TCP
            port: 80
            targetPort: 80
          - name: https
            protocol: TCP
            port: 443
            targetPort: 443
        selector:
          ingresscontroller.operator.openshift.io/deployment-ingresscontroller: default
        type: LoadBalancer
      Copy to Clipboard Toggle word wrap
    2. 输入以下命令应用配置:

      $ oc apply -f ingress-loadbalancer.yaml
      Copy to Clipboard Toggle word wrap
    3. 输入以下命令验证负载均衡器服务是否按预期工作:

      $ oc get svc metallb-ingress -n openshift-ingress
      Copy to Clipboard Toggle word wrap

      输出示例

      NAME              TYPE           CLUSTER-IP       EXTERNAL-IP    PORT(S)                      AGE
      metallb-ingress   LoadBalancer   172.31.127.129   10.11.176.71   80:30961/TCP,443:32090/TCP   16h
      Copy to Clipboard Toggle word wrap

  9. 配置 DNS 以使用负载均衡器:

    1. 通过将 5.2. apps .<hosted_cluster_namespace>.<base_domain> 通配符 DNS 记录指向负载均衡器 IP 地址,为 apps 域配置 DNS。
    2. 输入以下命令验证 DNS 解析:

      $ nslookup console-openshift-console.apps.<hosted_cluster_namespace>.<base_domain> <load_balancer_ip_address>
      Copy to Clipboard Toggle word wrap

      输出示例

      Server:         10.11.176.1
      Address:        10.11.176.1#53
      
      Name:   console-openshift-console.apps.my-hosted-cluster.sample-base-domain.com
      Address: 10.11.176.71
      Copy to Clipboard Toggle word wrap

验证

  1. 输入以下命令检查集群 Operator:

    $ oc get clusteroperators
    Copy to Clipboard Toggle word wrap

    确保所有 Operator 显示 AVAILABLE: True,PROGRESSING: False, 和 DEGRADED: False

  2. 输入以下命令检查节点:

    $ oc get nodes
    Copy to Clipboard Toggle word wrap

    确保所有节点的状态为 READY

  3. 通过在 Web 浏览器中输入以下 URL 来测试对控制台的访问:

    https://console-openshift-console.apps.<hosted_cluster_namespace>.<base_domain>
    Copy to Clipboard Toggle word wrap

4.2.4.2. 使用控制台在裸机上创建托管集群

要使用控制台创建托管集群,请完成以下步骤。

流程

  1. 打开 OpenShift Container Platform Web 控制台,并输入您的管理员凭证登录。有关打开控制台的说明,请参阅"访问 Web 控制台"。
  2. 在控制台标头中,确保选择了 All Clusters
  3. Infrastructure Clusters
  4. Create cluster Host inventory Hosted control plane

    此时会显示 Create cluster 页。

  5. Create cluster 页中,按照提示输入集群、节点池、网络和自动化的详细信息。

    注意

    在输入集群详情时,您可能会发现以下提示很有用:

    • 如果要使用预定义的值来自动填充控制台中的字段,您可以创建主机清单凭证。如需更多信息,请参阅"为内部环境创建凭证"。
    • Cluster details 页中,pull secret 是用于访问 OpenShift Container Platform 资源的 OpenShift Container Platform pull secret。如果您选择了主机清单凭证,则会自动填充 pull secret。
    • Node pool 页中,命名空间包含节点池的主机。如果使用控制台创建主机清单,控制台会创建一个专用命名空间。
    • Networking 页上,您可以选择 API 服务器发布策略。托管集群的 API 服务器可以通过使用现有负载均衡器或 NodePort 类型的服务公开。必须存在 api.<hosted_cluster_name>.<base_domain> 的 DNS 条目,指向可以访问 API 服务器的目标。此条目可以是指向管理集群中某一节点的记录,也可以是指向将传入流量重定向到 Ingress pod 的负载均衡器的记录。
  6. 检查您的条目并点 Create

    此时会显示 Hosted 集群视图。

  7. 托管集群视图中监控托管集群的部署。
  8. 如果您没有看到托管集群的信息,请确保选择了 All Clusters,然后点集群名称。
  9. 等待 control plane 组件就绪。这个过程可能需要几分钟时间。
  10. 要查看节点池状态,请滚动到 NodePool 部分。安装节点的过程需要大约 10 分钟。您还可以点 Nodes 来确认节点是否加入托管集群。

后续步骤

您可以通过在 hcp create cluster 命令中指定 --image-content-sources 标志,来使用镜像 registry 在裸机上创建托管集群。

流程

  1. 创建 YAML 文件来定义镜像内容源策略 (ICSP)。请参见以下示例:

    - mirrors:
      - brew.registry.redhat.io
      source: registry.redhat.io
    - mirrors:
      - brew.registry.redhat.io
      source: registry.stage.redhat.io
    - mirrors:
      - brew.registry.redhat.io
      source: registry-proxy.engineering.redhat.com
    Copy to Clipboard Toggle word wrap
  2. 将文件保存为 icsp.yaml。此文件包含您的镜像 registry。
  3. 要使用您的镜像 registry 创建托管集群,请运行以下命令:

    $ hcp create cluster agent \
        --name=<hosted_cluster_name> \
    1
    
        --pull-secret=<path_to_pull_secret> \
    2
    
        --agent-namespace=<hosted_control_plane_namespace> \
    3
    
        --base-domain=<basedomain> \
    4
    
        --api-server-address=api.<hosted_cluster_name>.<basedomain> \
    5
    
        --image-content-sources icsp.yaml  \
    6
    
        --ssh-key  <path_to_ssh_key> \
    7
    
        --namespace <hosted_cluster_namespace> \
    8
    
        --release-image=quay.io/openshift-release-dev/ocp-release:<ocp_release_image> 
    9
    Copy to Clipboard Toggle word wrap
    1
    指定托管集群的名称,如 example
    2
    指定 pull secret 的路径,例如 /user/name/pullsecret
    3
    指定托管的 control plane 命名空间,如 cluster-example。使用 oc get agent -n <hosted-control-plane-namespace> 命令,确保此在命名空间中有可用的代理。
    4
    指定您的基域,如 krnl.es
    5
    --api-server-address 标志定义用于托管集群中的 Kubernetes API 通信的 IP 地址。如果没有设置 --api-server-address 标志,您必须登录以连接到管理集群。
    6
    指定定义 ICSP 和您的镜像 registry 的 icsp.yaml 文件。
    7
    指定 SSH 公钥的路径。默认文件路径为 ~/.ssh/id_rsa.pub
    8
    指定托管集群命名空间。
    9
    指定您要使用的 OpenShift Container Platform 版本,例如 4.19.0-multi。如果您使用断开连接的环境,将 <ocp_release_image> 替换为摘要镜像。要提取 OpenShift Container Platform 发行镜像摘要,请参阅"提取 OpenShift Container Platform 发行镜像摘要"。

后续步骤

4.2.5. 验证托管集群创建

部署过程完成后,您可以验证托管集群是否已成功创建。在创建托管集群后,按照以下步骤操作。

流程

  1. 输入 extract 命令,获取新的托管集群的 kubeconfig :

    $ oc extract -n <hosted-control-plane-namespace> secret/admin-kubeconfig \
      --to=- > kubeconfig-<hosted-cluster-name>
    Copy to Clipboard Toggle word wrap
  2. 使用 kubeconfig 查看托管集群的集群 Operator。输入以下命令:

    $ oc get co --kubeconfig=kubeconfig-<hosted-cluster-name>
    Copy to Clipboard Toggle word wrap

    输出示例

    NAME                                       VERSION   AVAILABLE   PROGRESSING   DEGRADED   SINCE   MESSAGE
    console                                    4.10.26   True        False         False      2m38s
    dns                                        4.10.26   True        False         False      2m52s
    image-registry                             4.10.26   True        False         False      2m8s
    ingress                                    4.10.26   True        False         False      22m
    Copy to Clipboard Toggle word wrap

  3. 您还可以输入以下命令来查看在托管集群中运行的 pod:

    $ oc get pods -A --kubeconfig=kubeconfig-<hosted-cluster-name>
    Copy to Clipboard Toggle word wrap

    输出示例

    NAMESPACE                                          NAME                                                      READY   STATUS             RESTARTS        AGE
    kube-system                                        konnectivity-agent-khlqv                                  0/1     Running            0               3m52s
    openshift-cluster-node-tuning-operator             tuned-dhw5p                                               1/1     Running            0               109s
    openshift-cluster-storage-operator                 cluster-storage-operator-5f784969f5-vwzgz                 1/1     Running            1 (113s ago)    20m
    openshift-cluster-storage-operator                 csi-snapshot-controller-6b7687b7d9-7nrfw                  1/1     Running            0               3m8s
    openshift-console                                  console-5cbf6c7969-6gk6z                                  1/1     Running            0               119s
    openshift-console                                  downloads-7bcd756565-6wj5j                                1/1     Running            0               4m3s
    openshift-dns-operator                             dns-operator-77d755cd8c-xjfbn                             2/2     Running            0               21m
    openshift-dns                                      dns-default-kfqnh                                         2/2     Running            0               113s
    Copy to Clipboard Toggle word wrap

要为 API 服务器配置自定义证书,请在 HostedCluster 配置的 spec.configuration.apiServer 部分中指定证书详情。

您可以在第 1 天或第 2 天操作期间配置自定义证书。但是,由于在托管集群创建过程中设置服务发布策略后,服务发布策略不可变,所以您必须知道您要配置的 Kubernetes API 服务器的主机名。

先决条件

  • 您创建了包含管理集群中的自定义证书的 Kubernetes secret。secret 包含以下键:

    • tls.crt: 证书
    • tls.key :私钥
  • 如果您的 HostedCluster 配置包含使用负载均衡器的服务发布策略,请确保证书的 Subject Alternative Names (SAN)与内部 API 端点(api-int)不冲突。内部 API 端点由您的平台自动创建和管理。如果您在自定义证书和内部 API 端点中使用相同的主机名,则可能会出现路由冲突。此规则的唯一例外是,当您将 AWS 用作供应商时,使用 PrivatePublicAndPrivate 配置。在这些情况下,SAN 冲突由平台管理。
  • 证书必须对外部 API 端点有效。
  • 证书的有效性周期与集群的预期生命周期一致。

流程

  1. 输入以下命令使用自定义证书创建 secret:

    $ oc create secret tls sample-hosted-kas-custom-cert \
      --cert=path/to/cert.crt \
      --key=path/to/key.key \
      -n <hosted_cluster_namespace>
    Copy to Clipboard Toggle word wrap
  2. 使用自定义证书详情更新 HostedCluster 配置,如下例所示:

    spec:
      configuration:
        apiServer:
          servingCerts:
            namedCertificates:
            - names: 
    1
    
              - api-custom-cert-sample-hosted.sample-hosted.example.com
              servingCertificate: 
    2
    
                name: sample-hosted-kas-custom-cert
    Copy to Clipboard Toggle word wrap
    1
    证书有效的 DNS 名称列表。
    2
    包含自定义证书的 secret 的名称。
  3. 输入以下命令将更改应用到 HostedCluster 配置:

    $ oc apply -f <hosted_cluster_config>.yaml
    Copy to Clipboard Toggle word wrap

验证

  • 检查 API 服务器 pod,以确保挂载了新证书。
  • 使用自定义域名测试与 API 服务器的连接。
  • 在浏览器中或使用 openssl 等工具验证证书详情。
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2025 Red Hat