10.4. 在 vSphere 上为集群指定多个主机组


您可以配置 infrastructure .config.openshift.io 配置资源,为在 VMware vSphere 实例上运行的 OpenShift Container Platform 集群指定多个主机组。如果您的 vSphere 实例在扩展集群配置中,且您的 ESXi 主机和存储分布到多个物理数据中心中,则需要此项。如果您还没有在安装时为 OpenShift Container Platform 集群配置主机组,或者使用额外的主机组更新 OpenShift Container Platform 集群。

重要

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

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

先决条件

  • ESXi 主机分组到主机组中,它们通过 VM-host 关联性规则链接到对应的虚拟机(VM)组。详情请查看以下示例 govc 命令:

    # This example shows the correct configuration for a cluster with two host groups:
    
    # Create host groups:
    govc cluster.group.create -name <host_group_1> -host
    govc cluster.group.create -name <host_group_2> -host
    
    # Create VM groups:
    govc cluster.group.create -name <vm_group_1> -vm
    govc cluster.group.create -name <vm_group_2> -vm
    
    # Create VM-host affinity rules:
    govc cluster.rule.create -name <rule_1> -enable -vm-host -vm-group <vm_group_1> -host-affine-group <host_group_1>
    govc cluster.rule.create -name <rule_2> -enable -vm-host -vm-group <vm_group_2> -host-affine-group <host_group_2>
    
    # Add ESXi hosts to host groups:
    govc cluster.group.change -name <host_group_1> <esxi_host_1_ip>
    govc cluster.group.change -name <host_group_2> <esxi_host_2_ip>
    Copy to Clipboard Toggle word wrap
  • openshift-regionopenshift-zone 标签类别在 vCenter 服务器上创建。
  • Compute 集群有来自 openshift-region 标签类别的标签。
  • 主机组中的 ESXi 主机具有 openshift-zone 标签类别的标签。
  • Host.Inventory.EditCluster 特权在 vSphere vCenter 集群对象上被授予。
  • TechPreviewNoUpgrade 功能集已启用。如需更多信息,请参阅"使用功能门启用功能"。

