4.11.14. 在 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 机器。

流程

  1. 创建一个 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": "m4.2xlarge" 16
      }
    ]
    1
    您的 Ignition 配置文件中为集群编码的集群基础架构名称。
    2
    指定从 Ignition 配置文件元数据中提取的基础架构名称,其格式为 <cluster-name>-<random-string>
    3
    用于 worker 节点的当前 Red Hat Enterprise Linux CoreOS (RHCOS) AMI。
    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
    用于 control plane 机器的 AWS 实例类型。
    16
    允许的值:
    • m4.large
    • m4.xlarge
    • m4.2xlarge
    • m4.4xlarge
    • m4.10xlarge
    • m4.16xlarge
    • m5.large
    • m5.xlarge
    • m5.2xlarge
    • m5.4xlarge
    • m5.8xlarge
    • m5.12xlarge
    • m5.16xlarge
    • m5a.large
    • m5a.xlarge
    • m5a.2xlarge
    • m5a.4xlarge
    • m5a.8xlarge
    • m5a.10xlarge
    • m5a.16xlarge
    • c4.large
    • c4.xlarge
    • c4.2xlarge
    • c4.4xlarge
    • c4.8xlarge
    • c5.large
    • c5.xlarge
    • c5.2xlarge
    • c5.4xlarge
    • c5.9xlarge
    • c5.12xlarge
    • c5.18xlarge
    • c5.24xlarge
    • c5a.large
    • c5a.xlarge
    • c5a.2xlarge
    • c5a.4xlarge
    • c5a.8xlarge
    • c5a.12xlarge
    • c5a.16xlarge
    • c5a.24xlarge
    • r4.large
    • r4.xlarge
    • r4.2xlarge
    • r4.4xlarge
    • r4.8xlarge
    • r4.16xlarge
    • r5.large
    • r5.xlarge
    • r5.2xlarge
    • r5.4xlarge
    • r5.8xlarge
    • r5.12xlarge
    • r5.16xlarge
    • r5.24xlarge
    • r5a.large
    • r5a.xlarge
    • r5a.2xlarge
    • r5a.4xlarge
    • r5a.8xlarge
    • r5a.12xlarge
    • r5a.16xlarge
    • r5a.24xlarge
    • t3.large
    • t3.xlarge
    • t3.2xlarge
    • t3a.large
    • t3a.xlarge
    • t3a.2xlarge
  2. 复制 worker 机器的 CloudFormation 模板一节中的模板,并将它以 YAML 文件形式保存到计算机上。此模板描述了集群所需的网络对象和负载均衡器。
  3. 如果您将 m5 实例类型指定为 WorkerInstanceType 的值,请将该实例类型添加到 CloudFormation 模板中的 WorkerInstanceType.AllowedValues 参数。
  4. 启动 CloudFormation 模板,以创建代表 worker 节点的 AWS 资源堆栈:

    重要

    您必须在一行内输入命令。

    $ aws cloudformation create-stack --stack-name <name> 1
         --template-body file://<template>.yaml \ 2
         --parameters file://<parameters>.json 3
    1
    <name> 是 CloudFormation 堆栈的名称,如 cluster-worker-1。如果您删除集群,则需要此堆栈的名称。
    2
    <template> 是您保存的 CloudFormation 模板 YAML 文件的相对路径和名称。
    3
    <parameters> 是 CloudFormation 参数 JSON 文件的相对路径和名称。

    输出示例

    arn:aws:cloudformation:us-east-1:269333783861:stack/cluster-worker-1/729ee301-1c2a-11eb-348f-sd9888c65b59

    注意

    CloudFormation 模板会创建一个堆栈,它代表一个 worker 节点。

  5. 确认模板组件已存在:

    $ aws cloudformation describe-stacks --stack-name <name>
  6. 继续创建 worker 堆栈,直到为集群创建了充足的 worker 机器。您可以通过引用同一模板和参数文件并指定不同的堆栈名称来创建额外的 worker 堆栈。

    重要

    您必须至少创建两台 worker 机器,因此您必须创建至少两个使用此 CloudFormation 模板的堆栈。

4.11.14.1. worker 机器的 CloudFormation 模板

您可以使用以下 CloudFormation 模板来部署 OpenShift Container Platform 集群所需的 worker 机器。

例 4.40. 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 master nodes into.
    Type: AWS::EC2::Subnet::Id
  WorkerSecurityGroupId:
    Description: The master security group ID to associate with master 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 master nodes.
    Type: String
  WorkerInstanceType:
    Default: m5.large
    Type: String
    AllowedValues:
    - "m4.large"
    - "m4.xlarge"
    - "m4.2xlarge"
    - "m4.4xlarge"
    - "m4.10xlarge"
    - "m4.16xlarge"
    - "m5.large"
    - "m5.xlarge"
    - "m5.2xlarge"
    - "m5.4xlarge"
    - "m5.8xlarge"
    - "m5.12xlarge"
    - "m5.16xlarge"
    - "m5a.large"
    - "m5a.xlarge"
    - "m5a.2xlarge"
    - "m5a.4xlarge"
    - "m5a.8xlarge"
    - "m5a.10xlarge"
    - "m5a.16xlarge"
    - "c4.large"
    - "c4.xlarge"
    - "c4.2xlarge"
    - "c4.4xlarge"
    - "c4.8xlarge"
    - "c5.large"
    - "c5.xlarge"
    - "c5.2xlarge"
    - "c5.4xlarge"
    - "c5.9xlarge"
    - "c5.12xlarge"
    - "c5.18xlarge"
    - "c5.24xlarge"
    - "c5a.large"
    - "c5a.xlarge"
    - "c5a.2xlarge"
    - "c5a.4xlarge"
    - "c5a.8xlarge"
    - "c5a.12xlarge"
    - "c5a.16xlarge"
    - "c5a.24xlarge"
    - "r4.large"
    - "r4.xlarge"
    - "r4.2xlarge"
    - "r4.4xlarge"
    - "r4.8xlarge"
    - "r4.16xlarge"
    - "r5.large"
    - "r5.xlarge"
    - "r5.2xlarge"
    - "r5.4xlarge"
    - "r5.8xlarge"
    - "r5.12xlarge"
    - "r5.16xlarge"
    - "r5.24xlarge"
    - "r5a.large"
    - "r5a.xlarge"
    - "r5a.2xlarge"
    - "r5a.4xlarge"
    - "r5a.8xlarge"
    - "r5a.12xlarge"
    - "r5a.16xlarge"
    - "r5a.24xlarge"
    - "t3.large"
    - "t3.xlarge"
    - "t3.2xlarge"
    - "t3a.large"
    - "t3a.xlarge"
    - "t3a.2xlarge"

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

其他资源