This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.4.11.14. 在 GCP 中创建 bootstrap 机器
您必须在 Google Cloud Platform (GCP) 中创建 bootstrap 机器,以便在 OpenShift Container Platform 集群初始化过程中使用。创建此机器的一种方法是修改提供的 Deployment Manager 模板。
如果不使用提供的 Deployment Manager 模板来创建 bootstrap 机器,您必须检查提供的信息并手动创建基础架构。如果集群没有正确初始化,您可能需要联系红帽支持并提供您的安装日志。
先决条件
- 配置 GCP 帐户。
- 为集群生成 Ignition 配置文件。
- 在 GCP 中创建和配置 VPC 及相关子网。
- 在 GCP 中创建和配置联网及负载均衡器。
- 创建 control plane 和计算角色。
- 确定安装了 pyOpenSSL。
流程
-
复制 bootstrap 机器的 Deployment Manager 模板一节中的模板,并将它以
04_bootstrap.py
形式保存到计算机上。此模板描述了集群所需的 bootstrap 机器。 导出安装程序所需的 Red Hat Enterprise Linux CoreOS(RHCOS)镜像的位置:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow export CLUSTER_IMAGE=(`gcloud compute images describe ${INFRA_ID}-rhcos-image --format json | jq -r .selfLink`)
$ export CLUSTER_IMAGE=(`gcloud compute images describe ${INFRA_ID}-rhcos-image --format json | jq -r .selfLink`)
创建存储桶并上传
bootstrap.ign
文件:Copy to Clipboard Copied! Toggle word wrap Toggle overflow gsutil mb gs://${INFRA_ID}-bootstrap-ignition gsutil cp <installation_directory>/bootstrap.ign gs://${INFRA_ID}-bootstrap-ignition/
$ gsutil mb gs://${INFRA_ID}-bootstrap-ignition $ gsutil cp <installation_directory>/bootstrap.ign gs://${INFRA_ID}-bootstrap-ignition/
为 bootstrap 实例创建一个签名的 URL,用于访问 Ignition 配置。将输出中的 URL 导出为变量:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow export BOOTSTRAP_IGN=`gsutil signurl -d 1h service-account-key.json gs://${INFRA_ID}-bootstrap-ignition/bootstrap.ign | grep "^gs:" | awk '{print $5}'`
$ export BOOTSTRAP_IGN=`gsutil signurl -d 1h service-account-key.json gs://${INFRA_ID}-bootstrap-ignition/bootstrap.ign | grep "^gs:" | awk '{print $5}'`
创建
04_bootstrap.yaml
资源定义文件:Copy to Clipboard Copied! Toggle word wrap Toggle overflow cat <<EOF >04_bootstrap.yaml imports: - path: 04_bootstrap.py resources: - name: cluster-bootstrap type: 04_bootstrap.py properties: infra_id: '${INFRA_ID}' region: '${REGION}' zone: '${ZONE_0}' cluster_network: '${CLUSTER_NETWORK}' control_subnet: '${CONTROL_SUBNET}' image: '${CLUSTER_IMAGE}' machine_type: 'n1-standard-4' root_volume_size: '128' bootstrap_ign: '${BOOTSTRAP_IGN}' EOF
$ cat <<EOF >04_bootstrap.yaml imports: - path: 04_bootstrap.py resources: - name: cluster-bootstrap type: 04_bootstrap.py properties: infra_id: '${INFRA_ID}'
1 region: '${REGION}'
2 zone: '${ZONE_0}'
3 cluster_network: '${CLUSTER_NETWORK}'
4 control_subnet: '${CONTROL_SUBNET}'
5 image: '${CLUSTER_IMAGE}'
6 machine_type: 'n1-standard-4'
7 root_volume_size: '128'
8 bootstrap_ign: '${BOOTSTRAP_IGN}'
9 EOF
- 1
infra_id
是来自于提取步骤的INFRA_ID
基础架构名称。- 2
region
是集群要部署到的区域,如us-central1
。- 3
zone
是 Bootstrap 实例要部署到的区域,如us-central1-b
。- 4
cluster_network
是集群网络的selfLink
URL。- 5
control_subnet
是控制子网的selfLink
URL。- 6
image
是 RHCOS 镜像的selfLink
URL。- 7
machine_type
是实例的机器类型,如n1-standard-4
。- 8
root_volume_size
是 bootstrap 机器的引导磁盘大小。- 9
bootstrap_ign
是创建签名 URL 时的 URL 输出。
使用
gcloud
CLI 创建部署:Copy to Clipboard Copied! Toggle word wrap Toggle overflow gcloud deployment-manager deployments create ${INFRA_ID}-bootstrap --config 04_bootstrap.yaml
$ gcloud deployment-manager deployments create ${INFRA_ID}-bootstrap --config 04_bootstrap.yaml
由于 Deployment Manager 的限制,模板无法管理负载均衡器成员资格,因此您必须手动添加 bootstrap 机器:
将 bootstrap 实例添加到内部负载均衡器实例组中:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow gcloud compute instance-groups unmanaged add-instances \ ${INFRA_ID}-bootstrap-instance-group --zone=${ZONE_0} --instances=${INFRA_ID}-bootstrap
$ gcloud compute instance-groups unmanaged add-instances \ ${INFRA_ID}-bootstrap-instance-group --zone=${ZONE_0} --instances=${INFRA_ID}-bootstrap
将 bootstrap 实例组添加到内部负载均衡器后端服务中:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow gcloud compute backend-services add-backend \ ${INFRA_ID}-api-internal-backend-service --region=${REGION} --instance-group=${INFRA_ID}-bootstrap-instance-group --instance-group-zone=${ZONE_0}
$ gcloud compute backend-services add-backend \ ${INFRA_ID}-api-internal-backend-service --region=${REGION} --instance-group=${INFRA_ID}-bootstrap-instance-group --instance-group-zone=${ZONE_0}
4.11.14.1. bootstrap 机器的 Deployment Manager 模板
您可以使用以下 Deployment Manager 模板来部署 OpenShift Container Platform 集群所需的 bootstrap 机器:
例 4.25. 04_bootstrap.py
Deployment Manager 模板
def GenerateConfig(context): resources = [{ 'name': context.properties['infra_id'] + '-bootstrap-public-ip', 'type': 'compute.v1.address', 'properties': { 'region': context.properties['region'] } }, { 'name': context.properties['infra_id'] + '-bootstrap', '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': '{"ignition":{"config":{"replace":{"source":"' + context.properties['bootstrap_ign'] + '"}},"version":"3.1.0"}}', }] }, 'networkInterfaces': [{ 'subnetwork': context.properties['control_subnet'], 'accessConfigs': [{ 'natIP': '$(ref.' + context.properties['infra_id'] + '-bootstrap-public-ip.address)' }] }], 'tags': { 'items': [ context.properties['infra_id'] + '-master', context.properties['infra_id'] + '-bootstrap' ] }, 'zone': context.properties['zone'] } }, { 'name': context.properties['infra_id'] + '-bootstrap-instance-group', 'type': 'compute.v1.instanceGroup', 'properties': { 'namedPorts': [ { 'name': 'ignition', 'port': 22623 }, { 'name': 'https', 'port': 6443 } ], 'network': context.properties['cluster_network'], 'zone': context.properties['zone'] } }] return {'resources': resources}
def GenerateConfig(context):
resources = [{
'name': context.properties['infra_id'] + '-bootstrap-public-ip',
'type': 'compute.v1.address',
'properties': {
'region': context.properties['region']
}
}, {
'name': context.properties['infra_id'] + '-bootstrap',
'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': '{"ignition":{"config":{"replace":{"source":"' + context.properties['bootstrap_ign'] + '"}},"version":"3.1.0"}}',
}]
},
'networkInterfaces': [{
'subnetwork': context.properties['control_subnet'],
'accessConfigs': [{
'natIP': '$(ref.' + context.properties['infra_id'] + '-bootstrap-public-ip.address)'
}]
}],
'tags': {
'items': [
context.properties['infra_id'] + '-master',
context.properties['infra_id'] + '-bootstrap'
]
},
'zone': context.properties['zone']
}
}, {
'name': context.properties['infra_id'] + '-bootstrap-instance-group',
'type': 'compute.v1.instanceGroup',
'properties': {
'namedPorts': [
{
'name': 'ignition',
'port': 22623
}, {
'name': 'https',
'port': 6443
}
],
'network': context.properties['cluster_network'],
'zone': context.properties['zone']
}
}]
return {'resources': resources}