13.10. 在带有 Local Zone 子网的现有 VPC 上安装集群
您可以在 Amazon Web Services (AWS) 上将集群安装到现有的 Amazon Virtual Private Cloud (VPC) 中。安装程序会置备所需基础架构的其余部分,您可以进一步自定义这些基础架构。要自定义安装,请在安装集群前修改 install-config.yaml 文件中的参数。
在 AWS 上安装集群到现有的 VPC 中,需要使用 AWS Local Zones 将 worker 扩展到 Cloud Infrastructure 边缘。
Local Zone 子网将常规 worker 节点扩展到边缘网络。每个边缘 worker 节点都运行一个用户工作负载。创建 Amazon Web Service (AWS) Local Zone 环境并部署了集群后,您可以使用边缘 worker 节点在 Local Zone 子网中创建用户工作负载。
您可以使用提供的 CloudFormation 模板来创建 VPC 和公共子网。另外,您可以修改模板来自定义模板,或使用其包含的信息根据公司的策略创建 AWS 对象。
如果要创建专用子网,您必须修改提供的 CloudFormation 模板或创建自己的模板。
13.10.1. 在 AWS 中创建 VPC 复制链接链接已复制到粘贴板!
您可以在 OpenShift Container Platform 集群的 Amazon Web Services (AWS) 中为每个 Local Zone 位置创建一个 Virtual Private Cloud (VPC) 和子网,以将 worker 节点扩展到边缘位置。您可以进一步自定义 VPC 以满足您的要求,包括 VPN、路由表和添加新的 Local Zone 子网,这些子网没有包括在初始部署中。
您可以使用提供的 CloudFormation 模板和自定义参数文件创建代表 VPC 的 AWS 资源堆栈。
如果不使用提供的 CloudFormation 模板来创建 AWS 基础架构,您必须检查提供的信息并手动创建基础架构。如果集群没有正确初始化,您可能需要联系红帽支持并提供您的安装日志。
先决条件
- 已配置了一个 AWS 帐户。
-
您可以通过运行
aws configure,将 AWS 密钥和区域添加到本地 AWS 配置集中。 - 您可以选择 AWS 帐户上的 AWS 区域区域。
流程
创建一个 JSON 文件,其包含模板所需的参数值:
[ { "ParameterKey": "VpcCidr",1 "ParameterValue": "10.0.0.0/16"2 }, { "ParameterKey": "AvailabilityZoneCount",3 "ParameterValue": "3"4 }, { "ParameterKey": "SubnetBits",5 "ParameterValue": "12"6 } ]- 复制本主题的 VPC 的 CloudFormation 模板部分中的模板,并将它以 YAML 文件形式保存到计算机上。此模板描述了集群所需的 VPC。
运行以下命令,启动 CloudFormation 模板以创建代表 VPC 的 AWS 资源堆栈:
重要您必须在一行内输入命令。
$ aws cloudformation create-stack --stack-name <name> \1 --template-body file://<template>.yaml \2 --parameters file://<parameters>.json3 输出示例
arn:aws:cloudformation:us-east-1:123456789012:stack/cluster-vpc/dbedae40-2fd3-11eb-820e-12a48460849f运行以下命令确认模板组件已存在:
$ aws cloudformation describe-stacks --stack-name <name>在
StackStatus显示CREATE_COMPLETE后,输出会显示以下参数的值。您必须将这些参数值提供给您在创建集群时要运行的其他 CloudFormation 模板:VpcId您的 VPC ID。
PublicSubnetIds新公共子网的 ID。
PrivateSubnetIds新专用子网的 ID。
PublicRouteTableId新公共路由表 ID 的 ID。
13.10.2. 在 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>.json3 输出示例
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。
13.10.3. VPC 的 CloudFormation 模板 复制链接链接已复制到粘贴板!
您可以使用以下 CloudFormation 模板来部署 OpenShift Container Platform 集群所需的 VPC。
例 13.2. VPC 的 CloudFormation 模板
AWSTemplateFormatVersion: 2010-09-09
Description: Template for Best Practice VPC with 1-3 AZs
Parameters:
VpcCidr:
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.0.0/16
Description: CIDR block for VPC.
Type: String
AvailabilityZoneCount:
ConstraintDescription: "The number of availability zones. (Min: 1, Max: 3)"
MinValue: 1
MaxValue: 3
Default: 1
Description: "How many AZs to create VPC subnets for. (Min: 1, Max: 3)"
Type: Number
SubnetBits:
ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/19-27.
MinValue: 5
MaxValue: 13
Default: 12
Description: "Size of each subnet to create within the availability zones. (Min: 5 = /27, Max: 13 = /19)"
Type: Number
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: "Network Configuration"
Parameters:
- VpcCidr
- SubnetBits
- Label:
default: "Availability Zones"
Parameters:
- AvailabilityZoneCount
ParameterLabels:
AvailabilityZoneCount:
default: "Availability Zone Count"
VpcCidr:
default: "VPC CIDR"
SubnetBits:
default: "Bits Per Subnet"
Conditions:
DoAz3: !Equals [3, !Ref AvailabilityZoneCount]
DoAz2: !Or [!Equals [2, !Ref AvailabilityZoneCount], Condition: DoAz3]
Resources:
VPC:
Type: "AWS::EC2::VPC"
Properties:
EnableDnsSupport: "true"
EnableDnsHostnames: "true"
CidrBlock: !Ref VpcCidr
PublicSubnet:
Type: "AWS::EC2::Subnet"
Properties:
VpcId: !Ref VPC
CidrBlock: !Select [0, !Cidr [!Ref VpcCidr, 6, !Ref SubnetBits]]
AvailabilityZone: !Select
- 0
- Fn::GetAZs: !Ref "AWS::Region"
PublicSubnet2:
Type: "AWS::EC2::Subnet"
Condition: DoAz2
Properties:
VpcId: !Ref VPC
CidrBlock: !Select [1, !Cidr [!Ref VpcCidr, 6, !Ref SubnetBits]]
AvailabilityZone: !Select
- 1
- Fn::GetAZs: !Ref "AWS::Region"
PublicSubnet3:
Type: "AWS::EC2::Subnet"
Condition: DoAz3
Properties:
VpcId: !Ref VPC
CidrBlock: !Select [2, !Cidr [!Ref VpcCidr, 6, !Ref SubnetBits]]
AvailabilityZone: !Select
- 2
- Fn::GetAZs: !Ref "AWS::Region"
InternetGateway:
Type: "AWS::EC2::InternetGateway"
GatewayToInternet:
Type: "AWS::EC2::VPCGatewayAttachment"
Properties:
VpcId: !Ref VPC
InternetGatewayId: !Ref InternetGateway
PublicRouteTable:
Type: "AWS::EC2::RouteTable"
Properties:
VpcId: !Ref VPC
PublicRoute:
Type: "AWS::EC2::Route"
DependsOn: GatewayToInternet
Properties:
RouteTableId: !Ref PublicRouteTable
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref InternetGateway
PublicSubnetRouteTableAssociation:
Type: "AWS::EC2::SubnetRouteTableAssociation"
Properties:
SubnetId: !Ref PublicSubnet
RouteTableId: !Ref PublicRouteTable
PublicSubnetRouteTableAssociation2:
Type: "AWS::EC2::SubnetRouteTableAssociation"
Condition: DoAz2
Properties:
SubnetId: !Ref PublicSubnet2
RouteTableId: !Ref PublicRouteTable
PublicSubnetRouteTableAssociation3:
Condition: DoAz3
Type: "AWS::EC2::SubnetRouteTableAssociation"
Properties:
SubnetId: !Ref PublicSubnet3
RouteTableId: !Ref PublicRouteTable
PrivateSubnet:
Type: "AWS::EC2::Subnet"
Properties:
VpcId: !Ref VPC
CidrBlock: !Select [3, !Cidr [!Ref VpcCidr, 6, !Ref SubnetBits]]
AvailabilityZone: !Select
- 0
- Fn::GetAZs: !Ref "AWS::Region"
PrivateRouteTable:
Type: "AWS::EC2::RouteTable"
Properties:
VpcId: !Ref VPC
PrivateSubnetRouteTableAssociation:
Type: "AWS::EC2::SubnetRouteTableAssociation"
Properties:
SubnetId: !Ref PrivateSubnet
RouteTableId: !Ref PrivateRouteTable
NAT:
DependsOn:
- GatewayToInternet
Type: "AWS::EC2::NatGateway"
Properties:
AllocationId:
"Fn::GetAtt":
- EIP
- AllocationId
SubnetId: !Ref PublicSubnet
EIP:
Type: "AWS::EC2::EIP"
Properties:
Domain: vpc
Route:
Type: "AWS::EC2::Route"
Properties:
RouteTableId:
Ref: PrivateRouteTable
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId:
Ref: NAT
PrivateSubnet2:
Type: "AWS::EC2::Subnet"
Condition: DoAz2
Properties:
VpcId: !Ref VPC
CidrBlock: !Select [4, !Cidr [!Ref VpcCidr, 6, !Ref SubnetBits]]
AvailabilityZone: !Select
- 1
- Fn::GetAZs: !Ref "AWS::Region"
PrivateRouteTable2:
Type: "AWS::EC2::RouteTable"
Condition: DoAz2
Properties:
VpcId: !Ref VPC
PrivateSubnetRouteTableAssociation2:
Type: "AWS::EC2::SubnetRouteTableAssociation"
Condition: DoAz2
Properties:
SubnetId: !Ref PrivateSubnet2
RouteTableId: !Ref PrivateRouteTable2
NAT2:
DependsOn:
- GatewayToInternet
Type: "AWS::EC2::NatGateway"
Condition: DoAz2
Properties:
AllocationId:
"Fn::GetAtt":
- EIP2
- AllocationId
SubnetId: !Ref PublicSubnet2
EIP2:
Type: "AWS::EC2::EIP"
Condition: DoAz2
Properties:
Domain: vpc
Route2:
Type: "AWS::EC2::Route"
Condition: DoAz2
Properties:
RouteTableId:
Ref: PrivateRouteTable2
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId:
Ref: NAT2
PrivateSubnet3:
Type: "AWS::EC2::Subnet"
Condition: DoAz3
Properties:
VpcId: !Ref VPC
CidrBlock: !Select [5, !Cidr [!Ref VpcCidr, 6, !Ref SubnetBits]]
AvailabilityZone: !Select
- 2
- Fn::GetAZs: !Ref "AWS::Region"
PrivateRouteTable3:
Type: "AWS::EC2::RouteTable"
Condition: DoAz3
Properties:
VpcId: !Ref VPC
PrivateSubnetRouteTableAssociation3:
Type: "AWS::EC2::SubnetRouteTableAssociation"
Condition: DoAz3
Properties:
SubnetId: !Ref PrivateSubnet3
RouteTableId: !Ref PrivateRouteTable3
NAT3:
DependsOn:
- GatewayToInternet
Type: "AWS::EC2::NatGateway"
Condition: DoAz3
Properties:
AllocationId:
"Fn::GetAtt":
- EIP3
- AllocationId
SubnetId: !Ref PublicSubnet3
EIP3:
Type: "AWS::EC2::EIP"
Condition: DoAz3
Properties:
Domain: vpc
Route3:
Type: "AWS::EC2::Route"
Condition: DoAz3
Properties:
RouteTableId:
Ref: PrivateRouteTable3
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId:
Ref: NAT3
S3Endpoint:
Type: AWS::EC2::VPCEndpoint
Properties:
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal: '*'
Action:
- '*'
Resource:
- '*'
RouteTableIds:
- !Ref PublicRouteTable
- !Ref PrivateRouteTable
- !If [DoAz2, !Ref PrivateRouteTable2, !Ref "AWS::NoValue"]
- !If [DoAz3, !Ref PrivateRouteTable3, !Ref "AWS::NoValue"]
ServiceName: !Join
- ''
- - com.amazonaws.
- !Ref 'AWS::Region'
- .s3
VpcId: !Ref VPC
Outputs:
VpcId:
Description: ID of the new VPC.
Value: !Ref VPC
PublicSubnetIds:
Description: Subnet IDs of the public subnets.
Value:
!Join [
",",
[!Ref PublicSubnet, !If [DoAz2, !Ref PublicSubnet2, !Ref "AWS::NoValue"], !If [DoAz3, !Ref PublicSubnet3, !Ref "AWS::NoValue"]]
]
PrivateSubnetIds:
Description: Subnet IDs of the private subnets.
Value:
!Join [
",",
[!Ref PrivateSubnet, !If [DoAz2, !Ref PrivateSubnet2, !Ref "AWS::NoValue"], !If [DoAz3, !Ref PrivateSubnet3, !Ref "AWS::NoValue"]]
]
PublicRouteTableId:
Description: Public Route table ID
Value: !Ref PublicRouteTable
13.10.4. AWS 安全组 复制链接链接已复制到粘贴板!
默认情况下,安装程序会创建安全组并将其附加到 control plane 和计算机器。不可修改与默认安全组关联的规则。
但是,您可以将与现有 VPC 关联的其他现有 AWS 安全组应用到 control plane 和计算机器。应用自定义安全组可帮助您满足机构的安全需求,在这种情况下,您需要控制这些机器的传入或传出流量。
作为安装过程的一部分,您可以在部署集群前通过修改 install-config.yaml 文件来应用自定义安全组。
如需更多信息,请参阅"边缘计算池和 AWS 本地区域"。
13.10.5. 使用 AWS 本地区域的子网的 CloudFormation 模板 复制链接链接已复制到粘贴板!
您可以使用以下 CloudFormation 模板来部署使用 AWS Local Zones 的 OpenShift Container Platform 集群所需的子网。
例 13.3. 子网的 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]]
13.10.6. 修改安装配置文件以使用 AWS 本地区域子网 复制链接链接已复制到粘贴板!
修改 install-config.yaml 文件,使其包含 AWS Local Zones 子网。
先决条件
- 您使用"在 AWS Local Zones 中创建子网"流程创建子网。
-
您使用"创建安装配置文件"流程创建了
install-config.yaml文件。
流程
通过在
platform.aws.subnets属性中指定 Local Zone 子网来修改install-config.yaml配置文件,如下例所示:... platform: aws: region: us-west-2 subnets:1 - publicSubnetId-1 - publicSubnetId-2 - publicSubnetId-3 - privateSubnetId-1 - privateSubnetId-2 - privateSubnetId-3 - publicSubnetId-LocalZone-1 ...- 1
- 在可用性和本地区域中创建的子网列表。