6.10.5.2. 在 GCP 中创建 VPC

您必须在 Google Cloud Platform (GCP) 中创建一个 VPC,供您的 OpenShift Container Platform 集群使用。您可以自定义 VPC 来满足您的要求。创建 VPC 的一种方法是修改提供的 Deployment Manager 模板。

注意

如果不使用提供的 Deployment Manager 模板来创建 GCP 基础架构,您必须检查提供的信息并手动创建基础架构。如果集群没有正确初始化,您可能需要联系红帽支持并提供您的安装日志。

先决条件

  • 配置 GCP 帐户。

流程

  1. 复制 VPC 的 Deployment Manager 模板一节中的模板,并将它以 01_vpc.py 形式保存到计算机上。此模板描述了集群所需的 VPC。
  2. 导出资源定义所需的以下变量:

    1. 导出 control plane CIDR:

      $ export MASTER_SUBNET_CIDR='10.0.0.0/19'
    2. 导出计算 CIDR:

      $ export WORKER_SUBNET_CIDR='10.0.32.0/19'
    3. 将部署 VPC 网络和集群的区域导出到:

      $ export REGION='<region>'
  3. 导出托管共享 VPC 的项目 ID 的变量:

    $ export HOST_PROJECT=<host_project>
  4. 导出属于主机项目的服务帐户电子邮件的变量:

    $ export HOST_PROJECT_ACCOUNT=<host_service_account_email>
  5. 创建 01_vpc.yaml 资源定义文件:

    $ cat <<EOF >01_vpc.yaml
    imports:
    - path: 01_vpc.py
    
    resources:
    - name: cluster-vpc
      type: 01_vpc.py
      properties:
        infra_id: '<prefix>' 1
        region: '${REGION}' 2
        master_subnet_cidr: '${MASTER_SUBNET_CIDR}' 3
        worker_subnet_cidr: '${WORKER_SUBNET_CIDR}' 4
    EOF
    1
    infra_id 是网络名称的前缀。
    2
    region 是集群要部署到的区域,如 us-central1
    3
    master_subnet_cidr 是 master 子网的 CIDR,如 10.0.0.0/19
    4
    worker_subnet_cidr 是 worker 子网的 CIDR,如 10.0.32.0/19
  6. 使用 gcloud CLI 创建部署:

    $ gcloud deployment-manager deployments create <vpc_deployment_name> --config 01_vpc.yaml --project ${HOST_PROJECT} --account ${HOST_PROJECT_ACCOUNT} 1
    1
    对于 <vpc_deployment_name>,请指定要部署的 VPC 名称。
  7. 导出其他组件需要的 VPC 变量:

    1. 导出主机项目网络的名称:

      $ export HOST_PROJECT_NETWORK=<vpc_network>
    2. 导出主机项目 control plane 子网的名称:

      $ export HOST_PROJECT_CONTROL_SUBNET=<control_plane_subnet>
    3. 导出主机项目计算子网的名称:

      $ export HOST_PROJECT_COMPUTE_SUBNET=<compute_subnet>
  8. 设置共享 VPC。请参阅 GCP 文档中的 设置共享 VPC
6.10.5.2.1. VPC 的 Deployment Manager 模板

您可以使用以下 Deployment Manager 模板来部署 OpenShift Container Platform 集群所需的 VPC:

例 6.10. 01_VPC.py Deployment Manager 模板

def GenerateConfig(context):

    resources = [{
        'name': context.properties['infra_id'] + '-network',
        'type': 'compute.v1.network',
        'properties': {
            'region': context.properties['region'],
            'autoCreateSubnetworks': False
        }
    }, {
        'name': context.properties['infra_id'] + '-master-subnet',
        'type': 'compute.v1.subnetwork',
        'properties': {
            'region': context.properties['region'],
            'network': '$(ref.' + context.properties['infra_id'] + '-network.selfLink)',
            'ipCidrRange': context.properties['master_subnet_cidr']
        }
    }, {
        'name': context.properties['infra_id'] + '-worker-subnet',
        'type': 'compute.v1.subnetwork',
        'properties': {
            'region': context.properties['region'],
            'network': '$(ref.' + context.properties['infra_id'] + '-network.selfLink)',
            'ipCidrRange': context.properties['worker_subnet_cidr']
        }
    }, {
        'name': context.properties['infra_id'] + '-router',
        'type': 'compute.v1.router',
        'properties': {
            'region': context.properties['region'],
            'network': '$(ref.' + context.properties['infra_id'] + '-network.selfLink)',
            'nats': [{
                'name': context.properties['infra_id'] + '-nat-master',
                'natIpAllocateOption': 'AUTO_ONLY',
                'minPortsPerVm': 7168,
                'sourceSubnetworkIpRangesToNat': 'LIST_OF_SUBNETWORKS',
                'subnetworks': [{
                    'name': '$(ref.' + context.properties['infra_id'] + '-master-subnet.selfLink)',
                    'sourceIpRangesToNat': ['ALL_IP_RANGES']
                }]
            }, {
                'name': context.properties['infra_id'] + '-nat-worker',
                'natIpAllocateOption': 'AUTO_ONLY',
                'minPortsPerVm': 512,
                'sourceSubnetworkIpRangesToNat': 'LIST_OF_SUBNETWORKS',
                'subnetworks': [{
                    'name': '$(ref.' + context.properties['infra_id'] + '-worker-subnet.selfLink)',
                    'sourceIpRangesToNat': ['ALL_IP_RANGES']
                }]
            }]
        }
    }]

    return {'resources': resources}