1.11. クラスター API
Cluster API は、Kubernetes クラスターのプロビジョニング、アップグレード、管理を簡素化する宣言型 API を提供します。multicluster engine Operator は、コアとなる Cluster API コンポーネントに加え、複数のインフラストラクチャープロバイダーとブートストラッププロバイダーをインストールすることで、さまざまなユースケースとプラットフォームをサポートします。スタンドアロンの multicluster engine Operator または Red Hat Advanced Cluster Management で Cluster API を使用する方法を説明します。次のプロセスを参照してください。
- Cluster API を使用したマネージドクラスターのインストール
- Cluster API クラスター向けにハブクラスターを準備する (テクノロジープレビュー)
- Cluster API クラスターの自動インポートの有効化 (テクノロジープレビュー)
- Cluster API マネージドクラスターで AWS 認証情報から IAM ロールに切り替える (テクノロジープレビュー)
- Cluster API を使用して Red Hat OpenShift Service on AWS with Hosted Control Plane クラスターを作成するための準備 (テクノロジープレビュー)
- Cluster API を使用して Red Hat OpenShift Service on AWS with Hosted Control Plane クラスターを作成する (テクノロジープレビュー)
- Cluster API を使用して、Red Hat OpenShift Service on AWS with Hosted Control Plane クラスターを削除する (テクノロジープレビュー)
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 を指している必要があります。 次のアプリケーションベースドメインは、Ingress VIP の静的 IP アドレスを指す必要があります。
*.apps.<cluster_name>.<base_domain>-
クラスターの内部 API エンドポイント
api-int.<baseDomain>が必要です。 Cluster API Provider OpenShift Assisted には、以下のコンポーネントが必要です。
- Cluster API: コアコンポーネントは、管理クラスター内で必要なカスタムリソース定義とコントローラーを提供します。
- Assisted サービス: このサービスは、multicluster engine for Kubernetes Operator における Red Hat OpenShift のインフラストラクチャー Operator によってプロビジョニングされます。サービスが、アクセス可能で、かつ正常に動作していることを確認してください。
-
インフラストラクチャープロバイダー:
cluster-api-provider-metal3などのプロバイダーは、物理リソースまたは仮想リソースを管理します。
手順
ワークロードをプロビジョニングするために必要なサービスを有効にします。デフォルトでは、
assisted-serviceが有効になっています。デフォルトでは、cluster-api-provider-metal3とcluster-api-provider-openshift-assistedは、無効になっています。3 つのサービスがすべてenabled: trueであることを確認します。以下のコマンドを実行してリソースを編集します。oc edit multiclusterengines.multicluster.openshift.io -n multicluster-engineassisted-serviceコンポーネント、cluster-api-provider-metal3コンポーネント、cluster-api-provider-openshift-assistedコンポーネントの.spec.overridesでenabled: trueを設定します。次のconfigOverrides値を参照してください。- configOverrides: {} enabled: true name: assisted-service - configOverrides: {} enabled: true name: cluster-api ... - configOverrides: {} enabled: true name: cluster-api-provider-metal3 - configOverrides: {} enabled: true name: cluster-api-provider-openshift-assisted- 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: apiVersion: controlplane.cluster.x-k8s.io/v1alpha2 kind: OpenshiftAssistedControlPlane name: <cluster-name> namespace: <cluster-namespace> infrastructureRef: apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 kind: Metal3Cluster name: <cluster-name> namespace: <cluster-namespace>-
controlPlaneRef.kindでは、OpenshiftAssistedControlPlaneがコントロールプレーンです。 -
infrastructureRef.kindでは、Metal3Clusterがインフラストラクチャーです。
-
以下のコマンドを実行して 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: 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 }}"1 machineTemplate: infrastructureRef: apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 kind: Metal3MachineTemplate name: <cluster-name-control-plane> namespace: <cluster-namespace> replicas: 3-
.spec.openshiftAssistedConfigSpec.sshAuthorizedKeyは、ブート フェーズ (検出 フェーズとも呼ばれる) でノードにアクセスする場合に使用されます。 -
.spec.config.sshAuthorizedKeyは、プロビジョニングされた OpenShift Container Platform ノードにアクセスするために使用されます。
-
YAML ファイルを適用します。以下のコマンドを実行します。
oc apply -f <filename>.yaml- プルシークレットがない場合は、クラスターがコンテナーレジストリーからイメージをプルできるように、プルシークレットを作成する必要があります。プルシークレットを作成するには、次の手順を実行します。
イメージをプルするための YAML ファイルを作成します。
pull-secret.yamlという名前のファイルの次の例を参照してください。apiVersion: v1 kind: Secret metadata: name: pull-secret namespace: <cluster-namespace> data: .dockerconfigjson: <encoded_docker_configuration> type: kubernetes.io/dockerconfigjson-
<cluster-namespace>値がターゲットの namespace と一致していることを確認します。 -
<encoded_docker_configuration>の値として、base64 でエンコードされた設定ファイルを指定します。
-
次のコマンドを実行して、ファイルを適用します。
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.home port: 6443 noCloudProvider: true-
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: 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>-
spec.template.spec.imageは、distributionVersionの値と、OpenShift Container Platform Releases のバージョンに一致します。 -
<cluster-name>は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: name: <cluster-name-workers-2> apiVersion: infrastructure.cluster.x-k8s.io/v1alpha3 kind: Metal3MachineTemplate-
spec.bootstrap設定は、インストールに関する次のリソースでも参照されます。 -
infrastructureRef参照は、プロビジョニングするリソースを指します。
-
ファイルを適用します。以下のコマンドを実行します。
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}"' sshAuthorizedKey: "{{ ssh_authorized_key }}"-
kubeletExtraLabelsは、この値から変更できません。 -
sshAuthorizedKeyフィールドにキーを入力します。
-
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