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>
namespace: openshift-cluster-api
spec:
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: <infrastructure_kind>
name: <cluster_name>
namespace: openshift-cluster-api
剩余的 Cluster API 资源是特定于供应商的。请参考集群的 YAML 文件示例:
12.2.2. 用于配置 Amazon Web Services 集群的 YAML 文件示例 复制链接链接已复制到粘贴板!
有些 Cluster API 资源是特定于供应商的。本节中的 YAML 文件示例显示 Amazon Web Services (AWS) 集群的配置。
基础架构资源是特定于提供程序的,定义由集群中所有机器集(如地区和子网)共享的属性。机器集在创建机器时引用此资源。
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: AWSCluster
metadata:
name: <cluster_name>
namespace: openshift-cluster-api
spec:
region: <region>
机器模板资源是特定于提供程序的,定义机器集创建的机器的基本属性。机器集在创建机器时引用此模板。
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha4
kind: AWSMachineTemplate
metadata:
name: <template_name>
namespace: openshift-cluster-api
spec:
template:
spec:
uncompressedUserData: true
iamInstanceProfile: ....
instanceType: m5.large
cloudInit:
insecureSkipSecretsManager: true
ami:
id: ....
subnet:
filters:
- name: tag:Name
values:
- ...
additionalSecurityGroups:
- filters:
- name: tag:Name
values:
- ...
机器集资源定义它创建的机器的额外属性。机器集也会在创建机器时引用基础架构资源和机器模板。
apiVersion: cluster.x-k8s.io/v1alpha4
kind: MachineSet
metadata:
name: <machine_set_name>
namespace: openshift-cluster-api
spec:
clusterName: <cluster_name>
replicas: 1
selector:
matchLabels:
test: example
template:
metadata:
labels:
test: example
spec:
bootstrap:
dataSecretName: worker-user-data
clusterName: <cluster_name>
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha4
kind: AWSMachineTemplate
name: <cluster_name>
12.2.3. 用于配置 Google Cloud Platform 集群的 YAML 文件示例 复制链接链接已复制到粘贴板!
有些 Cluster API 资源是特定于供应商的。本节中的 YAML 文件示例显示 Google Cloud Platform (GCP) 集群的配置。
基础架构资源是特定于提供程序的,定义由集群中所有机器集(如地区和子网)共享的属性。机器集在创建机器时引用此资源。
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: GCPCluster
metadata:
name: <cluster_name>
spec:
network:
name: <cluster_name>-network
project: <project>
region: <region>
机器模板资源是特定于提供程序的,定义机器集创建的机器的基本属性。机器集在创建机器时引用此模板。
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: GCPMachineTemplate
metadata:
name: <template_name>
namespace: openshift-cluster-api
spec:
template:
spec:
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
机器集资源定义它创建的机器的额外属性。机器集也会在创建机器时引用基础架构资源和机器模板。
apiVersion: cluster.x-k8s.io/v1beta1
kind: MachineSet
metadata:
name: <machine_set_name>
namespace: openshift-cluster-api
spec:
clusterName: <cluster_name>
replicas: 1
selector:
matchLabels:
test: test
template:
metadata:
labels:
test: test
spec:
bootstrap:
dataSecretName: worker-user-data
clusterName: <cluster_name>
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: GCPMachineTemplate
name: <machine_set_name>
failureDomain: <failure_domain>