12.2. YAML 文件示例

对于 Cluster API 技术预览,您必须创建 Cluster API 需要的主要资源。本节中的 YAML 文件示例演示如何使这些资源共同工作,并为他们创建适合您环境的机器配置设置。

12.2.1. Cluster API 集群资源的 YAML 示例

集群资源定义集群的名称和基础架构供应商,并由 Cluster API 管理。此资源对所有提供程序具有相同的结构。

apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
metadata:
  name: <cluster_name> 1
  namespace: openshift-cluster-api
spec:
  infrastructureRef:
    apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
    kind: <infrastructure_kind> 2
    name: <cluster_name> 3
    namespace: openshift-cluster-api
1 3
指定集群的名称。
2
指定集群的基础架构类型。有效值为:
  • AWSCluster :集群在 Amazon Web Services (AWS) 上运行。
  • GCPCluster :集群在 Google Cloud Platform (GCP) 上运行。

剩余的 Cluster API 资源是特定于供应商的。请参考集群的 YAML 文件示例:

12.2.2. 用于配置 Amazon Web Services 集群的 YAML 文件示例

有些 Cluster API 资源是特定于供应商的。本节中的 YAML 文件示例显示 Amazon Web Services (AWS) 集群的配置。

12.2.2.1. Amazon Web Services 上 Cluster API 基础架构资源的 YAML 示例

基础架构资源是特定于提供程序的,定义由集群中所有计算机器集(如地区和子网)共享的属性。计算机器集在创建机器时引用此资源。

apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: AWSCluster 1
metadata:
  name: <cluster_name> 2
  namespace: openshift-cluster-api
spec:
  region: <region> 3
1
指定集群的基础架构类型。这个值必须与您的平台的值匹配。
2
指定集群的名称。
3
指定 AWS 区域。

12.2.2.2. Amazon Web Services 上 Cluster API 机器模板资源的 YAML 示例

机器模板资源是特定于提供程序的,定义计算机器创建的机器的基本属性。计算机器设置在创建机器时引用此模板。

apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: AWSMachineTemplate 1
metadata:
  name: <template_name> 2
  namespace: openshift-cluster-api
spec:
  template:
    spec: 3
      uncompressedUserData: true
      iamInstanceProfile: ....
      instanceType: m5.large
      cloudInit:
        insecureSkipSecretsManager: true
      ami:
        id: ....
      subnet:
        filters:
        - name: tag:Name
          values:
          - ...
      additionalSecurityGroups:
      - filters:
        - name: tag:Name
          values:
          - ...
1
指定机器模板类型。这个值必须与您的平台的值匹配。
2
为机器模板指定名称。
3
指定您的环境的详情。这里的值为示例。

12.2.2.3. Amazon Web Services 上 Cluster API 机器集资源的 YAML 示例

计算机器设置资源定义它所创建的机器的额外属性。计算机器集也会在创建机器时引用基础架构资源和机器模板。

apiVersion: cluster.x-k8s.io/v1beta1
kind: MachineSet
metadata:
  name: <machine_set_name> 1
  namespace: openshift-cluster-api
spec:
  clusterName: <cluster_name> 2
  replicas: 1
  selector:
    matchLabels:
      test: example
  template:
    metadata:
      labels:
        test: example
    spec:
      bootstrap:
         dataSecretName: worker-user-data 3
      clusterName: <cluster_name> 4
      infrastructureRef:
        apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
        kind: AWSMachineTemplate 5
        name: <cluster_name> 6
1
为计算机器设置指定一个名称。
2 4 6
指定集群的名称。
3
对于 Cluster API 技术预览,Operator 可以使用 openshift-machine-api 命名空间中的 worker 用户数据 secret。
5
指定机器模板类型。这个值必须与您的平台的值匹配。

12.2.3. 用于配置 Google Cloud Platform 集群的 YAML 文件示例

有些 Cluster API 资源是特定于供应商的。本节中的 YAML 文件示例显示 Google Cloud Platform (GCP) 集群的配置。

12.2.3.1. Google Cloud Platform 上 Cluster API 基础架构资源的 YAML 示例

基础架构资源是特定于提供程序的,定义由集群中所有计算机器集(如地区和子网)共享的属性。计算机器集在创建机器时引用此资源。

apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: GCPCluster 1
metadata:
  name: <cluster_name> 2
spec:
  network:
    name: <cluster_name>-network 3
  project: <project> 4
  region: <region> 5
1
指定集群的基础架构类型。这个值必须与您的平台的值匹配。
2 3
指定集群的名称。
4
指定 GCP 项目名称。
5
指定 GCP 区域。

12.2.3.2. Google Cloud Platform 上的 Cluster API 机器模板资源的 YAML 示例

机器模板资源是特定于提供程序的,定义计算机器创建的机器的基本属性。计算机器设置在创建机器时引用此模板。

apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: GCPMachineTemplate 1
metadata:
  name: <template_name> 2
  namespace: openshift-cluster-api
spec:
  template:
    spec: 3
      rootDeviceType: pd-ssd
      rootDeviceSize: 128
      instanceType: n1-standard-4
      image: projects/rhcos-cloud/global/images/rhcos-411-85-202203181601-0-gcp-x86-64
      subnet: <cluster_name>-worker-subnet
      serviceAccounts:
        email: <service_account_email_address>
        scopes:
          - https://www.googleapis.com/auth/cloud-platform
      additionalLabels:
        kubernetes-io-cluster-<cluster_name>: owned
      additionalNetworkTags:
        - <cluster_name>-worker
      ipForwarding: Disabled
1
指定机器模板类型。这个值必须与您的平台的值匹配。
2
为机器模板指定名称。
3
指定您的环境的详情。这里的值为示例。

12.2.3.3. Google Cloud Platform 上 Cluster API 机器集资源的 YAML 示例

计算机器设置资源定义它所创建的机器的额外属性。计算机器集也会在创建机器时引用基础架构资源和机器模板。

apiVersion: cluster.x-k8s.io/v1beta1
kind: MachineSet
metadata:
  name: <machine_set_name> 1
  namespace: openshift-cluster-api
spec:
  clusterName: <cluster_name> 2
  replicas: 1
  selector:
    matchLabels:
      test: test
  template:
    metadata:
      labels:
        test: test
    spec:
      bootstrap:
         dataSecretName: worker-user-data 3
      clusterName: <cluster_name> 4
      infrastructureRef:
        apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
        kind: GCPMachineTemplate 5
        name: <machine_set_name> 6
      failureDomain: <failure_domain> 7
1 6
为计算机器设置指定一个名称。
2 4
指定集群的名称。
3
对于 Cluster API 技术预览,Operator 可以使用 openshift-machine-api 命名空间中的 worker 用户数据 secret。
5
指定机器模板类型。这个值必须与您的平台的值匹配。
7
指定 GCP 区域中的故障域。