流程

  1. 编辑 OpenShift Container Platform 集群的基础架构设置。

    1. 要将现有基础架构设置复制到文件中,请运行以下命令:

      $ oc get infrastructures.config.openshift.io cluster -o yaml > <name_of_infrastructure_file>.yaml
      Copy to Clipboard Toggle word wrap
    2. 编辑您的基础架构文件,使其包含 vSphere 集群中每个主机组的故障域。有关此配置示例,请参考以下 YAML 文件。确保将gle 括号中嵌套的任何值(&lt; >)替换为您的值:

      apiVersion: config.openshift.io/v1
      kind: Infrastructure
      metadata:
        name: cluster
      spec:
        cloudConfig:
          key: config
          name: cloud-provider-config
        platformSpec:
          type: VSphere
          vsphere:
            apiServerInternalIPs:
            - <internal_ip_of_api_server>
            failureDomains:
            - name: <unique_name_for_failure_domain_1>
              region: <cluster_1_region_tag>
              server: <vcenter_server_ip_address>
              zoneAffinity:
                type: HostGroup
                hostGroup:
                  vmGroup: <name_of_vm_group_1>
                  hostGroup: <name_of_host_group_1>
                  vmHostRule: <name_of_vm_host_affinity_rule_1>
              regionAffinity:
                type: ComputeCluster
              topology:
                computeCluster: /<data_center_1>/host/<cluster_1>
                datacenter: <data_center_1>
                datastore: /<data_center_1>/datastore/<datastore_1>
                networks:
                - VM Network
                resourcePool: /<data_center_1>/host/<cluster_1>/Resources
                template: /<data_center_1>/vm/<vm_template>
              zone: <host_group_1_tag>
            - name: <unique_name_for_failure_domain_2>
              region: <cluster_1_region_tag>
              server: <vcenter_server_ip_address>
              zoneAffinity:
                type: HostGroup
                hostGroup:
                  vmGroup: <name_of_vm_group_2>
                  hostGroup: <name_of_host_group_2>
                  vmHostRule: <name_of_vm_host_affinity_rule_2>
              regionAffinity:
                type: ComputeCluster
              topology:
                computeCluster: /<data_center_1>/host/<cluster_1>
                datacenter: <data_center_1>
                datastore: /<data_center_1>/datastore/<datastore_1>
                networks:
                - VM Network
                resourcePool: /<data_center_1>/host/<cluster_1>/Resources
                template: /<data_center_1>/vm/<vm_template>
              zone: <host_group_2_tag>
      # ...
      Copy to Clipboard Toggle word wrap
    3. 要使用这些更改更新集群,请运行以下命令:

      $ oc replace -f <name_of_infrastructure_file>.yaml
      Copy to Clipboard Toggle word wrap
  2. 通过完成以下步骤,使用新的故障域更新 ControlPlaneMachineSet 自定义资源(CR):

    1. 运行以下命令来编辑 ControlPlaneMachineSet CR:

      $ oc edit controlplanemachinesets.machine.openshift.io -n openshift-machine-api cluster
      Copy to Clipboard Toggle word wrap
    2. 编辑 failureDomains 参数,如下例所示:

      spec:
        replicas: 3
        selector:
          matchLabels:
            machine.openshift.io/cluster-api-cluster: jdoe3-whb8l
            machine.openshift.io/cluster-api-machine-role: master
            machine.openshift.io/cluster-api-machine-type: master
        state: Active
        strategy:
          type: RollingUpdate
        template:
          machineType: machines_v1beta1_machine_openshift_io
          machines_v1beta1_machine_openshift_io:
            failureDomains:
              platform: VSphere
              vsphere:
              - name: <failure_domain_1_name>
              - name: <failure_domain_2_name>
      # ...
      Copy to Clipboard Toggle word wrap
    3. 在继续操作前,验证您的 control plane 节点已完成更新。要做到这一点,请运行以下命令:

      $ oc get controlplanemachinesets.machine.openshift.io -n openshift-machine-api
      Copy to Clipboard Toggle word wrap
  3. 为您的故障域创建新的 MachineSet CR。

    1. 要检索现有 MachineSet CR 的配置以用作模板,请运行以下命令:

      $ oc get machinesets.machine.openshift.io -n openshift-machine-api <existing_machine_set> -o yaml > machineset-<failure_domain_name>.yaml
      Copy to Clipboard Toggle word wrap
    2. 根据需要复制模板,为基础架构文件中定义的每个故障域创建 MachineSet CR 文件。请参考以下示例:

      apiVersion: machine.openshift.io/v1beta1
      kind: MachineSet
      metadata:
        labels:
          machine.openshift.io/cluster-api-cluster: <infrastructure_id>
        name: <machineset_name>
        namespace: openshift-machine-api
      spec:
        replicas: 0
        selector:
          matchLabels:
            machine.openshift.io/cluster-api-cluster: <infrastructure_id>
            machine.openshift.io/cluster-api-machineset: <machineset_name>
        template:
          metadata:
            labels:
              machine.openshift.io/cluster-api-cluster: <infrastructure_id>
              machine.openshift.io/cluster-api-machine-role: worker
              machine.openshift.io/cluster-api-machine-type: worker
              machine.openshift.io/cluster-api-machineset: <machineset_name>
          spec:
            lifecycleHooks: {}
            metadata: {}
            providerSpec:
              value:
                apiVersion: machine.openshift.io/v1beta1
                credentialsSecret:
                  name: vsphere-cloud-credentials
                diskGiB: <disk_GiB>
                kind: VSphereMachineProviderSpec
                memoryMiB: <memory_in_MiB>
                metadata:
                  creationTimestamp: null
                network:
                  devices:
                  - networkName: VM Network
                numCPUs: <number_of_cpus>
                numCoresPerSocket: <number_of_cores_per_socket>
                snapshot: ""
                template: <template_name>
                userDataSecret:
                  name: worker-user-data
                workspace:
                  datacenter: <data_center_1>
                  datastore: /<data_center_1>/datastore/<datastore_1>
                  folder: /<data_center_1>/vm/<folder>
                  resourcePool: /<data_center_1>/host/<cluster_1>/Resources
                  server: <server_ip_address>
                  vmGroup: <name_of_vm_group_1>
      # ...
      Copy to Clipboard Toggle word wrap
    3. 对于每个 MachineSet CR 文件,运行以下命令:

      $ oc create -f <name_of_machine_set_file>.yaml
      Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2025 Red Hat