14.7. 在 AWS 本地区中创建子网
在为 OpenShift Container Platform 集群配置 worker machineset 之前,您必须在 AWS Local Zones 中创建子网。
您必须为每个要部署 worker 节点的 Local Zone 重复以下流程。
您可以使用提供的 CloudFormation 模板和自定义参数文件来创建代表子网的 AWS 资源堆栈。
如果不使用提供的 CloudFormation 模板来创建 AWS 基础架构,您必须检查提供的信息并手动创建基础架构。如果集群没有正确初始化,您可能需要联系红帽支持并提供您的安装日志。
先决条件
- 已配置了一个 AWS 帐户。
-
您可以通过运行
aws configure
,将 AWS 密钥和区域添加到本地 AWS 配置集中。 - 您已选择 Local Zone 组。
流程
创建一个 JSON 文件,其包含模板所需的参数值:
[ { "ParameterKey": "VpcId", "ParameterValue": "<value_of_VpcId>" 1 }, { "ParameterKey": "PublicRouteTableId", "ParameterValue": "<value_of_PublicRouteTableId>" 2 }, { "ParameterKey": "ZoneName", "ParameterValue": "<value_of_ZoneName>" 3 }, { "ParameterKey": "SubnetName", "ParameterValue": "<value_of_SubnetName>" }, { "ParameterKey": "PublicSubnetCidr", "ParameterValue": "10.0.192.0/20" 4 } ]
- 复制本主题的子网的 CloudFormation 模板部分中的模板,并将它以 YAML 文件形式保存到计算机上。此模板描述了集群所需的 VPC。
运行以下命令,启动 CloudFormation 模板以创建代表 VPC 的 AWS 资源堆栈:
重要您必须在一行内输入命令。
$ aws cloudformation create-stack --stack-name <subnet_stack_name> \ 1 --template-body file://<template>.yaml \ 2 --parameters file://<parameters>.json 3
输出示例
arn:aws:cloudformation:us-east-1:123456789012:stack/<subnet_stack_name>/dbedae40-2fd3-11eb-820e-12a48460849f
运行以下命令确认模板组件已存在:
$ aws cloudformation describe-stacks --stack-name <subnet_stack_name>
在
StackStatus
显示CREATE_COMPLETE
后,输出会显示以下参数的值。您必须将这些参数值提供给您在创建集群时要运行的其他 CloudFormation 模板:PublicSubnetIds
新公共子网的 ID。
14.7.1. 使用 AWS 本地区域的子网的 CloudFormation 模板
您可以使用以下 CloudFormation 模板来部署使用 AWS Local Zones 的 OpenShift Container Platform 集群所需的子网。
例 14.2. 子网的 CloudFormation 模板
# CloudFormation template used to create Local Zone subnets and dependencies AWSTemplateFormatVersion: 2010-09-09 Description: Template for create Public Local Zone subnets Parameters: VpcId: Description: VPC Id Type: String ZoneName: Description: Local Zone Name (Example us-east-1-nyc-1a) Type: String SubnetName: Description: Local Zone Name (Example cluster-public-us-east-1-nyc-1a) Type: String PublicRouteTableId: Description: Public Route Table ID to associate the Local Zone subnet Type: String PublicSubnetCidr: AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(1[6-9]|2[0-4]))$ ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-24. Default: 10.0.128.0/20 Description: CIDR block for Public Subnet Type: String Resources: PublicSubnet: Type: "AWS::EC2::Subnet" Properties: VpcId: !Ref VpcId CidrBlock: !Ref PublicSubnetCidr AvailabilityZone: !Ref ZoneName Tags: - Key: Name Value: !Ref SubnetName - Key: kubernetes.io/cluster/unmanaged Value: "true" PublicSubnetRouteTableAssociation: Type: "AWS::EC2::SubnetRouteTableAssociation" Properties: SubnetId: !Ref PublicSubnet RouteTableId: !Ref PublicRouteTableId Outputs: PublicSubnetIds: Description: Subnet IDs of the public subnets. Value: !Join ["", [!Ref PublicSubnet]]
其他资源
- 您可以通过导航 AWS CloudFormation 控制台来查看您创建的 CloudFormation 堆栈的详情。