1.11. クラスター API
Cluster API は、Kubernetes クラスターのプロビジョニング、アップグレード、管理を簡素化する宣言型 API を提供します。multicluster engine Operator は、コアとなる Cluster API コンポーネントに加え、複数のインフラストラクチャープロバイダーとブートストラッププロバイダーをインストールすることで、さまざまなユースケースとプラットフォームをサポートします。スタンドアロンの multicluster engine Operator または Red Hat Advanced Cluster Management で Cluster API を使用する方法を説明します。次のプロセスを参照してください。
1.11.1. Cluster API を使用したマネージドクラスターのインストール リンクのコピーリンクがクリップボードにコピーされました!
metal3 インフラストラクチャープロバイダーと OpenShift Container Platform 支援ブートストラップおよびコントロールプレーンプロバイダーを使用して、Cluster API を備えた OpenShift Container Platform マネージドクラスターをインストールできます。
- `ControlPlane` はコントロールプレーンのプロパティーを定義します。
-
ClusterInfrastructureは、クラスターレベルのインフラストラクチャーの詳細を定義します。
前提条件
-
Red Hat Advanced Cluster Management インストールまたは multicluster engine Operator スタンドアロンインストールのいずれかからの
MultiClusterEngineリソースが必要です。 -
api.<cluster_name>.<base_domain>の API ベースドメインは、静的 API 仮想 IP を指している必要があります。 -
*.apps.<cluster_name>.<base_domain>のアプリケーションベースドメインは、Ingress 仮想 IP の静的 IP アドレスを指している必要があります。 -
クラスターの内部 API エンドポイント
api-int.<baseDomain>が必要です。
1.11.1.1. Cluster API を使用したワークロードのプロビジョニング リンクのコピーリンクがクリップボードにコピーされました!
ワークロードをプロビジョニングするために必要なサービスを有効にします。デフォルトでは、
assisted-serviceが有効になっています。デフォルトでは、cluster-api-provider-metal3-preview とcluster-api-provider-openshift-assisted-previewは無効になっています。3 つのサービスがすべてenabled: trueであることを確認します。以下のコマンドを実行してリソースを編集します。oc edit multiclusterengines.multicluster.openshift.io -n multicluster-engine.spec.overridesで、assisted-serviceコンポーネント、cluster-api-provider-metal3-previewコンポーネント、cluster-api-provider-openshift-assisted-previewコンポーネントをenabled: trueに設定します。次のconfigOverrides値を参照してください。- configOverrides: {} enabled: true name: assisted-service - configOverrides: {} enabled: true name: cluster-api ... - configOverrides: {} enabled: true name: cluster-api-provider-metal3-preview - configOverrides: {} enabled: true name: cluster-api-provider-openshift-assisted-preview- Central Infrastructure Management サービスの有効化手順は central infrastructure management サービスの有効化 を参照してください。
clusterNetwork仕様、controlPlaneRef仕様、およびinfrastructureRef仕様を使用してClusterリソースを設定します。次のClusterリソースを参照してください。apiVersion: cluster.x-k8s.io/v1beta1 kind: Cluster metadata: name: <cluster-name> namespace: <cluster-namespace> spec: clusterNetwork: pods: cidrBlocks: - 172.18.0.0/20 services: cidrBlocks: - 10.96.0.0/12 controlPlaneRef:1 apiVersion: controlplane.cluster.x-k8s.io/v1alpha2 kind: OpenshiftAssistedControlPlane name: <cluster-name> namespace: <cluster-namespace> infrastructureRef:2 apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 kind: Metal3Cluster name: <cluster-name> namespace: <cluster-namespace>以下のコマンドを実行して YAML コンテンツを適用します。
oc apply -f <filename>.yamldistributionVersion、apiVIPs、および SSH キーを含むOpenshiftAssistedControlPlaneリソースを設定します。distributionVersionフィールドに OpenShift Container Platform のバージョンを指定します。注記:
distributionVersionの値は OpenShift Container Platform Releases のイメージと一致します。次の YAML リソースを参照してください。apiVersion: controlplane.cluster.x-k8s.io/v1alpha2 kind: OpenshiftAssistedControlPlane metadata: name: <cluster-name> namespace: <cluster-namespace> annotations: {} spec:1 openshiftAssistedConfigSpec: sshAuthorizedKey: "{{ ssh_authorized_key }}" nodeRegistration: kubeletExtraLabels: - 'metal3.io/uuid="${METADATA_UUID}"' distributionVersion: <4.x.0> config: apiVIPs: - 192.168.222.40 ingressVIPs: - 192.168.222.41 baseDomain: lab.home pullSecretRef: name: "pull-secret" sshAuthorizedKey: "{{ ssh_authorized_key }}"2 machineTemplate: infrastructureRef: apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 kind: Metal3MachineTemplate name: <cluster-name-control-plane> namespace: <cluster-namespace> replicas: 3YAML ファイルを適用します。以下のコマンドを実行します。
oc apply -f <filename>.yaml- プルシークレットがない場合は、クラスターがコンテナーレジストリーからイメージをプルできるように、プルシークレットを作成する必要があります。プルシークレットを作成するには、次の手順を実行します。
イメージをプルするための YAML ファイルを作成します。
pull-secret.yamlという名前のファイルの次の例を参照してください。apiVersion: v1 kind: Secret metadata:1 name: pull-secret namespace: <cluster-namespace> data:2 .dockerconfigjson: <encoded_docker_configuration> type: kubernetes.io/dockerconfigjson次のコマンドを実行して、ファイルを適用します。
oc apply -f pull-secret.yamlベアメタル上のクラスターのデプロイメントに関連する情報が含まれる
Metal3Clusterインフラストラクチャーリソースを設定します。apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 kind: Metal3Cluster metadata: name: <cluster-name> namespace: <cluster-namespace> spec: controlPlaneEndpoint: host: <cluster-name>.lab.home1 port: 6443 noCloudProvider: true- 1
hostは、ClusterリソースのclusterNameを持つ<clusterName>.<baseDomain>*値であり、baseDomainはOpenshiftAssistedControlPlaneリソースで定義されます。
ファイルを適用します。以下のコマンドを実行します。
oc apply -f <filename>.yamlOpenshiftAssistedControlPlaneリソースから参照されるコントロールプレーンノードのMetal3MachineTemplateリソースを設定します。以下の YAML 例を参照してください。apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 kind: Metal3MachineTemplate metadata: name: <cluster-name> namespace: <cluster-namespace> spec: nodeReuse: false template: spec: automatedCleaningMode: disabled dataTemplate: name: <cluster-name-template> image:1 checksum: https://mirror.openshift.com/pub/openshift-v4/x86_64/dependencies/rhcos/4.19/4.19.0/sha256sum.txt checksumType: sha256 url: https://mirror.openshift.com/pub/openshift-v4/x86_64/dependencies/rhcos/4.19/4.19.0/rhcos-4.19.0-x86_64-nutanix.x86_64.qcow2 format: qcow2 --- apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 kind: Metal3DataTemplate metadata: name: <cluster-name-template> namespace: <cluster-namespace> spec: clusterName: <cluster-name>2 - 1
- イメージは、
distributionVersion値と OpenShift Container Platform Releases のバージョンと一致します。 - 2
clusterNameはClusterリソースと同じ値に設定します。
ファイルを適用します。以下のコマンドを実行します。
oc apply -f <filename>.yamlMetal3MachineTemplateを参照するMachineDeploymentリソースを使用してワーカーノードを設定します。以下は、YAML の例です。apiVersion: cluster.x-k8s.io/v1beta1 kind: MachineDeployment metadata: name: <cluster-name-worker> namespace: <cluster-namespace> labels: cluster.x-k8s.io/cluster-name: <cluster-name> spec: clusterName: <cluster-name> replicas: 2 selector: matchLabels: cluster.x-k8s.io/cluster-name: <cluster-name> template: metadata: labels: cluster.x-k8s.io/cluster-name: <cluster-name> spec: clusterName: <cluster-name> bootstrap:1 configRef: name: <cluster-name-worker> apiVersion: bootstrap.cluster.x-k8s.io/v1alpha1 kind: OpenshiftAssistedConfigTemplate infrastructureRef:2 name: <cluster-name-workers-2> apiVersion: infrastructure.cluster.x-k8s.io/v1alpha3 kind: Metal3MachineTemplateファイルを適用します。以下のコマンドを実行します。
oc apply -f <filename>.yamlMachineDeploymentで参照されるOpenshiftAssistedConfigTemplateリソースを作成します。次の YAML はワーカーノードのブートストラップ設定を定義し、Assisted Installer を使用してノードを登録するために使用されます。apiVersion: bootstrap.cluster.x-k8s.io/v1alpha1 kind: OpenshiftAssistedConfigTemplate metadata: name: <cluster-name-worker> namespace: <cluster-namespace> labels: cluster.x-k8s.io/cluster-name: cluster-name spec: template: spec: nodeRegistration: kubeletExtraLabels: - 'metal3.io/uuid="${METADATA_UUID}"'1 sshAuthorizedKey: "{{ ssh_authorized_key }}"2 MachineDeploymentリソースで参照されるMetal3MachineTemplateを作成します。以下の例を参照してください。apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 kind: Metal3MachineTemplate metadata: name: <cluster-name-workers-2> namespace: <cluster-namespace> spec: nodeReuse: false template: spec: automatedCleaningMode: metadata dataTemplate: name: <cluster-name-workers-template> image: checksum: https://mirror.openshift.com/pub/openshift-v4/x86_64/dependencies/rhcos/4.19/4.19.0/sha256sum.txt checksumType: sha256 url: https://mirror.openshift.com/pub/openshift-v4/x86_64/dependencies/rhcos/4.19/4.19.0/rhcos-4.19.0-x86_64-nutanix.x86_64.qcow2 format: qcow2 --- apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 kind: Metal3DataTemplate metadata: name: <cluster-name-workers-template> namespace: <cluster-namespace> spec: clusterName: <cluster-name>次のコマンドを実行して、YAML ファイルを保存し、クラスターをプロビジョニングします。
oc apply -f <filename>.yamlクラスターのプロビジョニングステータスを確認します。
oc get cluster --namespace <cluster-namespace> <cluster-name> -o yamlを実行して、Clusterリソースのステータスを確認します。次の出力とステータスを参照してください。
status: conditions: - lastTransitionTime: "2025-06-25T11:23:38Z" status: "True" type: Ready - lastTransitionTime: "2025-06-25T11:23:38Z" status: "True" type: ControlPlaneReady - lastTransitionTime: "2025-06-25T10:37:03Z" status: "True" type: InfrastructureReadyoc get metal3cluster --namespace <cluster-namespace> <cluster-name> -o yamlコマンドを実行して、クラスターインフラストラクチャーのステータスを確認します。次の出力とステータスを参照してください。
status: conditions: - lastTransitionTime: "2025-06-25T10:37:03Z" status: "True" type: Ready - lastTransitionTime: "2025-06-25T10:37:03Z" status: "True" type: BaremetalInfrastructureReadyコントロールプレーンのステータスを確認するには、
oc get openshiftassistedcontrolplane --namespace <cluster-namespace> <cluster-name> -o yamlコマンドを実行します。次の出力とステータスを参照してください。
status: conditions: - lastTransitionTime: "2025-06-25T11:23:38Z" status: "True" type: Ready - lastTransitionTime: "2025-06-25T11:23:38Z" status: "True" type: ControlPlaneReady - lastTransitionTime: "2025-06-25T10:45:48Z" status: "True" type: KubeconfigAvailable - lastTransitionTime: "2025-06-25T10:38:25Z" status: "True" type: MachinesCreated - lastTransitionTime: "2025-06-25T11:10:54Z" status: "True" type: MachinesReady - lastTransitionTime: "2025-06-25T11:23:38Z" status: "True" type: UpgradeCompletedoc get machinedeployment --namespace <cluster-namespace> <cluster-name> -o yamlコマンドを実行して、マシンのデプロイメントのステータスを確認します。次の出力とステータスを参照してください。
status: conditions: - lastTransitionTime: "2025-06-25T11:10:29Z" status: "True" type: Ready - lastTransitionTime: "2025-06-25T11:10:29Z" status: "True" type: Available - lastTransitionTime: "2025-06-25T11:10:29Z" status: "True" type: MachineSetReadykubectl get machine -l cluster.x-k8s.io/cluster-name=cluster-name -n test-capi -o yamlコマンドを実行して、マシンを確認します。次の出力とステータスを参照してください。
status: conditions: - lastTransitionTime: "2025-06-25T11:09:57Z" status: "True" type: Ready - lastTransitionTime: "2025-06-25T10:38:20Z" status: "True" type: BootstrapReady - lastTransitionTime: "2025-06-25T11:09:57Z" status: "True" type: InfrastructureReady - lastTransitionTime: "2025-06-25T11:10:29Z" status: "True" type: NodeHealthyクラスターにアクセスします。
kubeconfigファイルを取得するには、次のコマンドを実行します。oc get secret -n test-capi cluster-name-admin-kubeconfig -o json | jq -r .data.kubeconfig | base64 --decode > kubeconfig-
kubeconfigファイルを使用してクラスターにアクセスするには、次のコマンドを実行します。
export KUBECONFIG=$(realpath kubeconfig) oc get nodes