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": "ClusterName",1 "ParameterValue": "mycluster"2 }, { "ParameterKey": "VpcId",3 "ParameterValue": "vpc-<random_string>"4 }, { "ParameterKey": "PublicRouteTableId",5 "ParameterValue": "<vpc_rtb_pub>"6 }, { "ParameterKey": "LocalZoneName",7 "ParameterValue": "<cluster_region_name>-<location_identifier>-<zone_identifier>"8 }, { "ParameterKey": "LocalZoneNameShort",9 "ParameterValue": "<lz_zone_shortname>"10 }, { "ParameterKey": "PublicSubnetCidr",11 "ParameterValue": "10.0.128.0/20"12 } ]- 1
- 一个简短的、代表集群的名称用于主机名等。
- 2
- 指定您为集群生成
install-config.yaml文件时所用的集群名称。 - 3
- 创建 Local Zone 子网的 VPC ID。
- 4
- 指定 VPC 的 CloudFormation 模板输出的
VpcId值。 - 5
- VPC 的公共路由表 ID。
- 6
- 指定 VPC 的 CloudFormation 模板输出的
PublicRouteTableId值。 - 7
- VPC 所属的 Local Zone 名称。
- 8
- 指定您选择的 AWS 帐户的 Local Zone,如
us-east-1-nyc-1a。 - 9
- VPC 所属的 AWS Local Zone 的短名称。
- 10
- 为您选择 AWS 帐户的 AWS Local Zone 指定短名称,如
<zone_group_identified><zone_identifier>。例如,us-east-1-nyc-1a被缩短为nyc-1a。 - 11
- 允许访问本地区域的 CIDR 块。
- 12
- 以
x.x.x.x/16-24格式指定 CIDR 块。
- 复制本主题的子网的 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>.json3 输出示例
arn:aws:cloudformation:us-east-1:123456789012:stack/cluster-lz-nyc1/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 Best Practice VPC with 1-3 AZs
Parameters:
ClusterName:
Description: ClusterName used to prefix resource names
Type: String
VpcId:
Description: VPC Id
Type: String
LocalZoneName:
Description: Local Zone Name (Example us-east-1-bos-1)
Type: String
LocalZoneNameShort:
Description: Short name for Local Zone used on tag Name (Example bos1)
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 LocalZoneName
Tags:
- Key: Name
Value: !Join
- ""
- [ !Ref ClusterName, "-public-", !Ref LocalZoneNameShort, "-1" ]
- 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]
]