10.18. GCP での追加のワーカーマシンの作成
Google Cloud Platform (GCP) でクラスターが使用するワーカーマシンを作成するには、それぞれのインスタンスを個別に起動するか、自動スケーリンググループなどのクラスター外にある自動プロセスを実行します。OpenShift Container Platform の組み込まれたクラスタースケーリングメカニズムやマシン API を利用できます。
3 ノードクラスターをインストールする場合は、この手順をスキップしてください。3 ノードクラスターは、コンピュートマシンとしても機能する 3 つのコントロールプレーンマシンで構成されます。
この例では、Deployment Manager テンプレートを使用して 1 つのインスタンスを手動で起動します。追加のインスタンスは、ファイル内に 06_worker.py
というタイプのリソースを追加して起動することができます。
ワーカーマシンを使用するために提供される Deployment Manager テンプレートを使用しない場合は、提供される情報を確認し、インフラストラクチャーを手動で作成する必要があります。クラスターが適切に初期化されない場合、インストールログを用意して Red Hat サポートに問い合わせする必要がある可能性があります。
前提条件
- 共通変数のエクスポート、GCP でのロードバランサーの作成、および GCP でのブートストラップマシンの作成 セクションで変数が定義されている。
- ブートストラップマシンが作成されている。
- コントロールプレーンマシンが作成されている。
手順
-
このトピックの ワーカーマシンの Deployment Manager テンプレート からテンプレートをコピーし、これを
06_worker.py
としてコンピューターに保存します。このテンプレートは、クラスターに必要なワーカーマシンを記述しています。 リソース定義が使用する変数をエクスポートします。
コンピュートマシンをホストするサブネットをエクスポートします。
Copy to Clipboard Copied! Toggle word wrap Toggle overflow export COMPUTE_SUBNET=(`gcloud compute networks subnets describe ${INFRA_ID}-worker-subnet --region=${REGION} --format json | jq -r .selfLink`)
$ export COMPUTE_SUBNET=(`gcloud compute networks subnets describe ${INFRA_ID}-worker-subnet --region=${REGION} --format json | jq -r .selfLink`)
サービスアカウントのメールアドレスをエクスポートします。
Copy to Clipboard Copied! Toggle word wrap Toggle overflow export WORKER_SERVICE_ACCOUNT=(`gcloud iam service-accounts list --filter "email~^${INFRA_ID}-w@${PROJECT_NAME}." --format json | jq -r '.[0].email'`)
$ export WORKER_SERVICE_ACCOUNT=(`gcloud iam service-accounts list --filter "email~^${INFRA_ID}-w@${PROJECT_NAME}." --format json | jq -r '.[0].email'`)
コンピュートマシンの Ignition 設定ファイルの場所をエクスポートします。
Copy to Clipboard Copied! Toggle word wrap Toggle overflow export WORKER_IGNITION=`cat <installation_directory>/worker.ign`
$ export WORKER_IGNITION=`cat <installation_directory>/worker.ign`
06_worker.yaml
リソース定義ファイルを作成します。Copy to Clipboard Copied! Toggle word wrap Toggle overflow cat <<EOF >06_worker.yaml imports: - path: 06_worker.py resources: - name: 'worker-0' type: 06_worker.py properties: infra_id: '${INFRA_ID}' zone: '${ZONE_0}' compute_subnet: '${COMPUTE_SUBNET}' image: '${CLUSTER_IMAGE}' machine_type: 'n1-standard-4' root_volume_size: '128' service_account_email: '${WORKER_SERVICE_ACCOUNT}' ignition: '${WORKER_IGNITION}' - name: 'worker-1' type: 06_worker.py properties: infra_id: '${INFRA_ID}' zone: '${ZONE_1}' compute_subnet: '${COMPUTE_SUBNET}' image: '${CLUSTER_IMAGE}' machine_type: 'n1-standard-4' root_volume_size: '128' service_account_email: '${WORKER_SERVICE_ACCOUNT}' ignition: '${WORKER_IGNITION}' EOF
$ 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
はコンピュートサブネットのselfLink
URL です。- 5 12
image
は RHCOS イメージのselfLink
URL です。1- 6 13
machine_type
はインスタンスのマシンタイプです (例:n1-standard-4
)。- 7 14
service_account_email
は作成したワーカーサービスアカウントのメールアドレスです。- 8 15
Ignition
はworker.ign
ファイルの内容です。
-
オプション: 追加のインスタンスを起動する必要がある場合には、
06_worker.py
タイプの追加のリソースを06_worker.yaml
リソース定義ファイルに組み込みます。 gcloud
CLI を使用してデプロイメントを作成します。Copy to Clipboard Copied! Toggle word wrap Toggle overflow gcloud deployment-manager deployments create ${INFRA_ID}-worker --config 06_worker.yaml
$ gcloud deployment-manager deployments create ${INFRA_ID}-worker --config 06_worker.yaml
GCP Marketplace イメージを使用するには、使用するオファーを指定します。
-
OpenShift Container Platform:
https://www.googleapis.com/compute/v1/projects/redhat-marketplace-public/global/images/redhat-coreos-ocp-413-x86-64-202305021736
-
OpenShift Platform Plus:
https://www.googleapis.com/compute/v1/projects/redhat-marketplace-public/global/images/redhat-coreos-opp-413-x86-64-202305021736
-
OpenShift Kubernetes Engine:
https://www.googleapis.com/compute/v1/projects/redhat-marketplace-public/global/images/redhat-coreos-oke-413-x86-64-202305021736
-
OpenShift Container Platform:
10.18.1. ワーカーマシンの Deployment Manager テンプレート
以下の Deployment Manager テンプレートを使用し、OpenShift Container Platform クラスターに必要なワーカーマシンをデプロイすることができます。
例10.34 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}
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}