14.16. 在 AWS 中创建 worker 节点
您可以在 Amazon Web Services (AWS) 中创建 worker 节点,供集群使用。
您可以使用提供的 CloudFormation 模板和自定义参数文件创建代表 worker 节点的 AWS 资源堆栈。
CloudFormation 模板会创建一个堆栈,它代表一个 worker 节点。您必须为每个 worker 节点创建一个堆栈。
如果不使用提供的 CloudFormation 模板来创建 worker 节点,您必须检查提供的信息并手动创建基础架构。如果集群没有正确初始化,您可能需要联系红帽支持并提供您的安装日志。
先决条件
- 已配置了一个 AWS 帐户。
-
您可以通过运行
aws configure,将 AWS 密钥和区域添加到本地 AWS 配置集中。 - 已为集群生成 Ignition 配置文件。
- 您在 AWS 中创建并配置了 VPC 及相关子网。
- 您在 AWS 中创建并配置了 DNS、负载均衡器和监听程序。
- 您在 AWS 中创建了集群所需的安全组和角色。
- 已创建 bootstrap 机器。
- 已创建 control plane 机器。
流程
创建一个 JSON 文件,其包含 CloudFormation 模板需要的参数值:
[ { "ParameterKey": "InfrastructureName",1 "ParameterValue": "mycluster-<random_string>"2 }, { "ParameterKey": "RhcosAmi",3 "ParameterValue": "ami-<random_string>"4 }, { "ParameterKey": "Subnet",5 "ParameterValue": "subnet-<random_string>"6 }, { "ParameterKey": "WorkerSecurityGroupId",7 "ParameterValue": "sg-<random_string>"8 }, { "ParameterKey": "IgnitionLocation",9 "ParameterValue": "https://api-int.<cluster_name>.<domain_name>:22623/config/worker"10 }, { "ParameterKey": "CertificateAuthorities",11 "ParameterValue": ""12 }, { "ParameterKey": "WorkerInstanceProfileName",13 "ParameterValue": ""14 }, { "ParameterKey": "WorkerInstanceType",15 "ParameterValue": ""16 } ]- 1
- 您的 Ignition 配置文件中为集群编码的集群基础架构名称。
- 2
- 指定从 Ignition 配置文件元数据中提取的基础架构名称,其格式为
<cluster-name>-<random-string>。 - 3
- 根据您选择的架构,当前 Red Hat Enterprise Linux CoreOS (RHCOS) AMI 用于 worker 节点。
- 4
- 指定
AWS::EC2::Image::Id值。 - 5
- 在其中启动 worker 节点的子网,最好是专用子网。
- 6
- 从 DNS 和负载均衡的 CloudFormation 模板输出的
PrivateSubnets值指定子网。 - 7
- 与 worker 节点关联的 worker 安全组 ID。
- 8
- 指定安全组和角色的 CloudFormation 模板输出的
WorkerSecurityGroupId值。 - 9
- 从中获取 bootstrap Ignition 配置文件的位置。
- 10
- 指定生成的 Ignition 配置的位置,
https://api-int.<cluster_name>.<domain_name>:22623/config/worker。 - 11
- 要使用的 Base64 编码证书颁发机构字符串。
- 12
- 指定安装目录下
worker.ign文件中的值。这个值是一个长字符串,格式为data:text/plain;charset=utf-8;base64,ABC…xYz==。 - 13
- 与 worker 节点关联的 IAM 配置集。
- 14
- 指定安全组和角色的 CloudFormation 模板输出的
WorkerInstanceProfile参数值。 - 15
- 根据您选择的架构,用于计算机器的 AWS 实例类型。
- 16
- 实例类型值对应于计算机器的最低资源要求。例如,
m6i.large是 AMD64 的类型,m6g.large是 ARM64 的类型。
- 复制 worker 机器的 CloudFormation 模板一节中的模板,并将它以 YAML 文件形式保存到计算机上。此模板描述了集群所需的网络对象和负载均衡器。
-
可选:如果将
m5实例类型指定为WorkerInstanceType的值,请将该实例类型添加到 CloudFormation 模板中的WorkerInstanceType.AllowedValues参数。 -
可选:如果您使用 AWS Marketplace 镜像部署,请使用从订阅获取的 AMI ID 更新
Worker0.type.properties.ImageID参数。 使用 CloudFormation 模板创建代表 worker 节点的 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:269333783861:stack/cluster-worker-1/729ee301-1c2a-11eb-348f-sd9888c65b59注意CloudFormation 模板会创建一个堆栈,它代表一个 worker 节点。
确认模板组件已存在:
$ aws cloudformation describe-stacks --stack-name <name>继续创建 worker 堆栈,直到为集群创建了充足的 worker 机器。您可以通过引用同一模板和参数文件并指定不同的堆栈名称来创建额外的 worker 堆栈。
重要您必须至少创建两台 worker 机器,因此您必须创建至少两个使用此 CloudFormation 模板的堆栈。
14.16.1. worker 机器的 CloudFormation 模板 复制链接链接已复制到粘贴板!
您可以使用以下 CloudFormation 模板来部署 OpenShift Container Platform 集群所需的 worker 机器。
例 14.22. worker 机器的 CloudFormation 模板
AWSTemplateFormatVersion: 2010-09-09
Description: Template for OpenShift Cluster Node Launch (EC2 worker instance)
Parameters:
InfrastructureName:
AllowedPattern: ^([a-zA-Z][a-zA-Z0-9\-]{0,26})$
MaxLength: 27
MinLength: 1
ConstraintDescription: Infrastructure name must be alphanumeric, start with a letter, and have a maximum of 27 characters.
Description: A short, unique cluster ID used to tag nodes for the kubelet cloud provider.
Type: String
RhcosAmi:
Description: Current Red Hat Enterprise Linux CoreOS AMI to use for bootstrap.
Type: AWS::EC2::Image::Id
Subnet:
Description: The subnets, recommend private, to launch the worker nodes into.
Type: AWS::EC2::Subnet::Id
WorkerSecurityGroupId:
Description: The worker security group ID to associate with worker nodes.
Type: AWS::EC2::SecurityGroup::Id
IgnitionLocation:
Default: https://api-int.$CLUSTER_NAME.$DOMAIN:22623/config/worker
Description: Ignition config file location.
Type: String
CertificateAuthorities:
Default: data:text/plain;charset=utf-8;base64,ABC...xYz==
Description: Base64 encoded certificate authority string to use.
Type: String
WorkerInstanceProfileName:
Description: IAM profile to associate with worker nodes.
Type: String
WorkerInstanceType:
Default: m5.large
Type: String
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: "Cluster Information"
Parameters:
- InfrastructureName
- Label:
default: "Host Information"
Parameters:
- WorkerInstanceType
- RhcosAmi
- IgnitionLocation
- CertificateAuthorities
- WorkerSecurityGroupId
- WorkerInstanceProfileName
- Label:
default: "Network Configuration"
Parameters:
- Subnet
ParameterLabels:
Subnet:
default: "Subnet"
InfrastructureName:
default: "Infrastructure Name"
WorkerInstanceType:
default: "Worker Instance Type"
WorkerInstanceProfileName:
default: "Worker Instance Profile Name"
RhcosAmi:
default: "Red Hat Enterprise Linux CoreOS AMI ID"
IgnitionLocation:
default: "Worker Ignition Source"
CertificateAuthorities:
default: "Ignition CA String"
WorkerSecurityGroupId:
default: "Worker Security Group ID"
Resources:
Worker0:
Type: AWS::EC2::Instance
Properties:
ImageId: !Ref RhcosAmi
BlockDeviceMappings:
- DeviceName: /dev/xvda
Ebs:
VolumeSize: "120"
VolumeType: "gp2"
IamInstanceProfile: !Ref WorkerInstanceProfileName
InstanceType: !Ref WorkerInstanceType
NetworkInterfaces:
- AssociatePublicIpAddress: "false"
DeviceIndex: "0"
GroupSet:
- !Ref "WorkerSecurityGroupId"
SubnetId: !Ref "Subnet"
UserData:
Fn::Base64: !Sub
- '{"ignition":{"config":{"merge":[{"source":"${SOURCE}"}]},"security":{"tls":{"certificateAuthorities":[{"source":"${CA_BUNDLE}"}]}},"version":"3.1.0"}}'
- {
SOURCE: !Ref IgnitionLocation,
CA_BUNDLE: !Ref CertificateAuthorities,
}
Tags:
- Key: !Join ["", ["kubernetes.io/cluster/", !Ref InfrastructureName]]
Value: "shared"
Outputs:
PrivateIP:
Description: The compute node private IP address.
Value: !GetAtt Worker0.PrivateIp