11.18. Google Cloud での追加のワーカーマシンの作成
Google Cloud でクラスターが使用するワーカーマシンを作成するには、それぞれのインスタンスを個別に起動するか、自動スケーリンググループなどのクラスター外にある自動プロセスを実行します。OpenShift Container Platform の組み込まれたクラスタースケーリングメカニズムやマシン API を利用できます。
この例では、Deployment Manager テンプレートを使用して 1 つのインスタンスを手動で起動します。追加のインスタンスは、ファイル内に 06_worker.py というタイプのリソースを追加して起動することができます。
ワーカーマシンを使用するために提供される Deployment Manager テンプレートを使用しない場合は、提供される情報を確認し、インフラストラクチャーを手動で作成する必要があります。クラスターが適切に初期化されない場合、インストールログを用意して Red Hat サポートに問い合わせする必要がある可能性があります。
前提条件
- Google Cloud アカウントを設定する。
- クラスターの Ignition 設定ファイルを生成します。
- Google Cloud で VPC および関連するサブネットを作成し、設定します。
- Google Cloud でネットワークおよびロードバランサーを作成および設定します。
- コントロールプレーンおよびコンピュートロールを作成します。
- ブートストラップマシンを作成します。
- コントロールプレーンマシンが作成されている。
手順
-
このトピックの ワーカーマシンの Deployment Manager テンプレート からテンプレートをコピーし、これを
06_worker.pyとしてコンピューターに保存します。このテンプレートは、クラスターに必要なワーカーマシンを記述しています。 リソース定義が使用する変数をエクスポートします。
コンピュートマシンをホストするサブネットをエクスポートします。
$ export COMPUTE_SUBNET=(`gcloud compute networks subnets describe ${INFRA_ID}-worker-subnet --region=${REGION} --format json | jq -r .selfLink`)サービスアカウントのメールアドレスをエクスポートします。
$ export WORKER_SERVICE_ACCOUNT=(`gcloud iam service-accounts list --filter "email~^${INFRA_ID}-w@${PROJECT_NAME}." --format json | jq -r '.[0].email'`)コンピュートマシンの Ignition 設定ファイルの場所をエクスポートします。
$ export WORKER_IGNITION=`cat <installation_directory>/worker.ign`
06_worker.yamlリソース定義ファイルを作成します。$ cat <<EOF >06_worker.yaml imports: - path: 06_worker.py resources: - name: 'worker-0'1 type: 06_worker.py properties: infra_id: '${INFRA_ID}'2 zone: '${ZONE_0}'3 compute_subnet: '${COMPUTE_SUBNET}'4 image: '${CLUSTER_IMAGE}'5 machine_type: 'n1-standard-4'6 root_volume_size: '128' service_account_email: '${WORKER_SERVICE_ACCOUNT}'7 ignition: '${WORKER_IGNITION}'8 - name: 'worker-1' type: 06_worker.py properties: infra_id: '${INFRA_ID}'9 zone: '${ZONE_1}'10 compute_subnet: '${COMPUTE_SUBNET}'11 image: '${CLUSTER_IMAGE}'12 machine_type: 'n1-standard-4'13 root_volume_size: '128' service_account_email: '${WORKER_SERVICE_ACCOUNT}'14 ignition: '${WORKER_IGNITION}'15 EOF- 1
nameはワーカーマシンの名前です (例:worker-0)。- 2 9
infra_idは抽出手順で得られるINFRA_IDインフラストラクチャー名です。- 3 10
zoneはワーカーマシンをデプロイするゾーンです (例:us-central1-a)。- 4 11
compute_subnetはコンピュートサブネットのselfLinkURL です。- 5 12
imageは RHCOS イメージのselfLinkURL です。1- 6 13
machine_typeはインスタンスのマシンタイプです (例:n1-standard-4)。- 7 14
service_account_emailは作成したワーカーサービスアカウントのメールアドレスです。- 8 15
ignitionはworker.ignファイルの内容です。
-
オプション: 追加のインスタンスを起動する必要がある場合には、
06_worker.pyタイプの追加のリソースを06_worker.yamlリソース定義ファイルに組み込みます。 gcloudCLI を使用してデプロイメントを作成します。$ gcloud deployment-manager deployments create ${INFRA_ID}-worker --config 06_worker.yaml
Google Cloud Marketplace イメージを使用するには、使用するオファーを指定します。
-
OpenShift Container Platform:
https://www.googleapis.com/compute/v1/projects/redhat-marketplace-public/global/images/redhat-coreos-ocp-48-x86-64-202210040145 -
OpenShift Platform Plus:
https://www.googleapis.com/compute/v1/projects/redhat-marketplace-public/global/images/redhat-coreos-opp-48-x86-64-202206140145 -
OpenShift Kubernetes Engine:
https://www.googleapis.com/compute/v1/projects/redhat-marketplace-public/global/images/redhat-coreos-oke-48-x86-64-202206140145
-
OpenShift Container Platform:
11.18.1. ワーカーマシンの Deployment Manager テンプレート リンクのコピーリンクがクリップボードにコピーされました!
以下の Deployment Manager テンプレートを使用し、OpenShift Container Platform クラスターに必要なワーカーマシンをデプロイすることができます。
例11.32 06_worker.py Deployment Manager テンプレート
def GenerateConfig(context):
resources = [{
'name': context.properties['infra_id'] + '-' + context.env['name'],
'type': 'compute.v1.instance',
'properties': {
'disks': [{
'autoDelete': True,
'boot': True,
'initializeParams': {
'diskSizeGb': context.properties['root_volume_size'],
'sourceImage': context.properties['image']
}
}],
'machineType': 'zones/' + context.properties['zone'] + '/machineTypes/' + context.properties['machine_type'],
'metadata': {
'items': [{
'key': 'user-data',
'value': context.properties['ignition']
}]
},
'networkInterfaces': [{
'subnetwork': context.properties['compute_subnet']
}],
'serviceAccounts': [{
'email': context.properties['service_account_email'],
'scopes': ['https://www.googleapis.com/auth/cloud-platform']
}],
'tags': {
'items': [
context.properties['infra_id'] + '-worker',
]
},
'zone': context.properties['zone']
}
}]
return {'resources': resources}