7.2. 为生产环境创建基础架构机器集
在生产部署中,建议您至少部署三个机器集来容纳基础架构组件。OpenShift Logging 和 Red Hat OpenShift Service Mesh 部署 Elasticsearch,这需要三个实例安装到不同的节点上。这些节点可以部署到不同的可用区,以实现高可用性。这样的配置需要三个不同的计算机集,每个可用区对应一个。在没有多个可用区的全局 Azure 区域,您可以使用可用性集来确保高可用性。
7.2.1. 为不同云创建机器集 复制链接链接已复制到粘贴板!
使用云的示例机器集。
7.2.1.1. AWS 上机器设置自定义资源的 YAML 示例 复制链接链接已复制到粘贴板!
此 YAML 示例定义了一个在 us-east-1a Amazon Web Services(AWS)区域中运行的机器集,并创建通过 node-role.kubernetes.io/infra: "" 标记的节点。
在本例中,<infrastructure_id> 是基础架构 ID 标签,该标签基于您在置备集群时设定的集群 ID,而 <infra> 则是要添加的节点标签。
apiVersion: machine.openshift.io/v1beta1
kind: MachineSet
metadata:
labels:
machine.openshift.io/cluster-api-cluster: <infrastructure_id>
name: <infrastructure_id>-infra-<zone>
namespace: openshift-machine-api
spec:
replicas: 1
selector:
matchLabels:
machine.openshift.io/cluster-api-cluster: <infrastructure_id>
machine.openshift.io/cluster-api-machineset: <infrastructure_id>-infra-<zone>
template:
metadata:
labels:
machine.openshift.io/cluster-api-cluster: <infrastructure_id>
machine.openshift.io/cluster-api-machine-role: <infra>
machine.openshift.io/cluster-api-machine-type: <infra>
machine.openshift.io/cluster-api-machineset: <infrastructure_id>-infra-<zone>
spec:
metadata:
labels:
node-role.kubernetes.io/infra: ""
taints:
- key: node-role.kubernetes.io/infra
effect: NoSchedule
providerSpec:
value:
ami:
id: ami-046fe691f52a953f9
apiVersion: awsproviderconfig.openshift.io/v1beta1
blockDevices:
- ebs:
iops: 0
volumeSize: 120
volumeType: gp2
credentialsSecret:
name: aws-cloud-credentials
deviceIndex: 0
iamInstanceProfile:
id: <infrastructure_id>-worker-profile
instanceType: m4.large
kind: AWSMachineProviderConfig
placement:
availabilityZone: us-east-1a
region: us-east-1
securityGroups:
- filters:
- name: tag:Name
values:
- <infrastructure_id>-worker-sg
subnet:
filters:
- name: tag:Name
values:
- <infrastructure_id>-private-us-east-1a
tags:
- name: kubernetes.io/cluster/<infrastructure_id>
value: owned
userDataSecret:
name: worker-user-data
- 1 3 5 12 13 14 15
- 指定基于置备集群时所设置的集群 ID 的基础架构 ID。如果已安装 OpenShift CLI,您可以通过运行以下命令来获取基础架构 ID:
$ oc get -o jsonpath='{.status.infrastructureName}{"\n"}' infrastructure cluster - 2 4 8
- 指定基础架构 ID、
<infra>节点标签和区域。 - 6 7 9
- 指定
<infra>节点标签。 - 10
- 指定一个污点,以防止将用户工作负载调度到 infra 节点上。
- 11
- 为您的 OpenShift Container Platform 节点的 AWS 区域指定有效的 Red Hat Enterprise Linux CoreOS (RHCOS) AMI。
$ oc -n openshift-machine-api \ -o jsonpath='{.spec.template.spec.providerSpec.value.ami.id}{"\n"}' \ get machineset/<infrastructure_id>-worker-<zone>
在 AWS 上运行的机器集支持非保证的 Spot 实例。与 AWS 上的 On-Demand 实例相比,您可以使用 Spot 实例以较低价格来节约成本。通过在 MachineSet YAML 文件中添加 spotMarketOptions 来配置 Spot 实例。
7.2.1.2. Azure 上机器设置自定义资源的 YAML 示例 复制链接链接已复制到粘贴板!
此 YAML 示例定义了一个在区域中的 1 Microsoft Azure 区域中运行的机器集,并创建通过 node-role.kubernetes.io/infra: "" 标记的节点。
在本例中,<infrastructure_id> 是基础架构 ID 标签,该标签基于您在置备集群时设定的集群 ID,而 <infra> 则是要添加的节点标签。
apiVersion: machine.openshift.io/v1beta1
kind: MachineSet
metadata:
labels:
machine.openshift.io/cluster-api-cluster: <infrastructure_id>
machine.openshift.io/cluster-api-machine-role: <infra>
machine.openshift.io/cluster-api-machine-type: <infra>
name: <infrastructure_id>-infra-<region>
namespace: openshift-machine-api
spec:
replicas: 1
selector:
matchLabels:
machine.openshift.io/cluster-api-cluster: <infrastructure_id>
machine.openshift.io/cluster-api-machineset: <infrastructure_id>-infra-<region>
template:
metadata:
creationTimestamp: null
labels:
machine.openshift.io/cluster-api-cluster: <infrastructure_id>
machine.openshift.io/cluster-api-machine-role: <infra>
machine.openshift.io/cluster-api-machine-type: <infra>
machine.openshift.io/cluster-api-machineset: <infrastructure_id>-infra-<region>
spec:
metadata:
creationTimestamp: null
labels:
node-role.kubernetes.io/infra: ""
taints:
- key: node-role.kubernetes.io/infra
effect: NoSchedule
providerSpec:
value:
apiVersion: azureproviderconfig.openshift.io/v1beta1
credentialsSecret:
name: azure-cloud-credentials
namespace: openshift-machine-api
image:
offer: ""
publisher: ""
resourceID: /resourceGroups/<infrastructure_id>-rg/providers/Microsoft.Compute/images/<infrastructure_id>
sku: ""
version: ""
internalLoadBalancer: ""
kind: AzureMachineProviderSpec
location: <region>
managedIdentity: <infrastructure_id>-identity
metadata:
creationTimestamp: null
natRule: null
networkResourceGroup: ""
osDisk:
diskSizeGB: 128
managedDisk:
storageAccountType: Premium_LRS
osType: Linux
publicIP: false
publicLoadBalancer: ""
resourceGroup: <infrastructure_id>-rg
sshPrivateKey: ""
sshPublicKey: ""
subnet: <infrastructure_id>-<role>-subnet
userDataSecret:
name: worker-user-data
vmSize: Standard_DS4_v2
vnet: <infrastructure_id>-vnet
zone: "1"
- 1 5 7 13 15 16 17 20
- 指定基于置备集群时所设置的集群 ID 的基础架构 ID。如果已安装 OpenShift CLI,您可以通过运行以下命令来获取基础架构 ID:
$ oc get -o jsonpath='{.status.infrastructureName}{"\n"}' infrastructure cluster您可以运行以下命令来获取子网:
$ oc -n openshift-machine-api \ -o jsonpath='{.spec.template.spec.providerSpec.value.subnet}{"\n"}' \ get machineset/<infrastructure_id>-worker-centralus1您可以运行以下命令来获取 vnet:
$ oc -n openshift-machine-api \ -o jsonpath='{.spec.template.spec.providerSpec.value.vnet}{"\n"}' \ get machineset/<infrastructure_id>-worker-centralus1 - 2 3 8 9 11 18 19
- 指定
<infra>节点标签。 - 4 6 10
- 指定基础架构 ID、
<infra>节点标签和地区。 - 12
- 指定一个污点,以防止将用户工作负载调度到 infra 节点上。
- 14
- 指定要放置机器的区域。
- 21
- 指定您所在地区(region)内要放置机器的区域 (zone)。确保您的地区支持您指定的区域。
在 Azure 上运行的机器集支持非保证的 Spot 虚拟机。与 Azure 上的标准虚拟机相比,您可以使用 Spot 虚拟机以较低价格节约成本。您可以通过在 MachineSet YAML 文件中添加 spotVMOptions 来配置 Spot 虚拟机。
7.2.1.3. GCP 上机器设置自定义资源的 YAML 示例 复制链接链接已复制到粘贴板!
此 YAML 示例定义了一个在 Google Cloud Platform (GCP) 中运行的机器集,并创建通过 node-role.kubernetes.io/infra: "" 标记的节点。
在本例中,<infrastructure_id> 是基础架构 ID 标签,该标签基于您在置备集群时设定的集群 ID,而 <infra> 则是要添加的节点标签。
apiVersion: machine.openshift.io/v1beta1
kind: MachineSet
metadata:
labels:
machine.openshift.io/cluster-api-cluster: <infrastructure_id>
name: <infrastructure_id>-w-a
namespace: openshift-machine-api
spec:
replicas: 1
selector:
matchLabels:
machine.openshift.io/cluster-api-cluster: <infrastructure_id>
machine.openshift.io/cluster-api-machineset: <infrastructure_id>-w-a
template:
metadata:
creationTimestamp: null
labels:
machine.openshift.io/cluster-api-cluster: <infrastructure_id>
machine.openshift.io/cluster-api-machine-role: <infra>
machine.openshift.io/cluster-api-machine-type: <infra>
machine.openshift.io/cluster-api-machineset: <infrastructure_id>-w-a
spec:
metadata:
labels:
node-role.kubernetes.io/infra: ""
taints:
- key: node-role.kubernetes.io/infra
effect: NoSchedule
providerSpec:
value:
apiVersion: gcpprovider.openshift.io/v1beta1
canIPForward: false
credentialsSecret:
name: gcp-cloud-credentials
deletionProtection: false
disks:
- autoDelete: true
boot: true
image: <path_to_image>
labels: null
sizeGb: 128
type: pd-ssd
gcpMetadata:
- key: <custom_metadata_key>
value: <custom_metadata_value>
kind: GCPMachineProviderSpec
machineType: n1-standard-4
metadata:
creationTimestamp: null
networkInterfaces:
- network: <infrastructure_id>-network
subnetwork: <infrastructure_id>-worker-subnet
projectID: <project_name>
region: us-central1
serviceAccounts:
- email: <infrastructure_id>-w@<project_name>.iam.gserviceaccount.com
scopes:
- https://www.googleapis.com/auth/cloud-platform
tags:
- <infrastructure_id>-worker
userDataSecret:
name: worker-user-data
zone: us-central1-a
- 1 2 3 4 5 8 13 14 16 18
- 指定基于置备集群时所设置的集群 ID 的基础架构 ID。如果已安装 OpenShift CLI,您可以通过运行以下命令来获取基础架构 ID:
$ oc get -o jsonpath='{.status.infrastructureName}{"\n"}' infrastructure cluster - 6 7 9
- 指定
<infra>节点标签。 - 10
- 指定一个污点,以防止将用户工作负载调度到 infra 节点上。
- 11
- 指定当前机器集中使用的镜像的路径。如果已安装 OpenShift CLI,您可以通过运行以下命令来获取镜像的路径:
$ oc -n openshift-machine-api \ -o jsonpath='{.spec.template.spec.providerSpec.value.disks[0].image}{"\n"}' \ get machineset/<infrastructure_id>-worker-a - 12
- 可选:以
key:value对的形式指定自定义元数据。例如,请参阅 GCP 文档 来设置 自定义元数据。 - 15 17
- 指定用于集群的 GCP 项目的名称。
在 GCP 上运行的机器集支持非保证的可抢占虚拟机实例。与 GCP 上的普通实例相比,您可以使用抢占虚拟机实例以较低价格节约成本。您可以通过在 MachineSet YAML 文件中添加 preemptible,配置抢占的虚拟机实例。
7.2.1.4. RHOSP 上机器设置自定义资源的 YAML 示例 复制链接链接已复制到粘贴板!
此 YAML 示例定义了一个在 Red Hat OpenStack Platform(RHOSP)上运行的机器集,并创建带有 node-role.kubernetes.io/infra: "" 标记的节点
在本例中,<infrastructure_id> 是基础架构 ID 标签,该标签基于您在置备集群时设定的集群 ID,而 <infra> 则是要添加的节点标签。
apiVersion: machine.openshift.io/v1beta1
kind: MachineSet
metadata:
labels:
machine.openshift.io/cluster-api-cluster: <infrastructure_id>
machine.openshift.io/cluster-api-machine-role: <infra>
machine.openshift.io/cluster-api-machine-type: <infra>
name: <infrastructure_id>-infra
namespace: openshift-machine-api
spec:
replicas: <number_of_replicas>
selector:
matchLabels:
machine.openshift.io/cluster-api-cluster: <infrastructure_id>
machine.openshift.io/cluster-api-machineset: <infrastructure_id>-infra
template:
metadata:
labels:
machine.openshift.io/cluster-api-cluster: <infrastructure_id>
machine.openshift.io/cluster-api-machine-role: <infra>
machine.openshift.io/cluster-api-machine-type: <infra>
machine.openshift.io/cluster-api-machineset: <infrastructure_id>-infra
spec:
metadata:
creationTimestamp: null
labels:
node-role.kubernetes.io/infra: ""
taints:
- key: node-role.kubernetes.io/infra
effect: NoSchedule
providerSpec:
value:
apiVersion: openstackproviderconfig.openshift.io/v1alpha1
cloudName: openstack
cloudsSecret:
name: openstack-cloud-credentials
namespace: openshift-machine-api
flavor: <nova_flavor>
image: <glance_image_name_or_location>
serverGroupID: <optional_UUID_of_server_group>
kind: OpenstackProviderSpec
networks:
- filter: {}
subnets:
- filter:
name: <subnet_name>
tags: openshiftClusterID=<infrastructure_id>
primarySubnet: <rhosp_subnet_UUID>
securityGroups:
- filter: {}
name: <infrastructure_id>-worker
serverMetadata:
Name: <infrastructure_id>-worker
openshiftClusterID: <infrastructure_id>
tags:
- openshiftClusterID=<infrastructure_id>
trunk: true
userDataSecret:
name: worker-user-data
availabilityZone: <optional_openstack_availability_zone>
- 1 5 7 14 16 17 18 19
- 指定基于置备集群时所设置的集群 ID 的基础架构 ID。如果已安装 OpenShift CLI,您可以通过运行以下命令来获取基础架构 ID:
$ oc get -o jsonpath='{.status.infrastructureName}{"\n"}' infrastructure cluster - 2 3 8 9 20
- 指定
<infra>节点标签。 - 4 6 10
- 指定基础架构 ID 和
<infra>节点标签。 - 11
- 指定一个污点,以防止将用户工作负载调度到 infra 节点上。
- 12
- 13
- 部署到多个网络需要。如果部署到多个网络,这个列表必须包含用作
primarySubnet值的网络。 - 15
- 指定您要发布节点端点的 RHOSP 子网。通常,这与
install-config.yaml文件中的machineSubnet值相同。
7.2.1.5. RHV 上机器集自定义资源的 YAML 示例 复制链接链接已复制到粘贴板!
此 YAML 示例定义了一个在 RHV 上运行的机器集,并创建标记为 node-role.kubernetes.io/<node_role>: "" 的节点。
在本例中,<infrastructure_id> 是基础架构 ID 标签,该标签基于您在置备集群时设定的集群 ID,而 <role> 则是要添加的节点标签。
apiVersion: machine.openshift.io/v1beta1
kind: MachineSet
metadata:
labels:
machine.openshift.io/cluster-api-cluster: <infrastructure_id>
machine.openshift.io/cluster-api-machine-role: <role>
machine.openshift.io/cluster-api-machine-type: <role>
name: <infrastructure_id>-<role>
namespace: openshift-machine-api
spec:
replicas: <number_of_replicas>
selector:
matchLabels:
machine.openshift.io/cluster-api-cluster: <infrastructure_id>
machine.openshift.io/cluster-api-machineset: <infrastructure_id>-<role>
template:
metadata:
labels:
machine.openshift.io/cluster-api-cluster: <infrastructure_id>
machine.openshift.io/cluster-api-machine-role: <role>
machine.openshift.io/cluster-api-machine-type: <role>
machine.openshift.io/cluster-api-machineset: <infrastructure_id>-<role>
spec:
metadata:
labels:
node-role.kubernetes.io/<role>: ""
providerSpec:
value:
apiVersion: ovirtproviderconfig.machine.openshift.io/v1beta1
cluster_id: <ovirt_cluster_id>
template_name: <ovirt_template_name>
instance_type_id: <instance_type_id>
cpu:
sockets: <number_of_sockets>
cores: <number_of_cores>
threads: <number_of_threads>
memory_mb: <memory_size>
os_disk:
size_gb: <disk_size>
network_interfaces:
vnic_profile_id: <vnic_profile_id>
credentialsSecret:
name: ovirt-credentials
kind: OvirtMachineProviderSpec
type: <workload_type>
userDataSecret:
name: worker-user-data
- 1 7 9
- 指定基于置备集群时所设置的集群 ID 的基础架构 ID。如果已安装 OpenShift CLI(
oc)软件包,您可以通过运行以下命令来获取基础架构 ID:$ oc get -o jsonpath='{.status.infrastructureName}{"\n"}' infrastructure cluster - 2 3 10 11 13
- 指定要添加的节点标签。
- 4 8 12
- 指定基础架构 ID 和节点标签。这两个字符串不能超过 35 个字符。
- 5
- 指定要创建的机器数量。
- 6
- 机器的选择器。
- 14
- 指定此虚拟机实例所属的 RHV 集群的 UUID。
- 15
- 指定用于创建机器的 RHV VM 模板。
- 16
- 可选:指定虚拟机实例类型。警告
instance_type_id字段已弃用,并将在以后的发行版本中删除。如果包含这个参数,则不需要指定包括 CPU 和内存在内的虚拟机的硬件参数,因为这个参数会覆盖所有硬件参数。
- 17
- 可选:CPU 字段包含 CPU 配置,包括插槽、内核和线程。
- 18
- 可选:指定虚拟机的插槽数量。
- 19
- 可选:指定每个插槽的内核数。
- 20
- 可选:指定每个内核的线程数量。
- 21
- 可选:指定虚拟机的内存大小(MiB)。
- 22
- 可选:节点的 Root 磁盘。
- 23
- 可选:指定可引导磁盘的大小(GiB)。
- 24
- 可选:虚拟机网络接口列表。如果包含此参数,OpenShift Container Platform 会丢弃来自模板中的所有网络接口并创建新接口。
- 25
- 可选:指定 vNIC 配置集 ID。
- 26
- 指定包含 RHV 凭证的 secret 名称。
- 27
- 可选:指定实例优化的工作负载类型。这个值会影响
RHV VM参数。支持的值包括:desktop、server(默认)、high_performance。high_performance提高了虚拟机的性能,但存在一些限制。例如,您无法使用图形控制台访问虚拟机。详情请参阅虚拟机器管理指南中的 Configuring High Performance Virtual Machines, Templates, and Pools。
因为 RHV 在创建虚拟机时使用模板,如果您没有为可选参数指定值,RHV 将使用模板中指定的参数值。
7.2.1.6. vSphere 上机器设置自定义资源的 YAML 示例 复制链接链接已复制到粘贴板!
此 YAML 示例定义了一个在 VMware vSphere 上运行的机器集,并创建标记为 node-role.kubernetes.io/infra: "" 的节点。
在本例中,<infrastructure_id> 是基础架构 ID 标签,该标签基于您在置备集群时设定的集群 ID,而 <infra> 则是要添加的节点标签。
apiVersion: machine.openshift.io/v1beta1
kind: MachineSet
metadata:
creationTimestamp: null
labels:
machine.openshift.io/cluster-api-cluster: <infrastructure_id>
name: <infrastructure_id>-infra
namespace: openshift-machine-api
spec:
replicas: 1
selector:
matchLabels:
machine.openshift.io/cluster-api-cluster: <infrastructure_id>
machine.openshift.io/cluster-api-machineset: <infrastructure_id>-infra
template:
metadata:
creationTimestamp: null
labels:
machine.openshift.io/cluster-api-cluster: <infrastructure_id>
machine.openshift.io/cluster-api-machine-role: <infra>
machine.openshift.io/cluster-api-machine-type: <infra>
machine.openshift.io/cluster-api-machineset: <infrastructure_id>-infra
spec:
metadata:
creationTimestamp: null
labels:
node-role.kubernetes.io/infra: ""
taints:
- key: node-role.kubernetes.io/infra
effect: NoSchedule
providerSpec:
value:
apiVersion: vsphereprovider.openshift.io/v1beta1
credentialsSecret:
name: vsphere-cloud-credentials
diskGiB: 120
kind: VSphereMachineProviderSpec
memoryMiB: 8192
metadata:
creationTimestamp: null
network:
devices:
- networkName: "<vm_network_name>"
numCPUs: 4
numCoresPerSocket: 1
snapshot: ""
template: <vm_template_name>
userDataSecret:
name: worker-user-data
workspace:
datacenter: <vcenter_datacenter_name>
datastore: <vcenter_datastore_name>
folder: <vcenter_vm_folder_path>
resourcepool: <vsphere_resource_pool>
server: <vcenter_server_ip>
- 1 3 5
- 指定基于置备集群时所设置的集群 ID 的基础架构 ID。如果已安装 OpenShift CLI(
oc)软件包,您可以通过运行以下命令来获取基础架构 ID:$ oc get -o jsonpath='{.status.infrastructureName}{"\n"}' infrastructure cluster - 2 4 8
- 指定基础架构 ID 和
<infra>节点标签。 - 6 7 9
- 指定
<infra>节点标签。 - 10
- 指定一个污点,以防止将用户工作负载调度到 infra 节点上。
- 11
- 指定要将机器集部署到的 vSphere VM 网络。此虚拟机网络必须是集群中其他计算机器所处的位置。
- 12
- 指定要使用的 vSphere 虚拟机模板,如
user-5ddjd-rhcos。 - 13
- 指定要将机器集部署到的 vCenter Datacenter。
- 14
- 指定要部署机器集的 vCenter Datastore。
- 15
- 指定 vCenter 中 vSphere 虚拟机文件夹的路径,如
/dc1/vm/user-inst-5ddjd。 - 16
- 指定虚拟机的 vSphere 资源池。
- 17
- 指定 vCenter 服务器 IP 或完全限定域名。