6.13. 使用 CloudFormation 模板在 AWS 中用户置备的基础架构上安装集群

在 OpenShift Container Platform 版本 4.12 中,您可以使用您提供的基础架构在 Amazon Web Services (AWS) 上安装集群。

创建此基础架构的一种方法是使用提供的 CloudFormation 模板。您可以修改模板来自定义基础架构,或使用其包含的信息来按照公司策略创建 AWS 对象。

重要

进行用户置备的基础架构安装的步骤仅作为示例。使用您提供的基础架构安装集群需要了解云供应商和 OpenShift Container Platform 安装过程。提供的几个 CloudFormation 模板可帮助完成这些步骤,或者帮助您自行建模。您也可以自由选择通过其他方法创建所需的资源;模板仅作示例之用。

6.13.1. 先决条件

6.13.2. OpenShift Container Platform 互联网访问

在 OpenShift Container Platform 4.12 中,您需要访问互联网来安装集群。

您必须具有以下互联网访问权限:

  • 访问 OpenShift Cluster Manager Hybrid Cloud Console 以下载安装程序并执行订阅管理。如果集群可以访问互联网,并且没有禁用 Telemetry,该服务会自动授权您的集群。
  • 访问 Quay.io,以获取安装集群所需的软件包。
  • 获取执行集群更新所需的软件包。
重要

如果您的集群无法直接访问互联网,则可以在置备的某些类型的基础架构上执行受限网络安装。在此过程中,您可以下载所需的内容,并使用它为镜像 registry 填充安装软件包。对于某些安装类型,集群要安装到的环境不需要访问互联网。在更新集群前,您要更新镜像 registry 的内容。

6.13.3. 具有用户置备基础架构的集群的要求

对于包含用户置备的基础架构的集群,您必须部署所有所需的机器。

本节论述了在用户置备的基础架构上部署 OpenShift Container Platform 的要求。

6.13.3.1. 集群安装所需的机器

最小的 OpenShift Container Platform 集群需要以下主机:

表 6.46. 最低所需的主机

主机描述

一个临时 bootstrap 机器

集群需要 bootstrap 机器在三台 control plane 机器上部署 OpenShift Container Platform 集群。您可在安装集群后删除 bootstrap 机器。

三台 control plane 机器

control plane 机器运行组成 control plane 的 Kubernetes 和 OpenShift Container Platform 服务。

至少两台计算机器,也称为 worker 机器。

OpenShift Container Platform 用户请求的工作负载在计算机器上运行。

重要

要保持集群的高可用性,请将独立的物理主机用于这些集群机器。

bootstrap 和 control plane 机器必须使用 Red Hat Enterprise Linux CoreOS(RHCOS)作为操作系统。但是,计算机器可以在 Red Hat Enterprise Linux CoreOS(RHCOS)、Red Hat Enterprise Linux(RHEL) 8.6 和更高的版本。

请注意,RHCOS 基于 Red Hat Enterprise Linux(RHEL)8,并继承其所有硬件认证和要求。查看 红帽企业 Linux 技术功能和限制

6.13.3.2. 集群安装的最低资源要求

每台集群机器都必须满足以下最低要求:

表 6.47. 最低资源要求

机器操作系统vCPU [1]虚拟内存Storage每秒输入/输出 (IOPS) [2]

bootstrap

RHCOS

4

16 GB

100 GB

300

Control plane(控制平面)

RHCOS

4

16 GB

100 GB

300

Compute

RHCOS、RHEL 8.6 及更新版本 [3]

2

8 GB

100 GB

300

  1. 当未启用并发多线程(SMT)或超线程时,一个 vCPU 相当于一个物理内核。启用后,使用以下公式来计算对应的比例:(每个内核数的线程)× sockets = vCPU。
  2. OpenShift Container Platform 和 Kubernetes 对磁盘性能非常敏感,建议使用更快的存储速度,特别是 control plane 节点上需要 10 ms p99 fsync 持续时间的 etcd。请注意,在许多云平台上,存储大小和 IOPS 可一起扩展,因此您可能需要过度分配存储卷来获取足够的性能。
  3. 与所有用户置备的安装一样,如果您选择在集群中使用 RHEL 计算机器,则负责所有操作系统生命周期管理和维护,包括执行系统更新、应用补丁和完成所有其他必要的任务。RHEL 7 计算机器的使用已弃用,并已在 OpenShift Container Platform 4.10 及更新的版本中删除。

如果平台的实例类型满足集群机器的最低要求,则 OpenShift Container Platform 支持使用它。

其他资源

6.13.3.3. 为 AWS 测试的实例类型

以下 Amazon Web Services(AWS) 实例类型已经过 OpenShift Container Platform 测试。

注意

将以下图中包含的机器类型用于 AWS 实例。如果您使用没有在图中列出的实例类型,请确保使用的实例大小与集群安装"最小资源要求"中列出的最少资源要求匹配。

例 6.29. 基于 64 位 x86 架构的机器类型

  • c4.*
  • c5.*
  • c5a.*
  • i3.*
  • m4.*
  • m5.*
  • m5a.*
  • m6a.*
  • m6i.*
  • r4.*
  • r5.*
  • r5a.*
  • r6i.*
  • t3.*
  • t3a.*

6.13.3.4. 在 64 位 ARM 基础架构上为 AWS 测试过的实例类型

OpenShift Container Platform 中已经测试了以下 Amazon Web Services (AWS) ARM64 实例类型。

注意

使用 AWS ARM 实例的以下图中包含的机器类型。如果您使用没有在图中列出的实例类型,请确保使用的实例大小与集群安装"最小资源要求"中列出的最少资源要求匹配。

例 6.30. 基于 64 位 ARM 架构的机器类型

  • c6g.*
  • m6g.*

6.13.3.5. 证书签名请求管理

在使用您置备的基础架构时,集群只能有限地访问自动机器管理,因此您必须提供一种在安装后批准集群证书签名请求 (CSR) 的机制。kube-controller-manager 只能批准 kubelet 客户端 CSR。machine-approver 无法保证使用 kubelet 凭证请求的提供证书的有效性,因为它不能确认是正确的机器发出了该请求。您必须决定并实施一种方法,以验证 kubelet 提供证书请求的有效性并进行批准。

6.13.4. 所需的 AWS 基础架构组件

要在 Amazon Web Services (AWS) 中用户置备的基础架构上安装 OpenShift Container Platform,您必须手动创建机器及其支持的基础架构。

如需有关不同平台集成测试的更多信息,请参阅 OpenShift Container Platform 4.x Tested Integrations页面。

通过使用提供的 CloudFormation 模板,您可以创建代表以下组件的 AWS 资源堆栈:

  • 一个 AWS Virtual Private Cloud (VPC)
  • 网络和负载均衡组件
  • 安全组和角色
  • 一个 OpenShift Container Platform bootstrap 节点
  • OpenShift Container Platform control plane 节点
  • 一个 OpenShift Container Platform 计算节点

或者,您可以手动创建组件,也可以重复使用满足集群要求的现有基础架构。查看 CloudFormation 模板,了解组件如何相互连接的更多详情。

6.13.4.1. 其他基础架构组件

  • VPC
  • DNS 条目
  • 负载均衡器(典型或网络)和监听器
  • 公共和专用路由 53 区域
  • 安全组
  • IAM 角色
  • S3 存储桶

如果您在断开连接的环境中工作,则无法访问 EC2、ELB 和 S3 端点的公共 IP 地址。根据您要在安装过程中限制互联网流量的级别,有以下配置选项:

选项 1:创建 VPC 端点

创建 VPC 端点,并将其附加到集群使用的子网。将端点命名为如下:

  • ec2.<aws_region>.amazonaws.com
  • elasticloadbalancing.<aws_region>.amazonaws.com
  • s3.<aws_region>.amazonaws.com

通过这个选项,网络流量在 VPC 和所需的 AWS 服务之间保持私有。

选项 2:创建一个没有 VPC 端点的代理

作为安装过程的一部分,您可以配置 HTTP 或 HTTPS 代理。使用此选项时,互联网流量会通过代理访问所需的 AWS 服务。

选项 3:创建带有 VPC 端点的代理

作为安装过程的一部分,您可以使用 VPC 端点配置 HTTP 或 HTTPS 代理。创建 VPC 端点,并将其附加到集群使用的子网。将端点命名为如下:

  • ec2.<aws_region>.amazonaws.com
  • elasticloadbalancing.<aws_region>.amazonaws.com
  • s3.<aws_region>.amazonaws.com

install-config.yaml 文件中配置代理时,将这些端点添加到 noProxy 字段。通过这个选项,代理会阻止集群直接访问互联网。但是,您的 VPC 和所需的 AWS 服务之间网络流量保持私有。

所需的 VPC 组件

您必须提供合适的 VPC 和子网,以便与您的机器通信。

组件AWS 类型描述

VPC

  • AWS::EC2::VPC
  • AWS::EC2::VPCEndpoint

您必须提供一个公共 VPC 供集群使用。VPC 使用引用每个子网的路由表的端点,以改进与托管在 S3 中的 registry 的通信。

公共子网

  • AWS::EC2::Subnet
  • AWS::EC2::SubnetNetworkAclAssociation

您的 VPC 必须有 1 到 3 个可用区的公共子网,并将其与适当的入口规则关联。

互联网网关

  • AWS::EC2::InternetGateway
  • AWS::EC2::VPCGatewayAttachment
  • AWS::EC2::RouteTable
  • AWS::EC2::Route
  • AWS::EC2::SubnetRouteTableAssociation
  • AWS::EC2::NatGateway
  • AWS::EC2::EIP

您必须有一个公共互联网网关,以及附加到 VPC 的公共路由。在提供的模板中,每个公共子网都有一个具有 EIP 地址的 NAT 网关。这些 NAT 网关允许集群资源(如专用子网实例)访问互联网,而有些受限网络或代理场景则不需要它们。

网络访问控制

  • AWS::EC2::NetworkAcl
  • AWS::EC2::NetworkAclEntry

您必须允许 VPC 访问下列端口:

端口

原因

80

入站 HTTP 流量

443

入站 HTTPS 流量

22

入站 SSH 流量

1024 - 65535

入站临时流量

0 - 65535

出站临时流量

专用子网

  • AWS::EC2::Subnet
  • AWS::EC2::RouteTable
  • AWS::EC2::SubnetRouteTableAssociation

您的 VPC 可以具有私有子网。提供的 CloudFormation 模板可为 1 到 3 个可用区创建专用子网。如果您使用专用子网,必须为其提供适当的路由和表。

所需的 DNS 和负载均衡组件

您的 DNS 和负载均衡器配置需要使用公共托管区,并可使用类似安装程序使用的专用托管区(如果安装程序置备了集群的基础架构)。您必须创建一个解析到负载均衡器的 DNS 条目。api.<cluster_name>.<domain> 的条目必须指向外部负载均衡器,api-int.<cluster_name>.<domain> 的条目则必须指向内部负载均衡器。

集群还需要负载均衡器,以及监听端口 6443(用于 Kubernetes API 及其扩展)和端口 22623(用于新机器的 Ignition 配置文件)的监听程序。目标是 control plane 节点。集群外的客户端和集群内的节点都必须能够访问端口 6443。集群内的节点必须能够访问端口 22623。

组件AWS 类型描述

DNS

AWS::Route53::HostedZone

内部 DNS 的托管区。

公共负载均衡器

AWS::ElasticLoadBalancingV2::LoadBalancer

公共子网的负载均衡器。

外部 API 服务器记录

AWS::Route53::RecordSetGroup

外部 API 服务器的别名记录。

外部监听程序

AWS::ElasticLoadBalancingV2::Listener

为外部负载均衡器监听端口 6443 的监听程序。

外部目标组

AWS::ElasticLoadBalancingV2::TargetGroup

外部负载均衡器的目标组。

专用负载均衡器

AWS::ElasticLoadBalancingV2::LoadBalancer

专用子网的负载均衡器。

内部 API 服务器记录

AWS::Route53::RecordSetGroup

内部 API 服务器的别名记录。

内部监听程序

AWS::ElasticLoadBalancingV2::Listener

为内部负载均衡器监听端口 22623 的监听程序。

内部目标组

AWS::ElasticLoadBalancingV2::TargetGroup

内部负载均衡器的目标组。

内部监听程序

AWS::ElasticLoadBalancingV2::Listener

为内部负载均衡器监听端口 6443 的监听程序。

内部目标组

AWS::ElasticLoadBalancingV2::TargetGroup

内部负载均衡器的目标组。

安全组

control plane 和 worker 机器需要访问下列端口:

类型IP 协议端口范围

MasterSecurityGroup

AWS::EC2::SecurityGroup

icmp

0

tcp

22

tcp

6443

tcp

22623

WorkerSecurityGroup

AWS::EC2::SecurityGroup

icmp

0

tcp

22

BootstrapSecurityGroup

AWS::EC2::SecurityGroup

tcp

22

tcp

19531

control plane 入口

control plane 机器需要以下入口组。每个入口组都是 AWS::EC2::SecurityGroupIngress 资源。

入口组描述IP 协议端口范围

MasterIngressEtcd

etcd

tcp

2379- 2380

MasterIngressVxlan

Vxlan 数据包

udp

4789

MasterIngressWorkerVxlan

Vxlan 数据包

udp

4789

MasterIngressInternal

内部集群通信和 Kubernetes 代理指标

tcp

9000 - 9999

MasterIngressWorkerInternal

内部集群通信

tcp

9000 - 9999

MasterIngressKube

kubernetes kubelet、调度程序和控制器管理器

tcp

10250 - 10259

MasterIngressWorkerKube

kubernetes kubelet、调度程序和控制器管理器

tcp

10250 - 10259

MasterIngressIngressServices

Kubernetes 入口服务

tcp

30000 - 32767

MasterIngressWorkerIngressServices

Kubernetes 入口服务

tcp

30000 - 32767

MasterIngressGeneve

Geneve 包

udp

6081

MasterIngressWorkerGeneve

Geneve 包

udp

6081

MasterIngressIpsecIke

IPsec IKE 数据包

udp

500

MasterIngressWorkerIpsecIke

IPsec IKE 数据包

udp

500

MasterIngressIpsecNat

IPsec NAT-T 数据包

udp

4500

MasterIngressWorkerIpsecNat

IPsec NAT-T 数据包

udp

4500

MasterIngressIpsecEsp

IPsec ESP 数据包

50

All

MasterIngressWorkerIpsecEsp

IPsec ESP 数据包

50

All

MasterIngressInternalUDP

内部集群通信

udp

9000 - 9999

MasterIngressWorkerInternalUDP

内部集群通信

udp

9000 - 9999

MasterIngressIngressServicesUDP

Kubernetes 入口服务

udp

30000 - 32767

MasterIngressWorkerIngressServicesUDP

Kubernetes 入口服务

udp

30000 - 32767

worker 入口

worker 机器需要以下入口组。每个入口组都是 AWS::EC2::SecurityGroupIngress 资源。

入口组描述IP 协议端口范围

WorkerIngressVxlan

Vxlan 数据包

udp

4789

WorkerIngressWorkerVxlan

Vxlan 数据包

udp

4789

WorkerIngressInternal

内部集群通信

tcp

9000 - 9999

WorkerIngressWorkerInternal

内部集群通信

tcp

9000 - 9999

WorkerIngressKube

Kubernetes kubelet、调度程序和控制器管理器

tcp

10250

WorkerIngressWorkerKube

Kubernetes kubelet、调度程序和控制器管理器

tcp

10250

WorkerIngressIngressServices

Kubernetes 入口服务

tcp

30000 - 32767

WorkerIngressWorkerIngressServices

Kubernetes 入口服务

tcp

30000 - 32767

WorkerIngressGeneve

Geneve 包

udp

6081

WorkerIngressMasterGeneve

Geneve 包

udp

6081

WorkerIngressIpsecIke

IPsec IKE 数据包

udp

500

WorkerIngressMasterIpsecIke

IPsec IKE 数据包

udp

500

WorkerIngressIpsecNat

IPsec NAT-T 数据包

udp

4500

WorkerIngressMasterIpsecNat

IPsec NAT-T 数据包

udp

4500

WorkerIngressIpsecEsp

IPsec ESP 数据包

50

All

WorkerIngressMasterIpsecEsp

IPsec ESP 数据包

50

All

WorkerIngressInternalUDP

内部集群通信

udp

9000 - 9999

WorkerIngressMasterInternalUDP

内部集群通信

udp

9000 - 9999

WorkerIngressIngressServicesUDP

Kubernetes 入口服务

udp

30000 - 32767

WorkerIngressMasterIngressServicesUDP

Kubernetes 入口服务

udp

30000 - 32767

角色和实例配置集

您必须在 AWS 中为机器授予权限。提供的 CloudFormation 模板为以下 AWS::IAM::Role 对象授予机器 Allow 权限,并为每一组角色提供一个 AWS::IAM::InstanceProfile。如果不使用模板,您可以为机器授予以下宽泛权限或单独权限。

角色影响操作资源

Master

Allow

ec2:*

*

Allow

elasticloadbalancing:*

*

Allow

iam:PassRole

*

Allow

s3:GetObject

*

Worker

Allow

ec2:Describe*

*

bootstrap

Allow

ec2:Describe*

*

Allow

ec2:AttachVolume

*

Allow

ec2:DetachVolume

*

6.13.4.2. 集群机器

以下机器需要 AWS::EC2::Instance 对象:

  • bootstrap 机器。安装过程中需要此机器,但可在集群部署后删除。
  • 三个 control plane 机器。control plane 机器不受 control plane 机器集的管控。
  • 计算机器。在安装过程中创建至少两台计算(compute)机器(也称为 worker 机器)。这些机器不受计算机器集的管控。

6.13.4.3. IAM 用户所需的 AWS 权限

注意

您的 IAM 用户必须在区域 us-east-1 中有权限 tag:GetResources 来删除基本集群资源。作为 AWS API 的要求的一部分,OpenShift Container Platform 安装程序在此区域中执行各种操作。

AdministratorAccess 策略附加到您在 Amazon Web Services (AWS) 中创建的 IAM 用户时,授予该用户所有需要的权限。要部署 OpenShift Container Platform 集群的所有组件,IAM 用户需要以下权限:

例 6.31. 安装所需的 EC2 权限

  • ec2:AuthorizeSecurityGroupEgress
  • ec2:AuthorizeSecurityGroupIngress
  • ec2:CopyImage
  • ec2:CreateNetworkInterface
  • ec2:AttachNetworkInterface
  • ec2:CreateSecurityGroup
  • ec2:CreateTags
  • ec2:CreateVolume
  • ec2:DeleteSecurityGroup
  • ec2:DeleteSnapshot
  • ec2:DeleteTags
  • ec2:DeregisterImage
  • ec2:DescribeAccountAttributes
  • ec2:DescribeAddresses
  • ec2:DescribeAvailabilityZones
  • ec2:DescribeDhcpOptions
  • ec2:DescribeImages
  • ec2:DescribeInstanceAttribute
  • ec2:DescribeInstanceCreditSpecifications
  • ec2:DescribeInstances
  • ec2:DescribeInstanceTypes
  • ec2:DescribeInternetGateways
  • ec2:DescribeKeyPairs
  • ec2:DescribeNatGateways
  • ec2:DescribeNetworkAcls
  • ec2:DescribeNetworkInterfaces
  • ec2:DescribePrefixLists
  • ec2:DescribeRegions
  • ec2:DescribeRouteTables
  • ec2:DescribeSecurityGroups
  • ec2:DescribeSubnets
  • ec2:DescribeTags
  • ec2:DescribeVolumes
  • ec2:DescribeVpcAttribute
  • ec2:DescribeVpcClassicLink
  • ec2:DescribeVpcClassicLinkDnsSupport
  • ec2:DescribeVpcEndpoints
  • ec2:DescribeVpcs
  • ec2:GetEbsDefaultKmsKeyId
  • ec2:ModifyInstanceAttribute
  • ec2:ModifyNetworkInterfaceAttribute
  • ec2:RevokeSecurityGroupEgress
  • ec2:RevokeSecurityGroupIngress
  • ec2:RunInstances
  • ec2:TerminateInstances

例 6.32. 安装过程中创建网络资源所需的权限

  • ec2:AllocateAddress
  • ec2:AssociateAddress
  • ec2:AssociateDhcpOptions
  • ec2:AssociateRouteTable
  • ec2:AttachInternetGateway
  • ec2:CreateDhcpOptions
  • ec2:CreateInternetGateway
  • ec2:CreateNatGateway
  • ec2:CreateRoute
  • ec2:CreateRouteTable
  • ec2:CreateSubnet
  • ec2:CreateVpc
  • ec2:CreateVpcEndpoint
  • ec2:ModifySubnetAttribute
  • ec2:ModifyVpcAttribute
注意

如果您使用现有的 VPC,您的帐户不需要这些权限来创建网络资源。

例 6.33. 安装所需的 Elastic Load Balancing 权限(ELB)

  • elasticloadbalancing:AddTags
  • elasticloadbalancing:ApplySecurityGroupsToLoadBalancer
  • elasticloadbalancing:AttachLoadBalancerToSubnets
  • elasticloadbalancing:ConfigureHealthCheck
  • elasticloadbalancing:CreateLoadBalancer
  • elasticloadbalancing:CreateLoadBalancerListeners
  • elasticloadbalancing:DeleteLoadBalancer
  • elasticloadbalancing:DeregisterInstancesFromLoadBalancer
  • elasticloadbalancing:DescribeInstanceHealth
  • elasticloadbalancing:DescribeLoadBalancerAttributes
  • elasticloadbalancing:DescribeLoadBalancers
  • elasticloadbalancing:DescribeTags
  • elasticloadbalancing:ModifyLoadBalancerAttributes
  • elasticloadbalancing:RegisterInstancesWithLoadBalancer
  • elasticloadbalancing:SetLoadBalancerPoliciesOfListener

例 6.34. 安装所需的 Elastic Load Balancing 权限(ELBv2)

  • elasticloadbalancing:AddTags
  • elasticloadbalancing:CreateListener
  • elasticloadbalancing:CreateLoadBalancer
  • elasticloadbalancing:CreateTargetGroup
  • elasticloadbalancing:DeleteLoadBalancer
  • elasticloadbalancing:DeregisterTargets
  • elasticloadbalancing:DescribeListeners
  • elasticloadbalancing:DescribeLoadBalancerAttributes
  • elasticloadbalancing:DescribeLoadBalancers
  • elasticloadbalancing:DescribeTargetGroupAttributes
  • elasticloadbalancing:DescribeTargetHealth
  • elasticloadbalancing:ModifyLoadBalancerAttributes
  • elasticloadbalancing:ModifyTargetGroup
  • elasticloadbalancing:ModifyTargetGroupAttributes
  • elasticloadbalancing:RegisterTargets

例 6.35. 安装所需的 IAM 权限

  • iam:AddRoleToInstanceProfile
  • iam:CreateInstanceProfile
  • iam:CreateRole
  • iam:DeleteInstanceProfile
  • iam:DeleteRole
  • iam:DeleteRolePolicy
  • iam:GetInstanceProfile
  • iam:GetRole
  • iam:GetRolePolicy
  • iam:GetUser
  • iam:ListInstanceProfilesForRole
  • iam:ListRoles
  • iam:ListUsers
  • iam:PassRole
  • iam:PutRolePolicy
  • iam:RemoveRoleFromInstanceProfile
  • iam:SimulatePrincipalPolicy
  • iam:TagRole
注意

如果您还没有在 AWS 帐户中创建负载均衡器,IAM 用户还需要 iam:CreateServiceLinkedRole 权限。

例 6.36. 安装所需的 Route 53 权限

  • route53:ChangeResourceRecordSets
  • route53:ChangeTagsForResource
  • route53:CreateHostedZone
  • route53:DeleteHostedZone
  • route53:GetChange
  • route53:GetHostedZone
  • route53:ListHostedZones
  • route53:ListHostedZonesByName
  • route53:ListResourceRecordSets
  • route53:ListTagsForResource
  • route53:UpdateHostedZoneComment

例 6.37. 安装所需的 S3 权限

  • s3:CreateBucket
  • s3:DeleteBucket
  • s3:GetAccelerateConfiguration
  • s3:GetBucketAcl
  • s3:GetBucketCors
  • s3:GetBucketLocation
  • s3:GetBucketLogging
  • s3:GetBucketPolicy
  • s3:GetBucketObjectLockConfiguration
  • s3:GetBucketReplication
  • s3:GetBucketRequestPayment
  • s3:GetBucketTagging
  • s3:GetBucketVersioning
  • s3:GetBucketWebsite
  • s3:GetEncryptionConfiguration
  • s3:GetLifecycleConfiguration
  • s3:GetReplicationConfiguration
  • s3:ListBucket
  • s3:PutBucketAcl
  • s3:PutBucketTagging
  • s3:PutEncryptionConfiguration

例 6.38. 集群 Operators 所需的 S3 权限

  • s3:DeleteObject
  • s3:GetObject
  • s3:GetObjectAcl
  • s3:GetObjectTagging
  • s3:GetObjectVersion
  • s3:PutObject
  • s3:PutObjectAcl
  • s3:PutObjectTagging

例 6.39. 删除基本集群资源所需的权限

  • autoscaling:DescribeAutoScalingGroups
  • ec2:DeletePlacementGroup
  • ec2:DeleteNetworkInterface
  • ec2:DeleteVolume
  • elasticloadbalancing:DeleteTargetGroup
  • elasticloadbalancing:DescribeTargetGroups
  • iam:DeleteAccessKey
  • iam:DeleteUser
  • iam:ListAttachedRolePolicies
  • iam:ListInstanceProfiles
  • iam:ListRolePolicies
  • iam:ListUserPolicies
  • s3:DeleteObject
  • s3:ListBucketVersions
  • tag:GetResources

例 6.40. 删除网络资源所需的权限

  • ec2:DeleteDhcpOptions
  • ec2:DeleteInternetGateway
  • ec2:DeleteNatGateway
  • ec2:DeleteRoute
  • ec2:DeleteRouteTable
  • ec2:DeleteSubnet
  • ec2:DeleteVpc
  • ec2:DeleteVpcEndpoints
  • ec2:DetachInternetGateway
  • ec2:DisassociateRouteTable
  • ec2:ReleaseAddress
  • ec2:ReplaceRouteTableAssociation
注意

如果您使用现有的 VPC,您的帐户不需要这些权限来删除网络资源。您的帐户只需要有 tag:UntagResources 权限就能删除网络资源。

例 6.41. 使用共享实例角色删除集群所需的权限

  • iam:UntagRole

例 6.42. 创建清单所需的额外 IAM 和 S3 权限

  • iam:DeleteAccessKey
  • iam:DeleteUser
  • iam:DeleteUserPolicy
  • iam:GetUserPolicy
  • iam:ListAccessKeys
  • iam:PutUserPolicy
  • iam:TagUser
  • s3:PutBucketPublicAccessBlock
  • s3:GetBucketPublicAccessBlock
  • s3:PutLifecycleConfiguration
  • s3:ListBucket
  • s3:ListBucketMultipartUploads
  • s3:AbortMultipartUpload
注意

如果您要使用 mint 模式管理云供应商凭证,IAM 用户还需要 The iam:CreateAccessKeyiam:CreateUser 权限。

例 6.43. 实例的可选权限和安装配额检查

  • ec2:DescribeInstanceTypeOfferings
  • servicequotas:ListAWSDefaultServiceQuotas

6.13.5. 获取 AWS Marketplace 镜像

如果要使用 AWS Marketplace 镜像部署 OpenShift Container Platform 集群,您必须首先通过 AWS 订阅。订阅提供的提供的 AMI ID 可让您使用安装程序用来部署 worker 节点的 AMI ID。

先决条件

  • 有 AWS 账户购买的产品。此帐户不必与用于安装集群的帐户相同。

流程

  1. AWS Marketplace 完成 OpenShift Container Platform 订阅。
  2. 记录特定区域的 AMI ID。如果使用 CloudFormation 模板来部署 worker 节点,您必须更新 worker0.type.properties.ImageID 参数。

6.13.6. 获取安装程序

在安装 OpenShift Container Platform 前,将安装文件下载到您用于安装的主机上。

先决条件

  • 您有一台运行 Linux 或 macOS 的计算机,本地磁盘空间为 500 MB。

流程

  1. 访问 OpenShift Cluster Manager 站点的 Infrastructure Provider 页面。如果您有红帽帐户,请使用您的凭证登录。如果没有,请创建一个帐户。
  2. 选择您的基础架构供应商。
  3. 进入到安装类型的页面,下载与您的主机操作系统和架构对应的安装程序,并将该文件放在您要存储安装配置文件的目录中。

    重要

    安装程序会在用来安装集群的计算机上创建几个文件。在完成集群安装后,您必须保留安装程序和安装程序所创建的文件。这两个文件都需要删除集群。

    重要

    删除安装程序创建的文件不会删除您的集群,即使集群在安装过程中失败也是如此。要删除集群,请为特定云供应商完成 OpenShift Container Platform 卸载流程。

  4. 提取安装程序。例如,在使用 Linux 操作系统的计算机上运行以下命令:

    $ tar -xvf openshift-install-linux.tar.gz
  5. 从 Red Hat OpenShift Cluster Manager 下载安装 pull secret。此 pull secret 允许您与所含授权机构提供的服务进行身份验证,这些服务包括为 OpenShift Container Platform 组件提供容器镜像的 Quay.io。

6.13.7. 为集群节点 SSH 访问生成密钥对

在 OpenShift Container Platform 安装过程中,您可以为安装程序提供 SSH 公钥。密钥通过它们的 Ignition 配置文件传递给 Red Hat Enterprise Linux CoreOS(RHCOS)节点,用于验证对节点的 SSH 访问。密钥添加到每个节点上 core 用户的 ~/.ssh/authorized_keys 列表中,这将启用免密码身份验证。

将密钥传递给节点后,您可以使用密钥对作为用户 核心 通过 SSH 连接到 RHCOS 节点。若要通过 SSH 访问节点,必须由 SSH 为您的本地用户管理私钥身份。

如果要通过 SSH 连接到集群节点来执行安装调试或灾难恢复,则必须在安装过程中提供 SSH 公钥。./openshift-install gather 命令还需要在集群节点上设置 SSH 公钥。

重要

不要在生产环境中跳过这个过程,在生产环境中需要灾难恢复和调试。

注意

您必须使用本地密钥,而不是使用特定平台方法配置 的密钥,如 AWS 密钥对

流程

  1. 如果您在本地计算机上没有可用于在集群节点上进行身份验证的现有 SSH 密钥对,请创建一个。例如,在使用 Linux 操作系统的计算机上运行以下命令:

    $ ssh-keygen -t ed25519 -N '' -f <path>/<file_name> 1
    1
    指定新 SSH 密钥的路径和文件名,如 ~/.ssh/id_ed25519。如果您已有密钥对,请确保您的公钥位于 ~/.ssh 目录中。
    注意

    如果您计划在 x86_64ppc64les390x 架构上安装使用 FIPS 验证或 Modules In Process 加密库的 OpenShift Container Platform 集群。请不要创建使用 ed25519 算法的密钥。相反,创建一个使用 rsaecdsa 算法的密钥。

  2. 查看公共 SSH 密钥:

    $ cat <path>/<file_name>.pub

    例如,运行以下命令来查看 ~/.ssh/id_ed25519.pub 公钥:

    $ cat ~/.ssh/id_ed25519.pub
  3. 将 SSH 私钥身份添加到本地用户的 SSH 代理(如果尚未添加)。在集群节点上,或者要使用 ./openshift-install gather 命令,需要对该密钥进行 SSH 代理管理,才能在集群节点上进行免密码 SSH 身份验证。

    注意

    在某些发行版中,自动管理默认 SSH 私钥身份,如 ~/.ssh/id_rsa~/.ssh/id_dsa

    1. 如果 ssh-agent 进程尚未为您的本地用户运行,请将其作为后台任务启动:

      $ eval "$(ssh-agent -s)"

      输出示例

      Agent pid 31874

      注意

      如果集群处于 FIPS 模式,则只使用 FIPS 兼容算法来生成 SSH 密钥。密钥必须是 RSA 或 ECDSA。

  4. 将 SSH 私钥添加到 ssh-agent

    $ ssh-add <path>/<file_name> 1
    1
    指定 SSH 私钥的路径和文件名,如 ~/.ssh/id_ed25519.pub

    输出示例

    Identity added: /home/<you>/<path>/<file_name> (<computer_name>)

后续步骤

  • 安装 OpenShift Container Platform 时,为安装程序提供 SSH 公钥。如果在您置备的基础架构上安装集群,则必须为安装程序提供密钥。

6.13.8. 创建用于 AWS 的安装文件

要使用用户置备的基础架构在 Amazon Web Services (AWS) 上安装 OpenShift Container Platform,您必须生成并修改安装程序部署集群所需的文件,以便集群只创建要使用的机器。您要生成并自定义 install-config.yaml 文件、Kubernetes 清单和 Ignition 配置文件。您还可以选择在安装准备阶段首先设置独立 var 分区。

6.13.8.1. 可选:创建独立 /var 分区

建议安装程序将 OpenShift Container Platform 的磁盘分区保留给安装程序。然而,在有些情况下您可能需要在文件系统的一部分中创建独立分区。

OpenShift Container Platform 支持添加单个分区来将存储附加到 /var 分区或 /var 的子目录中。例如:

  • /var/lib/containers :保存随着系统中添加更多镜像和容器而增长的容器相关内容。
  • /var/lib/etcd :保存您可能希望独立保留的数据,比如 etcd 存储的性能优化。
  • /var :保存您可能希望独立保留的数据,以满足审计等目的。

通过单独存储 /var 目录的内容,可以更轻松地根据需要为区域扩展存储,并在以后重新安装 OpenShift Container Platform,并保持该数据的完整性。使用这个方法,您不必再次拉取所有容器,在更新系统时也不必复制大量日志文件。

因为 /var 在进行一个全新的 Red Hat Enterprise Linux CoreOS(RHCOS)安装前必需存在,所以这个流程会在 OpenShift Container Platform 安装过程的 openshift-install 准备阶段插入一个创建的机器配置清单的机器配置来设置独立的 /var 分区。

重要

如果按照以下步骤在此流程中创建独立 /var 分区,则不需要再次创建 Kubernetes 清单和 Ignition 配置文件,如本节所述。

流程

  1. 创建存放 OpenShift Container Platform 安装文件的目录:

    $ mkdir $HOME/clusterconfig
  2. 运行 openshift-install,以在 manifestopenshift 子目录中创建一组文件。在系统提示时回答系统问题:

    $ openshift-install create manifests --dir $HOME/clusterconfig

    输出示例

    ? SSH Public Key ...
    INFO Credentials loaded from the "myprofile" profile in file "/home/myuser/.aws/credentials"
    INFO Consuming Install Config from target directory
    INFO Manifests created in: $HOME/clusterconfig/manifests and $HOME/clusterconfig/openshift

  3. 可选:确认安装程序在 clusterconfig/openshift 目录中创建了清单:

    $ ls $HOME/clusterconfig/openshift/

    输出示例

    99_kubeadmin-password-secret.yaml
    99_openshift-cluster-api_master-machines-0.yaml
    99_openshift-cluster-api_master-machines-1.yaml
    99_openshift-cluster-api_master-machines-2.yaml
    ...

  4. 创建用于配置额外分区的 Butane 配置。例如,将文件命名为 $HOME/clusterconfig/98-var-partition.bu,将磁盘设备名称改为 worker 系统上存储设备的名称,并根据情况设置存储大小。这个示例将 /var 目录放在一个单独的分区中:

    variant: openshift
    version: 4.12.0
    metadata:
      labels:
        machineconfiguration.openshift.io/role: worker
      name: 98-var-partition
    storage:
      disks:
      - device: /dev/<device_name> 1
        partitions:
        - label: var
          start_mib: <partition_start_offset> 2
          size_mib: <partition_size> 3
          number: 5
      filesystems:
        - device: /dev/disk/by-partlabel/var
          path: /var
          format: xfs
          mount_options: [defaults, prjquota] 4
          with_mount_unit: true
    1
    要分区的磁盘的存储设备名称。
    2
    在引导磁盘中添加数据分区时,推荐最少使用 25000 MiB(Mebibytes)。root 文件系统会自动调整大小以填充所有可用空间(最多到指定的偏移值)。如果没有指定值,或者指定的值小于推荐的最小值,则生成的 root 文件系统会太小,而在以后进行的 RHCOS 重新安装可能会覆盖数据分区的开始部分。
    3
    以兆字节为单位的数据分区大小。
    4
    对于用于容器存储的文件系统,必须启用 prjquota 挂载选项。
    注意

    当创建单独的 /var 分区时,如果不同的实例类型没有相同的设备名称,则无法为 worker 节点使用不同的实例类型。

  5. 从 Butane 配置创建一个清单,并将它保存到 clusterconfig/openshift 目录中。例如,运行以下命令:

    $ butane $HOME/clusterconfig/98-var-partition.bu -o $HOME/clusterconfig/openshift/98-var-partition.yaml
  6. 再次运行 openshift-install,从 manifestopenshift 子目录中的一组文件创建 Ignition 配置:

    $ openshift-install create ignition-configs --dir $HOME/clusterconfig
    $ ls $HOME/clusterconfig/
    auth  bootstrap.ign  master.ign  metadata.json  worker.ign

现在,您可以使用 Ignition 配置文件作为安装程序的输入来安装 Red Hat Enterprise Linux CoreOS(RHCOS)系统。

6.13.8.2. 创建安装配置文件

生成并自定义安装程序部署集群所需的安装配置文件。

先决条件

  • 已获取 OpenShift Container Platform 安装程序用于用户置备的基础架构和集群的 pull secret。
  • 使用红帽发布的附带 Red Hat Enterprise Linux CoreOS(RHCOS)AMI 检查您是否将集群部署到一个区域。如果您要部署到需要自定义 AMI 的区域,如 AWS GovCloud 区域,您必须手动创建 install-config.yaml 文件。

流程

  1. 创建 install-config.yaml 文件。

    1. 进入包含安装程序的目录并运行以下命令:

      $ ./openshift-install create install-config --dir <installation_directory> 1
      1
      对于 <installation_directory>,请指定要存储安装程序创建的文件的目录名称。
      重要

      指定一个空目录。有些安装资产,如 bootstrap X.509 证书的过期间隔较短,因此不得重复使用安装目录。如果要重复使用另一个集群安装中的单个文件,您可以将它们复制到您的目录中。但是,安装资产的文件名可能会在发行版本间有所变化。从以前的 OpenShift Container Platform 版本中复制安装文件时请小心。

    2. 在提示符处,提供云的配置详情:

      1. 可选: 选择用于访问集群机器的 SSH 密钥。

        注意

        对于您要在其上执行安装调试或灾难恢复的生产环境 OpenShift Container Platform 集群,请指定 ssh-agent 进程使用的 SSH 密钥。

      2. 选择 aws 作为目标平台。
      3. 如果计算机上没有保存 AWS 配置集,请为您配置用于运行安装程序的用户输入 AWS 访问密钥 ID 和 secret 访问密钥。

        注意

        AWS 访问密钥 ID 和 secret 访问密钥存储在安装主机上当前用户主目录中的 ~/.aws/credentials 中。如果文件中不存在导出的配置集凭证,安装程序会提示您输入凭证。您向安装程序提供的所有凭证都存储在文件中。

      4. 选择要将集群部署到的 AWS 区域。
      5. 选择您为集群配置的 Route 53 服务的基域。
      6. 为集群输入描述性名称。
      7. 粘贴 Red Hat OpenShift Cluster Manager 中的 pull secret
  2. 可选:备份 install-config.yaml 文件。

    重要

    install-config.yaml 文件会在安装过程中消耗掉。如果要重复使用此文件,必须现在备份。

其他资源

6.13.8.3. 在安装过程中配置集群范围代理

生产环境可能会拒绝直接访问互联网,而是提供 HTTP 或 HTTPS 代理。您可以通过在 install-config.yaml 文件中配置代理设置,将新的 OpenShift Container Platform 集群配置为使用代理。

先决条件

  • 您有一个现有的 install-config.yaml 文件。
  • 您检查了集群需要访问的站点,并确定它们中的任何站点是否需要绕过代理。默认情况下,所有集群出口流量都经过代理,包括对托管云供应商 API 的调用。如果需要,您将在 Proxy 对象的 spec.noProxy 字段中添加站点来绕过代理。

    注意

    Proxy 对象 status.noProxy 字段使用安装配置中的 networking.machineNetwork[].cidrnetworking.clusterNetwork[].cidrnetworking.serviceNetwork[] 字段的值填充。

    对于在 Amazon Web Services(AWS)、Google Cloud Platform(GCP)、Microsoft Azure 和 Red Hat OpenStack Platform(RHOSP)上安装,Proxy 对象 status.noProxy 字段也会使用实例元数据端点填充(169.254.169.254)。

流程

  1. 编辑 install-config.yaml 文件并添加代理设置。例如:

    apiVersion: v1
    baseDomain: my.domain.com
    proxy:
      httpProxy: http://<username>:<pswd>@<ip>:<port> 1
      httpsProxy: https://<username>:<pswd>@<ip>:<port> 2
      noProxy: ec2.<aws_region>.amazonaws.com,elasticloadbalancing.<aws_region>.amazonaws.com,s3.<aws_region>.amazonaws.com 3
    additionalTrustBundle: | 4
        -----BEGIN CERTIFICATE-----
        <MY_TRUSTED_CA_CERT>
        -----END CERTIFICATE-----
    additionalTrustBundlePolicy: <policy_to_add_additionalTrustBundle> 5
    1
    用于创建集群外 HTTP 连接的代理 URL。URL 方案必须是 http
    2
    用于创建集群外 HTTPS 连接的代理 URL。
    3
    要从代理中排除的目标域名、IP 地址或其他网络 CIDR 的逗号分隔列表。在域前面加上 . 以仅匹配子域。例如,.y.com 匹配 x.y.com,但不匹配 y.com。使用 * 绕过所有目的地的代理。如果您已将 Amazon EC2Elastic Load BalancingS3 VPC 端点添加到 VPC 中,您必须将这些端点添加到 noProxy 字段。
    4
    如果提供,安装程序会在 openshift-config 命名空间中生成名为 user-ca-bundle 的配置映射,其包含代理 HTTPS 连接所需的一个或多个额外 CA 证书。然后,Cluster Network Operator 会创建 trusted-ca-bundle 配置映射,将这些内容与 Red Hat Enterprise Linux CoreOS(RHCOS)信任捆绑包合并, Proxy 对象的 trustedCA 字段中也会引用此配置映射。additionalTrustBundle 字段是必需的,除非代理的身份证书由来自 RHCOS 信任捆绑包的颁发机构签名。
    5
    可选:决定 Proxy 对象的配置以引用 trustedCA 字段中 user-ca-bundle 配置映射的策略。允许的值是 ProxyonlyAlways。仅在配置了 http/https 代理时,使用 Proxyonly 引用 user-ca-bundle 配置映射。使用 Always 始终引用 user-ca-bundle 配置映射。默认值为 Proxyonly
    注意

    安装程序不支持代理的 readinessEndpoints 字段。

    注意

    如果安装程序超时,重启并使用安装程序的 wait-for 命令完成部署。例如:

    $ ./openshift-install wait-for install-complete --log-level debug
  2. 保存该文件并在安装 OpenShift Container Platform 时引用。

安装程序会创建一个名为 cluster 的集群范围代理,该代理 使用 提供的 install-config.yaml 文件中的代理设置。如果没有提供代理设置,仍然会创建一个 cluster Proxy 对象,但它会有一个空 spec

注意

只支持名为 clusterProxy 对象,且无法创建额外的代理。

6.13.8.4. 创建 Kubernetes 清单和 Ignition 配置文件

由于您必须修改一些集群定义文件并手动启动集群机器,因此您必须生成 Kubernetes 清单和 Ignition 配置文件来配置机器。

安装配置文件转换为 Kubernetes 清单。清单嵌套到 Ignition 配置文件中,稍后用于配置集群机器。

重要
  • OpenShift Container Platform 安装程序生成的 Ignition 配置文件包含 24 小时后过期的证书,然后在该时进行续订。如果在更新证书前关闭集群,且集群在 24 小时后重启,集群会自动恢复过期的证书。一个例外是,您必须手动批准待处理的 node-bootstrapper 证书签名请求(CSR)来恢复 kubelet 证书。如需更多信息,请参阅从过期的 control plane 证书 中恢复的文档。
  • 建议您在 Ignition 配置文件生成后的 12 小时内使用它们,因为 24 小时的证书会在集群安装后的 16 小时到 22 小时间进行轮转。通过在 12 小时内使用 Ignition 配置文件,您可以避免在安装过程中因为执行了证书更新而导致安装失败的问题。

先决条件

  • 已获得 OpenShift Container Platform 安装程序。
  • 已创建 install-config.yaml 安装配置文件。

流程

  1. 进入包含 OpenShift Container Platform 安装程序的目录,并为集群生成 Kubernetes 清单:

    $ ./openshift-install create manifests --dir <installation_directory> 1
    1
    对于 <installation_directory>,请指定包含您创建的 install-config.yaml 文件的安装目录。
  2. 删除定义 control plane 机器的 Kubernetes 清单文件:

    $ rm -f <installation_directory>/openshift/99_openshift-cluster-api_master-machines-*.yaml

    通过删除这些文件,您可以防止集群自动生成 control plane 机器。

  3. 删除定义 control plane 机器集的 Kubernetes 清单文件:

    $ rm -f <installation_directory>/openshift/99_openshift-machine-api_master-control-plane-machine-set.yaml
    $ rm -f <installation_directory>/openshift/99_openshift-cluster-api_worker-machineset-*.yaml

    由于您要自行创建和管理 worker 机器,因此不需要初始化这些机器。

  4. 检查 <installation_directory>/manifests/cluster-scheduler-02-config.yml Kubernetes 清单文件中的 mastersSchedulable 参数是否已设置为 false。此设置可防止在 control plane 机器上调度 pod:

    1. 打开 <installation_directory>/manifests/cluster-scheduler-02-config.yml 文件。
    2. 找到 mastersSchedulable 参数,并确保它被设置为 false
    3. 保存并退出 文件。
  5. 可选:如果您不希望 Ingress Operator 代表您创建 DNS 记录,请删除 <installation_directory>/manifests/cluster-dns-02-config.yml DNS 配置文件中的 privateZone 和 publicZone 部分:

    apiVersion: config.openshift.io/v1
    kind: DNS
    metadata:
      creationTimestamp: null
      name: cluster
    spec:
      baseDomain: example.openshift.com
      privateZone: 1
        id: mycluster-100419-private-zone
      publicZone: 2
        id: example.openshift.com
    status: {}
    1 2
    完全删除此部分。

    如果这样做,您必须在后续步骤中手动添加入口 DNS 记录。

  6. 可选: 如果手动创建云身份和访问管理(IAM)角色,请运行以下命令在发行镜像中找到带有 TechPreviewNoUpgrade 注解的任何 CredentialsRequest 对象:

    $ oc adm release extract quay.io/openshift-release-dev/ocp-release:4.y.z-x86_64 --credentials-requests --cloud=<platform_name>

    输出示例

    0000_30_capi-operator_00_credentials-request.yaml:  release.openshift.io/feature-set: TechPreviewNoUpgrade

    重要

    发行镜像包含通过 TechPreviewNoUpgrade 功能集启用的技术预览功能的 CredentialsRequest 对象。您可以使用 release.openshift.io/feature-set: TechPreviewNoUpgrade 注解来识别这些对象。

    • 如果不使用这些功能,请不要为这些对象创建 secret。为不使用的技术预览功能创建 secret 可能会导致安装失败。
    • 如果使用这些功能,必须为对应的对象创建 secret。
    1. 删除具有 TechPreviewNoUpgrade 注解的所有 CredentialsRequest 对象。
  7. 要创建 Ignition 配置文件,请从包含安装程序的目录运行以下命令:

    $ ./openshift-install create ignition-configs --dir <installation_directory> 1
    1
    对于 <installation_directory>,请指定相同的安装目录。

    为安装目录中的 bootstrap、control plane 和计算节点创建 Ignition 配置文件。kubeadmin-passwordkubeconfig 文件在 ./<installation_directory>/auth 目录中创建:

    .
    ├── auth
    │   ├── kubeadmin-password
    │   └── kubeconfig
    ├── bootstrap.ign
    ├── master.ign
    ├── metadata.json
    └── worker.ign

6.13.9. 提取基础架构名称

Ignition 配置文件包含一个唯一集群标识符,您可以使用它在 Amazon Web Services (AWS) 中唯一地标识您的集群。基础架构名称还用于在 OpenShift Container Platform 安装过程中定位适当的 AWS 资源。提供的 CloudFormation 模板包含对此基础架构名称的引用,因此您必须提取它。

先决条件

  • 已获取 OpenShift Container Platform 安装程序和集群的 pull secret。
  • 已为集群生成 Ignition 配置文件。
  • 已安装 jq 软件包。

流程

  • 要从 Ignition 配置文件元数据中提取和查看基础架构名称,请运行以下命令:

    $ jq -r .infraID <installation_directory>/metadata.json 1
    1
    对于 <installation_directory>,请指定安装文件保存到的目录的路径。

    输出示例

    openshift-vw9j6 1

    1
    此命令的输出是您的集群名称和随机字符串。

6.13.10. 在 AWS 中创建 VPC

您必须在 Amazon Web Services(AWS)中创建 Virtual Private Cloud(VPC),供您的 OpenShift Container Platform 集群使用。您可以自定义 VPC 来满足您的要求,包括 VPN 和路由表。

您可以使用提供的 CloudFormation 模板和自定义参数文件创建代表 VPC 的 AWS 资源堆栈。

注意

如果不使用提供的 CloudFormation 模板来创建 AWS 基础架构,您必须检查提供的信息并手动创建基础架构。如果集群没有正确初始化,您可能需要联系红帽支持并提供您的安装日志。

先决条件

  • 已配置了一个 AWS 帐户。
  • 您可以通过运行 aws configure,将 AWS 密钥和区域添加到本地 AWS 配置集中。
  • 已为集群生成 Ignition 配置文件。

流程

  1. 创建一个 JSON 文件,其包含模板所需的参数值:

    [
      {
        "ParameterKey": "VpcCidr", 1
        "ParameterValue": "10.0.0.0/16" 2
      },
      {
        "ParameterKey": "AvailabilityZoneCount", 3
        "ParameterValue": "1" 4
      },
      {
        "ParameterKey": "SubnetBits", 5
        "ParameterValue": "12" 6
      }
    ]
    1
    VPC 的 CIDR 块。
    2
    x.x.x.x/16-24 格式指定 CIDR 块。
    3
    在其中部署 VPC 的可用区的数量。
    4
    指定一个 13 之间的整数。
    5
    各个可用区中每个子网的大小。
    6
    指定 513 之间的整数,其中 5/2713/19
  2. 复制本主题的 VPC 的 CloudFormation 模板部分中的模板,并将它以 YAML 文件形式保存到计算机上。此模板描述了集群所需的 VPC。
  3. 启动 CloudFormation 模板,以创建代表 VPC 的 AWS 资源堆栈:

    重要

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

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

    输出示例

    arn:aws:cloudformation:us-east-1:269333783861:stack/cluster-vpc/dbedae40-2fd3-11eb-820e-12a48460849f

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

    $ aws cloudformation describe-stacks --stack-name <name>

    StackStatus 显示 CREATE_COMPLETE 后,输出会显示以下参数的值。您必须将这些参数值提供给您在创建集群时要运行的其他 CloudFormation 模板:

    VpcId

    您的 VPC ID。

    PublicSubnetIds

    新公共子网的 ID。

    PrivateSubnetIds

    新专用子网的 ID。

6.13.10.1. VPC 的 CloudFormation 模板

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

例 6.44. 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"]]
      ]

其他资源

6.13.11. 在 AWS 中创建网络和负载均衡组件

您必须在 OpenShift Container Platform 集群可以使用的 Amazon Web Services(AWS)中配置网络、经典或网络负载均衡。

您可以使用提供的 CloudFormation 模板和自定义参数文件来创建 AWS 资源堆栈。堆栈代表 OpenShift Container Platform 集群所需的网络和负载均衡组件。该模板还创建一个托管区和子网标签。

您可以在单一虚拟私有云(VPC)内多次运行该模板。

注意

如果不使用提供的 CloudFormation 模板来创建 AWS 基础架构,您必须检查提供的信息并手动创建基础架构。如果集群没有正确初始化,您可能需要联系红帽支持并提供您的安装日志。

先决条件

  • 已配置了一个 AWS 帐户。
  • 您可以通过运行 aws configure,将 AWS 密钥和区域添加到本地 AWS 配置集中。
  • 已为集群生成 Ignition 配置文件。
  • 您在 AWS 中创建并配置了 VPC 及相关子网。

流程

  1. 获取您在 install-config.yaml 文件中为集群指定的 Route 53 基域的托管区 ID。您可以运行以下命令来获取托管区的详细信息:

    $ aws route53 list-hosted-zones-by-name --dns-name <route53_domain> 1
    1
    对于 <route53_domain>,请指定您为集群生成 install-config.yaml 文件时所用的 Route53 基域。

    输出示例

    mycluster.example.com.	False	100
    HOSTEDZONES	65F8F38E-2268-B835-E15C-AB55336FCBFA	/hostedzone/Z21IXYZABCZ2A4	mycluster.example.com.	10

    在示例输出中,托管区 ID 为 Z21IXYZABCZ2A4

  2. 创建一个 JSON 文件,其包含模板所需的参数值:

    [
      {
        "ParameterKey": "ClusterName", 1
        "ParameterValue": "mycluster" 2
      },
      {
        "ParameterKey": "InfrastructureName", 3
        "ParameterValue": "mycluster-<random_string>" 4
      },
      {
        "ParameterKey": "HostedZoneId", 5
        "ParameterValue": "<random_string>" 6
      },
      {
        "ParameterKey": "HostedZoneName", 7
        "ParameterValue": "example.com" 8
      },
      {
        "ParameterKey": "PublicSubnets", 9
        "ParameterValue": "subnet-<random_string>" 10
      },
      {
        "ParameterKey": "PrivateSubnets", 11
        "ParameterValue": "subnet-<random_string>" 12
      },
      {
        "ParameterKey": "VpcId", 13
        "ParameterValue": "vpc-<random_string>" 14
      }
    ]
    1
    一个简短的、代表集群的名称用于主机名等。
    2
    指定您为集群生成 install-config.yaml 文件时所用的集群名称。
    3
    您的 Ignition 配置文件中为集群编码的集群基础架构名称。
    4
    指定从 Ignition 配置文件元数据中提取的基础架构名称,其格式为 <cluster-name>-<random-string>
    5
    用来注册目标的 Route 53 公共区 ID。
    6
    指定 Route 53 公共区 ID,其格式与 Z21IXYZABCZ2A4 类似。您可以从 AWS 控制台获取这个值。
    7
    用来注册目标的 Route 53 区。
    8
    指定您为集群生成 install-config.yaml 文件时所用的 Route 53 基域。请勿包含 AWS 控制台中显示的结尾句点 (.)。
    9
    为 VPC 创建的公共子网。
    10
    指定 VPC 的 CloudFormation 模板输出的 PublicSubnetIds 值。
    11
    为 VPC 创建的专用子网。
    12
    指定 VPC 的 CloudFormation 模板输出的 PrivateSubnetIds 值。
    13
    为集群创建的 VPC。
    14
    指定 VPC 的 CloudFormation 模板输出的 VpcId 值。
  3. 复制本主题的网络和负载均衡器的 CloudFormation 模板部分中的模板,并将它以 YAML 文件形式保存到计算机上。此模板描述了集群所需的网络和负载均衡对象。

    重要

    如果要将集群部署到 AWS 政府或 secret 区域,您必须更新 CloudFormation 模板中的 InternalApiServerRecord,以使用 CNAME 记录。AWS 政府区不支持 ALIAS 类型的记录。

  4. 启动 CloudFormation 模板,以创建 AWS 资源堆栈,该堆栈提供网络和负载均衡组件:

    重要

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

    $ aws cloudformation create-stack --stack-name <name> 1
         --template-body file://<template>.yaml 2
         --parameters file://<parameters>.json 3
         --capabilities CAPABILITY_NAMED_IAM 4
    1
    <name> 是 CloudFormation 堆栈的名称,如 cluster-dns。如果您删除集群,则需要此堆栈的名称。
    2
    <template> 是您保存的 CloudFormation 模板 YAML 文件的相对路径和名称。
    3
    <parameters> 是 CloudFormation 参数 JSON 文件的相对路径和名称。
    4
    您必须明确声明 CAPABILITY_NAMED_IAM 功能,因为提供的模板会创建一些 AWS::IAM::Role 资源。

    输出示例

    arn:aws:cloudformation:us-east-1:269333783861:stack/cluster-dns/cd3e5de0-2fd4-11eb-5cf0-12be5c33a183

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

    $ aws cloudformation describe-stacks --stack-name <name>

    StackStatus 显示 CREATE_COMPLETE 后,输出会显示以下参数的值。您必须将这些参数值提供给您在创建集群时要运行的其他 CloudFormation 模板:

    PrivateHostedZoneId

    专用 DNS 的托管区 ID。

    ExternalApiLoadBalancerName

    外部 API 负载均衡器的完整名称。

    InternalApiLoadBalancerName

    内部 API 负载均衡器的完整名称。

    ApiServerDnsName

    API 服务器的完整主机名。

    RegisterNlbIpTargetsLambda

    有助于为这些负载均衡器注册/撤销注册 IP 目标的 Lambda ARN。

    ExternalApiTargetGroupArn

    外部 API 目标组的 ARN。

    InternalApiTargetGroupArn

    内部 API 目标组的 ARN。

    InternalServiceTargetGroupArn

    内部服务目标组群的 ARN。

6.13.11.1. 网络和负载均衡器的 CloudFormation 模板

您可以使用以下 CloudFormation 模板来部署 OpenShift Container Platform 集群所需的网络对象和负载均衡器。

例 6.45. 网络和负载均衡器的 CloudFormation 模板

AWSTemplateFormatVersion: 2010-09-09
Description: Template for OpenShift Cluster Network Elements (Route53 & LBs)

Parameters:
  ClusterName:
    AllowedPattern: ^([a-zA-Z][a-zA-Z0-9\-]{0,26})$
    MaxLength: 27
    MinLength: 1
    ConstraintDescription: Cluster name must be alphanumeric, start with a letter, and have a maximum of 27 characters.
    Description: A short, representative cluster name to use for host names and other identifying names.
    Type: String
  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 cloud resources and identify items owned or used by the cluster.
    Type: String
  HostedZoneId:
    Description: The Route53 public zone ID to register the targets with, such as Z21IXYZABCZ2A4.
    Type: String
  HostedZoneName:
    Description: The Route53 zone to register the targets with, such as example.com. Omit the trailing period.
    Type: String
    Default: "example.com"
  PublicSubnets:
    Description: The internet-facing subnets.
    Type: List<AWS::EC2::Subnet::Id>
  PrivateSubnets:
    Description: The internal subnets.
    Type: List<AWS::EC2::Subnet::Id>
  VpcId:
    Description: The VPC-scoped resources will belong to this VPC.
    Type: AWS::EC2::VPC::Id

Metadata:
  AWS::CloudFormation::Interface:
    ParameterGroups:
    - Label:
        default: "Cluster Information"
      Parameters:
      - ClusterName
      - InfrastructureName
    - Label:
        default: "Network Configuration"
      Parameters:
      - VpcId
      - PublicSubnets
      - PrivateSubnets
    - Label:
        default: "DNS"
      Parameters:
      - HostedZoneName
      - HostedZoneId
    ParameterLabels:
      ClusterName:
        default: "Cluster Name"
      InfrastructureName:
        default: "Infrastructure Name"
      VpcId:
        default: "VPC ID"
      PublicSubnets:
        default: "Public Subnets"
      PrivateSubnets:
        default: "Private Subnets"
      HostedZoneName:
        default: "Public Hosted Zone Name"
      HostedZoneId:
        default: "Public Hosted Zone ID"

Resources:
  ExtApiElb:
    Type: AWS::ElasticLoadBalancingV2::LoadBalancer
    Properties:
      Name: !Join ["-", [!Ref InfrastructureName, "ext"]]
      IpAddressType: ipv4
      Subnets: !Ref PublicSubnets
      Type: network

  IntApiElb:
    Type: AWS::ElasticLoadBalancingV2::LoadBalancer
    Properties:
      Name: !Join ["-", [!Ref InfrastructureName, "int"]]
      Scheme: internal
      IpAddressType: ipv4
      Subnets: !Ref PrivateSubnets
      Type: network

  IntDns:
    Type: "AWS::Route53::HostedZone"
    Properties:
      HostedZoneConfig:
        Comment: "Managed by CloudFormation"
      Name: !Join [".", [!Ref ClusterName, !Ref HostedZoneName]]
      HostedZoneTags:
      - Key: Name
        Value: !Join ["-", [!Ref InfrastructureName, "int"]]
      - Key: !Join ["", ["kubernetes.io/cluster/", !Ref InfrastructureName]]
        Value: "owned"
      VPCs:
      - VPCId: !Ref VpcId
        VPCRegion: !Ref "AWS::Region"

  ExternalApiServerRecord:
    Type: AWS::Route53::RecordSetGroup
    Properties:
      Comment: Alias record for the API server
      HostedZoneId: !Ref HostedZoneId
      RecordSets:
      - Name:
          !Join [
            ".",
            ["api", !Ref ClusterName, !Join ["", [!Ref HostedZoneName, "."]]],
          ]
        Type: A
        AliasTarget:
          HostedZoneId: !GetAtt ExtApiElb.CanonicalHostedZoneID
          DNSName: !GetAtt ExtApiElb.DNSName

  InternalApiServerRecord:
    Type: AWS::Route53::RecordSetGroup
    Properties:
      Comment: Alias record for the API server
      HostedZoneId: !Ref IntDns
      RecordSets:
      - Name:
          !Join [
            ".",
            ["api", !Ref ClusterName, !Join ["", [!Ref HostedZoneName, "."]]],
          ]
        Type: A
        AliasTarget:
          HostedZoneId: !GetAtt IntApiElb.CanonicalHostedZoneID
          DNSName: !GetAtt IntApiElb.DNSName
      - Name:
          !Join [
            ".",
            ["api-int", !Ref ClusterName, !Join ["", [!Ref HostedZoneName, "."]]],
          ]
        Type: A
        AliasTarget:
          HostedZoneId: !GetAtt IntApiElb.CanonicalHostedZoneID
          DNSName: !GetAtt IntApiElb.DNSName

  ExternalApiListener:
    Type: AWS::ElasticLoadBalancingV2::Listener
    Properties:
      DefaultActions:
      - Type: forward
        TargetGroupArn:
          Ref: ExternalApiTargetGroup
      LoadBalancerArn:
        Ref: ExtApiElb
      Port: 6443
      Protocol: TCP

  ExternalApiTargetGroup:
    Type: AWS::ElasticLoadBalancingV2::TargetGroup
    Properties:
      HealthCheckIntervalSeconds: 10
      HealthCheckPath: "/readyz"
      HealthCheckPort: 6443
      HealthCheckProtocol: HTTPS
      HealthyThresholdCount: 2
      UnhealthyThresholdCount: 2
      Port: 6443
      Protocol: TCP
      TargetType: ip
      VpcId:
        Ref: VpcId
      TargetGroupAttributes:
      - Key: deregistration_delay.timeout_seconds
        Value: 60

  InternalApiListener:
    Type: AWS::ElasticLoadBalancingV2::Listener
    Properties:
      DefaultActions:
      - Type: forward
        TargetGroupArn:
          Ref: InternalApiTargetGroup
      LoadBalancerArn:
        Ref: IntApiElb
      Port: 6443
      Protocol: TCP

  InternalApiTargetGroup:
    Type: AWS::ElasticLoadBalancingV2::TargetGroup
    Properties:
      HealthCheckIntervalSeconds: 10
      HealthCheckPath: "/readyz"
      HealthCheckPort: 6443
      HealthCheckProtocol: HTTPS
      HealthyThresholdCount: 2
      UnhealthyThresholdCount: 2
      Port: 6443
      Protocol: TCP
      TargetType: ip
      VpcId:
        Ref: VpcId
      TargetGroupAttributes:
      - Key: deregistration_delay.timeout_seconds
        Value: 60

  InternalServiceInternalListener:
    Type: AWS::ElasticLoadBalancingV2::Listener
    Properties:
      DefaultActions:
      - Type: forward
        TargetGroupArn:
          Ref: InternalServiceTargetGroup
      LoadBalancerArn:
        Ref: IntApiElb
      Port: 22623
      Protocol: TCP

  InternalServiceTargetGroup:
    Type: AWS::ElasticLoadBalancingV2::TargetGroup
    Properties:
      HealthCheckIntervalSeconds: 10
      HealthCheckPath: "/healthz"
      HealthCheckPort: 22623
      HealthCheckProtocol: HTTPS
      HealthyThresholdCount: 2
      UnhealthyThresholdCount: 2
      Port: 22623
      Protocol: TCP
      TargetType: ip
      VpcId:
        Ref: VpcId
      TargetGroupAttributes:
      - Key: deregistration_delay.timeout_seconds
        Value: 60

  RegisterTargetLambdaIamRole:
    Type: AWS::IAM::Role
    Properties:
      RoleName: !Join ["-", [!Ref InfrastructureName, "nlb", "lambda", "role"]]
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
        - Effect: "Allow"
          Principal:
            Service:
            - "lambda.amazonaws.com"
          Action:
          - "sts:AssumeRole"
      Path: "/"
      Policies:
      - PolicyName: !Join ["-", [!Ref InfrastructureName, "master", "policy"]]
        PolicyDocument:
          Version: "2012-10-17"
          Statement:
          - Effect: "Allow"
            Action:
              [
                "elasticloadbalancing:RegisterTargets",
                "elasticloadbalancing:DeregisterTargets",
              ]
            Resource: !Ref InternalApiTargetGroup
          - Effect: "Allow"
            Action:
              [
                "elasticloadbalancing:RegisterTargets",
                "elasticloadbalancing:DeregisterTargets",
              ]
            Resource: !Ref InternalServiceTargetGroup
          - Effect: "Allow"
            Action:
              [
                "elasticloadbalancing:RegisterTargets",
                "elasticloadbalancing:DeregisterTargets",
              ]
            Resource: !Ref ExternalApiTargetGroup

  RegisterNlbIpTargets:
    Type: "AWS::Lambda::Function"
    Properties:
      Handler: "index.handler"
      Role:
        Fn::GetAtt:
        - "RegisterTargetLambdaIamRole"
        - "Arn"
      Code:
        ZipFile: |
          import json
          import boto3
          import cfnresponse
          def handler(event, context):
            elb = boto3.client('elbv2')
            if event['RequestType'] == 'Delete':
              elb.deregister_targets(TargetGroupArn=event['ResourceProperties']['TargetArn'],Targets=[{'Id': event['ResourceProperties']['TargetIp']}])
            elif event['RequestType'] == 'Create':
              elb.register_targets(TargetGroupArn=event['ResourceProperties']['TargetArn'],Targets=[{'Id': event['ResourceProperties']['TargetIp']}])
            responseData = {}
            cfnresponse.send(event, context, cfnresponse.SUCCESS, responseData, event['ResourceProperties']['TargetArn']+event['ResourceProperties']['TargetIp'])
      Runtime: "python3.8"
      Timeout: 120

  RegisterSubnetTagsLambdaIamRole:
    Type: AWS::IAM::Role
    Properties:
      RoleName: !Join ["-", [!Ref InfrastructureName, "subnet-tags-lambda-role"]]
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
        - Effect: "Allow"
          Principal:
            Service:
            - "lambda.amazonaws.com"
          Action:
          - "sts:AssumeRole"
      Path: "/"
      Policies:
      - PolicyName: !Join ["-", [!Ref InfrastructureName, "subnet-tagging-policy"]]
        PolicyDocument:
          Version: "2012-10-17"
          Statement:
          - Effect: "Allow"
            Action:
              [
                "ec2:DeleteTags",
                "ec2:CreateTags"
              ]
            Resource: "arn:aws:ec2:*:*:subnet/*"
          - Effect: "Allow"
            Action:
              [
                "ec2:DescribeSubnets",
                "ec2:DescribeTags"
              ]
            Resource: "*"

  RegisterSubnetTags:
    Type: "AWS::Lambda::Function"
    Properties:
      Handler: "index.handler"
      Role:
        Fn::GetAtt:
        - "RegisterSubnetTagsLambdaIamRole"
        - "Arn"
      Code:
        ZipFile: |
          import json
          import boto3
          import cfnresponse
          def handler(event, context):
            ec2_client = boto3.client('ec2')
            if event['RequestType'] == 'Delete':
              for subnet_id in event['ResourceProperties']['Subnets']:
                ec2_client.delete_tags(Resources=[subnet_id], Tags=[{'Key': 'kubernetes.io/cluster/' + event['ResourceProperties']['InfrastructureName']}]);
            elif event['RequestType'] == 'Create':
              for subnet_id in event['ResourceProperties']['Subnets']:
                ec2_client.create_tags(Resources=[subnet_id], Tags=[{'Key': 'kubernetes.io/cluster/' + event['ResourceProperties']['InfrastructureName'], 'Value': 'shared'}]);
            responseData = {}
            cfnresponse.send(event, context, cfnresponse.SUCCESS, responseData, event['ResourceProperties']['InfrastructureName']+event['ResourceProperties']['Subnets'][0])
      Runtime: "python3.8"
      Timeout: 120

  RegisterPublicSubnetTags:
    Type: Custom::SubnetRegister
    Properties:
      ServiceToken: !GetAtt RegisterSubnetTags.Arn
      InfrastructureName: !Ref InfrastructureName
      Subnets: !Ref PublicSubnets

  RegisterPrivateSubnetTags:
    Type: Custom::SubnetRegister
    Properties:
      ServiceToken: !GetAtt RegisterSubnetTags.Arn
      InfrastructureName: !Ref InfrastructureName
      Subnets: !Ref PrivateSubnets

Outputs:
  PrivateHostedZoneId:
    Description: Hosted zone ID for the private DNS, which is required for private records.
    Value: !Ref IntDns
  ExternalApiLoadBalancerName:
    Description: Full name of the external API load balancer.
    Value: !GetAtt ExtApiElb.LoadBalancerFullName
  InternalApiLoadBalancerName:
    Description: Full name of the internal API load balancer.
    Value: !GetAtt IntApiElb.LoadBalancerFullName
  ApiServerDnsName:
    Description: Full hostname of the API server, which is required for the Ignition config files.
    Value: !Join [".", ["api-int", !Ref ClusterName, !Ref HostedZoneName]]
  RegisterNlbIpTargetsLambda:
    Description: Lambda ARN useful to help register or deregister IP targets for these load balancers.
    Value: !GetAtt RegisterNlbIpTargets.Arn
  ExternalApiTargetGroupArn:
    Description: ARN of the external API target group.
    Value: !Ref ExternalApiTargetGroup
  InternalApiTargetGroupArn:
    Description: ARN of the internal API target group.
    Value: !Ref InternalApiTargetGroup
  InternalServiceTargetGroupArn:
    Description: ARN of the internal service target group.
    Value: !Ref InternalServiceTargetGroup
重要

如果要将集群部署到 AWS 政府或 secret 区域,您必须更新 InternalApiServerRecord 以使用 CNAME 记录。AWS 政府区不支持 ALIAS 类型的记录。例如:

Type: CNAME
TTL: 10
ResourceRecords:
- !GetAtt IntApiElb.DNSName

其他资源

6.13.12. 在 AWS 中创建安全组和角色

您必须在 Amazon Web Services (AWS) 中创建安全组和角色,供您的 OpenShift Container Platform 集群使用。

您可以使用提供的 CloudFormation 模板和自定义参数文件来创建 AWS 资源堆栈。堆栈代表 OpenShift Container Platform 集群所需的安全组和角色。

注意

如果不使用提供的 CloudFormation 模板来创建 AWS 基础架构,您必须检查提供的信息并手动创建基础架构。如果集群没有正确初始化,您可能需要联系红帽支持并提供您的安装日志。

先决条件

  • 已配置了一个 AWS 帐户。
  • 您可以通过运行 aws configure,将 AWS 密钥和区域添加到本地 AWS 配置集中。
  • 已为集群生成 Ignition 配置文件。
  • 您在 AWS 中创建并配置了 VPC 及相关子网。

流程

  1. 创建一个 JSON 文件,其包含模板所需的参数值:

    [
      {
        "ParameterKey": "InfrastructureName", 1
        "ParameterValue": "mycluster-<random_string>" 2
      },
      {
        "ParameterKey": "VpcCidr", 3
        "ParameterValue": "10.0.0.0/16" 4
      },
      {
        "ParameterKey": "PrivateSubnets", 5
        "ParameterValue": "subnet-<random_string>" 6
      },
      {
        "ParameterKey": "VpcId", 7
        "ParameterValue": "vpc-<random_string>" 8
      }
    ]
    1
    您的 Ignition 配置文件中为集群编码的集群基础架构名称。
    2
    指定从 Ignition 配置文件元数据中提取的基础架构名称,其格式为 <cluster-name>-<random-string>
    3
    VPC 的 CIDR 块。
    4
    指定以 x.x.x.x/16-24 格式定义的用于 VPC 的 CIDR 地址块。
    5
    为 VPC 创建的专用子网。
    6
    指定 VPC 的 CloudFormation 模板输出的 PrivateSubnetIds 值。
    7
    为集群创建的 VPC。
    8
    指定 VPC 的 CloudFormation 模板输出的 VpcId 值。
  2. 复制本主题的安全对象的 CloudFormation 模板部分中的模板,并将它以 YAML 文件形式保存到计算机上。此模板描述了集群所需的安全组和角色。
  3. 启动 CloudFormation 模板,以创建代表安全组和角色的 AWS 资源堆栈:

    重要

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

    $ aws cloudformation create-stack --stack-name <name> 1
         --template-body file://<template>.yaml 2
         --parameters file://<parameters>.json 3
         --capabilities CAPABILITY_NAMED_IAM 4
    1
    <name> 是 CloudFormation 堆栈的名称,如 cluster-sec。如果您删除集群,则需要此堆栈的名称。
    2
    <template> 是您保存的 CloudFormation 模板 YAML 文件的相对路径和名称。
    3
    <parameters> 是 CloudFormation 参数 JSON 文件的相对路径和名称。
    4
    您必须明确声明 CAPABILITY_NAMED_IAM 功能,因为提供的模板会创建一些 AWS::IAM::RoleAWS::IAM::InstanceProfile 资源。

    输出示例

    arn:aws:cloudformation:us-east-1:269333783861:stack/cluster-sec/03bd4210-2ed7-11eb-6d7a-13fc0b61e9db

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

    $ aws cloudformation describe-stacks --stack-name <name>

    StackStatus 显示 CREATE_COMPLETE 后,输出会显示以下参数的值。您必须将这些参数值提供给您在创建集群时要运行的其他 CloudFormation 模板:

    MasterSecurityGroupId

    Master 安全组 ID

    WorkerSecurityGroupId

    worker 安全组 ID

    MasterInstanceProfile

    Master IAM 实例配置集

    WorkerInstanceProfile

    worker IAM 实例配置集

6.13.12.1. 安全对象的 CloudFormation 模板

您可以使用以下 CloudFormation 模板来部署 OpenShift Container Platform 集群所需的安全对象。

例 6.46. 安全对象的 CloudFormation 模板

AWSTemplateFormatVersion: 2010-09-09
Description: Template for OpenShift Cluster Security Elements (Security Groups & IAM)

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 cloud resources and identify items owned or used by the cluster.
    Type: String
  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
  VpcId:
    Description: The VPC-scoped resources will belong to this VPC.
    Type: AWS::EC2::VPC::Id
  PrivateSubnets:
    Description: The internal subnets.
    Type: List<AWS::EC2::Subnet::Id>

Metadata:
  AWS::CloudFormation::Interface:
    ParameterGroups:
    - Label:
        default: "Cluster Information"
      Parameters:
      - InfrastructureName
    - Label:
        default: "Network Configuration"
      Parameters:
      - VpcId
      - VpcCidr
      - PrivateSubnets
    ParameterLabels:
      InfrastructureName:
        default: "Infrastructure Name"
      VpcId:
        default: "VPC ID"
      VpcCidr:
        default: "VPC CIDR"
      PrivateSubnets:
        default: "Private Subnets"

Resources:
  MasterSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: Cluster Master Security Group
      SecurityGroupIngress:
      - IpProtocol: icmp
        FromPort: 0
        ToPort: 0
        CidrIp: !Ref VpcCidr
      - IpProtocol: tcp
        FromPort: 22
        ToPort: 22
        CidrIp: !Ref VpcCidr
      - IpProtocol: tcp
        ToPort: 6443
        FromPort: 6443
        CidrIp: !Ref VpcCidr
      - IpProtocol: tcp
        FromPort: 22623
        ToPort: 22623
        CidrIp: !Ref VpcCidr
      VpcId: !Ref VpcId

  WorkerSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: Cluster Worker Security Group
      SecurityGroupIngress:
      - IpProtocol: icmp
        FromPort: 0
        ToPort: 0
        CidrIp: !Ref VpcCidr
      - IpProtocol: tcp
        FromPort: 22
        ToPort: 22
        CidrIp: !Ref VpcCidr
      VpcId: !Ref VpcId

  MasterIngressEtcd:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt MasterSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt MasterSecurityGroup.GroupId
      Description: etcd
      FromPort: 2379
      ToPort: 2380
      IpProtocol: tcp

  MasterIngressVxlan:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt MasterSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt MasterSecurityGroup.GroupId
      Description: Vxlan packets
      FromPort: 4789
      ToPort: 4789
      IpProtocol: udp

  MasterIngressWorkerVxlan:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt MasterSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt WorkerSecurityGroup.GroupId
      Description: Vxlan packets
      FromPort: 4789
      ToPort: 4789
      IpProtocol: udp

  MasterIngressGeneve:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt MasterSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt MasterSecurityGroup.GroupId
      Description: Geneve packets
      FromPort: 6081
      ToPort: 6081
      IpProtocol: udp

  MasterIngressWorkerGeneve:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt MasterSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt WorkerSecurityGroup.GroupId
      Description: Geneve packets
      FromPort: 6081
      ToPort: 6081
      IpProtocol: udp

  MasterIngressIpsecIke:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt MasterSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt MasterSecurityGroup.GroupId
      Description: IPsec IKE packets
      FromPort: 500
      ToPort: 500
      IpProtocol: udp

  MasterIngressIpsecNat:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt MasterSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt MasterSecurityGroup.GroupId
      Description: IPsec NAT-T packets
      FromPort: 4500
      ToPort: 4500
      IpProtocol: udp

  MasterIngressIpsecEsp:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt MasterSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt MasterSecurityGroup.GroupId
      Description: IPsec ESP packets
      IpProtocol: 50

  MasterIngressWorkerIpsecIke:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt MasterSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt WorkerSecurityGroup.GroupId
      Description: IPsec IKE packets
      FromPort: 500
      ToPort: 500
      IpProtocol: udp

  MasterIngressWorkerIpsecNat:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt MasterSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt WorkerSecurityGroup.GroupId
      Description: IPsec NAT-T packets
      FromPort: 4500
      ToPort: 4500
      IpProtocol: udp

  MasterIngressWorkerIpsecEsp:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt MasterSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt WorkerSecurityGroup.GroupId
      Description: IPsec ESP packets
      IpProtocol: 50

  MasterIngressInternal:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt MasterSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt MasterSecurityGroup.GroupId
      Description: Internal cluster communication
      FromPort: 9000
      ToPort: 9999
      IpProtocol: tcp

  MasterIngressWorkerInternal:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt MasterSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt WorkerSecurityGroup.GroupId
      Description: Internal cluster communication
      FromPort: 9000
      ToPort: 9999
      IpProtocol: tcp

  MasterIngressInternalUDP:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt MasterSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt MasterSecurityGroup.GroupId
      Description: Internal cluster communication
      FromPort: 9000
      ToPort: 9999
      IpProtocol: udp

  MasterIngressWorkerInternalUDP:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt MasterSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt WorkerSecurityGroup.GroupId
      Description: Internal cluster communication
      FromPort: 9000
      ToPort: 9999
      IpProtocol: udp

  MasterIngressKube:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt MasterSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt MasterSecurityGroup.GroupId
      Description: Kubernetes kubelet, scheduler and controller manager
      FromPort: 10250
      ToPort: 10259
      IpProtocol: tcp

  MasterIngressWorkerKube:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt MasterSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt WorkerSecurityGroup.GroupId
      Description: Kubernetes kubelet, scheduler and controller manager
      FromPort: 10250
      ToPort: 10259
      IpProtocol: tcp

  MasterIngressIngressServices:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt MasterSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt MasterSecurityGroup.GroupId
      Description: Kubernetes ingress services
      FromPort: 30000
      ToPort: 32767
      IpProtocol: tcp

  MasterIngressWorkerIngressServices:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt MasterSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt WorkerSecurityGroup.GroupId
      Description: Kubernetes ingress services
      FromPort: 30000
      ToPort: 32767
      IpProtocol: tcp

  MasterIngressIngressServicesUDP:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt MasterSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt MasterSecurityGroup.GroupId
      Description: Kubernetes ingress services
      FromPort: 30000
      ToPort: 32767
      IpProtocol: udp

  MasterIngressWorkerIngressServicesUDP:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt MasterSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt WorkerSecurityGroup.GroupId
      Description: Kubernetes ingress services
      FromPort: 30000
      ToPort: 32767
      IpProtocol: udp

  WorkerIngressVxlan:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt WorkerSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt WorkerSecurityGroup.GroupId
      Description: Vxlan packets
      FromPort: 4789
      ToPort: 4789
      IpProtocol: udp

  WorkerIngressMasterVxlan:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt WorkerSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt MasterSecurityGroup.GroupId
      Description: Vxlan packets
      FromPort: 4789
      ToPort: 4789
      IpProtocol: udp

  WorkerIngressGeneve:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt WorkerSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt WorkerSecurityGroup.GroupId
      Description: Geneve packets
      FromPort: 6081
      ToPort: 6081
      IpProtocol: udp

  WorkerIngressMasterGeneve:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt WorkerSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt MasterSecurityGroup.GroupId
      Description: Geneve packets
      FromPort: 6081
      ToPort: 6081
      IpProtocol: udp

  WorkerIngressIpsecIke:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt WorkerSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt WorkerSecurityGroup.GroupId
      Description: IPsec IKE packets
      FromPort: 500
      ToPort: 500
      IpProtocol: udp

  WorkerIngressIpsecNat:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt WorkerSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt WorkerSecurityGroup.GroupId
      Description: IPsec NAT-T packets
      FromPort: 4500
      ToPort: 4500
      IpProtocol: udp

  WorkerIngressIpsecEsp:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt WorkerSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt WorkerSecurityGroup.GroupId
      Description: IPsec ESP packets
      IpProtocol: 50

  WorkerIngressMasterIpsecIke:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt WorkerSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt MasterSecurityGroup.GroupId
      Description: IPsec IKE packets
      FromPort: 500
      ToPort: 500
      IpProtocol: udp

  WorkerIngressMasterIpsecNat:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt WorkerSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt MasterSecurityGroup.GroupId
      Description: IPsec NAT-T packets
      FromPort: 4500
      ToPort: 4500
      IpProtocol: udp

  WorkerIngressMasterIpsecEsp:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt WorkerSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt MasterSecurityGroup.GroupId
      Description: IPsec ESP packets
      IpProtocol: 50

  WorkerIngressInternal:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt WorkerSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt WorkerSecurityGroup.GroupId
      Description: Internal cluster communication
      FromPort: 9000
      ToPort: 9999
      IpProtocol: tcp

  WorkerIngressMasterInternal:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt WorkerSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt MasterSecurityGroup.GroupId
      Description: Internal cluster communication
      FromPort: 9000
      ToPort: 9999
      IpProtocol: tcp

  WorkerIngressInternalUDP:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt WorkerSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt WorkerSecurityGroup.GroupId
      Description: Internal cluster communication
      FromPort: 9000
      ToPort: 9999
      IpProtocol: udp

  WorkerIngressMasterInternalUDP:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt WorkerSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt MasterSecurityGroup.GroupId
      Description: Internal cluster communication
      FromPort: 9000
      ToPort: 9999
      IpProtocol: udp

  WorkerIngressKube:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt WorkerSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt WorkerSecurityGroup.GroupId
      Description: Kubernetes secure kubelet port
      FromPort: 10250
      ToPort: 10250
      IpProtocol: tcp

  WorkerIngressWorkerKube:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt WorkerSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt MasterSecurityGroup.GroupId
      Description: Internal Kubernetes communication
      FromPort: 10250
      ToPort: 10250
      IpProtocol: tcp

  WorkerIngressIngressServices:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt WorkerSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt WorkerSecurityGroup.GroupId
      Description: Kubernetes ingress services
      FromPort: 30000
      ToPort: 32767
      IpProtocol: tcp

  WorkerIngressMasterIngressServices:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt WorkerSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt MasterSecurityGroup.GroupId
      Description: Kubernetes ingress services
      FromPort: 30000
      ToPort: 32767
      IpProtocol: tcp

  WorkerIngressIngressServicesUDP:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt WorkerSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt WorkerSecurityGroup.GroupId
      Description: Kubernetes ingress services
      FromPort: 30000
      ToPort: 32767
      IpProtocol: udp

  WorkerIngressMasterIngressServicesUDP:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !GetAtt WorkerSecurityGroup.GroupId
      SourceSecurityGroupId: !GetAtt MasterSecurityGroup.GroupId
      Description: Kubernetes ingress services
      FromPort: 30000
      ToPort: 32767
      IpProtocol: udp

  MasterIamRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
        - Effect: "Allow"
          Principal:
            Service:
            - "ec2.amazonaws.com"
          Action:
          - "sts:AssumeRole"
      Policies:
      - PolicyName: !Join ["-", [!Ref InfrastructureName, "master", "policy"]]
        PolicyDocument:
          Version: "2012-10-17"
          Statement:
          - Effect: "Allow"
            Action:
            - "ec2:AttachVolume"
            - "ec2:AuthorizeSecurityGroupIngress"
            - "ec2:CreateSecurityGroup"
            - "ec2:CreateTags"
            - "ec2:CreateVolume"
            - "ec2:DeleteSecurityGroup"
            - "ec2:DeleteVolume"
            - "ec2:Describe*"
            - "ec2:DetachVolume"
            - "ec2:ModifyInstanceAttribute"
            - "ec2:ModifyVolume"
            - "ec2:RevokeSecurityGroupIngress"
            - "elasticloadbalancing:AddTags"
            - "elasticloadbalancing:AttachLoadBalancerToSubnets"
            - "elasticloadbalancing:ApplySecurityGroupsToLoadBalancer"
            - "elasticloadbalancing:CreateListener"
            - "elasticloadbalancing:CreateLoadBalancer"
            - "elasticloadbalancing:CreateLoadBalancerPolicy"
            - "elasticloadbalancing:CreateLoadBalancerListeners"
            - "elasticloadbalancing:CreateTargetGroup"
            - "elasticloadbalancing:ConfigureHealthCheck"
            - "elasticloadbalancing:DeleteListener"
            - "elasticloadbalancing:DeleteLoadBalancer"
            - "elasticloadbalancing:DeleteLoadBalancerListeners"
            - "elasticloadbalancing:DeleteTargetGroup"
            - "elasticloadbalancing:DeregisterInstancesFromLoadBalancer"
            - "elasticloadbalancing:DeregisterTargets"
            - "elasticloadbalancing:Describe*"
            - "elasticloadbalancing:DetachLoadBalancerFromSubnets"
            - "elasticloadbalancing:ModifyListener"
            - "elasticloadbalancing:ModifyLoadBalancerAttributes"
            - "elasticloadbalancing:ModifyTargetGroup"
            - "elasticloadbalancing:ModifyTargetGroupAttributes"
            - "elasticloadbalancing:RegisterInstancesWithLoadBalancer"
            - "elasticloadbalancing:RegisterTargets"
            - "elasticloadbalancing:SetLoadBalancerPoliciesForBackendServer"
            - "elasticloadbalancing:SetLoadBalancerPoliciesOfListener"
            - "kms:DescribeKey"
            Resource: "*"

  MasterInstanceProfile:
    Type: "AWS::IAM::InstanceProfile"
    Properties:
      Roles:
      - Ref: "MasterIamRole"

  WorkerIamRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
        - Effect: "Allow"
          Principal:
            Service:
            - "ec2.amazonaws.com"
          Action:
          - "sts:AssumeRole"
      Policies:
      - PolicyName: !Join ["-", [!Ref InfrastructureName, "worker", "policy"]]
        PolicyDocument:
          Version: "2012-10-17"
          Statement:
          - Effect: "Allow"
            Action:
            - "ec2:DescribeInstances"
            - "ec2:DescribeRegions"
            Resource: "*"

  WorkerInstanceProfile:
    Type: "AWS::IAM::InstanceProfile"
    Properties:
      Roles:
      - Ref: "WorkerIamRole"

Outputs:
  MasterSecurityGroupId:
    Description: Master Security Group ID
    Value: !GetAtt MasterSecurityGroup.GroupId

  WorkerSecurityGroupId:
    Description: Worker Security Group ID
    Value: !GetAtt WorkerSecurityGroup.GroupId

  MasterInstanceProfile:
    Description: Master IAM Instance Profile
    Value: !Ref MasterInstanceProfile

  WorkerInstanceProfile:
    Description: Worker IAM Instance Profile
    Value: !Ref WorkerInstanceProfile

其他资源

6.13.13. 使用流元数据访问 RHCOS AMI

在 OpenShift Container Platform 中,流元数据以 JSON 格式提供与 RHCOS 相关的标准化元数据,并将元数据注入集群中。流元数据是一种稳定的格式,支持多种架构,旨在自我记录以维护自动化。

您可以使用 openshift-installcoreos print-stream-json 子命令访问流元数据格式的引导镜像的信息。此命令提供了一种以可脚本、机器可读格式打印流元数据的方法。

对于用户置备的安装,openshift-install 二进制文件包含对经过测试用于 OpenShift Container Platform 的 RHCOS 引导镜像版本的引用,如 AWS AMI。

流程

要解析流元数据,请使用以下方法之一:

  • 在 Go 程序中使用位于 https://github.com/coreos/stream-metadata-go 的正式 stream-metadata-go 库。您还可以查看库中的示例代码。
  • 在 Python 或 Ruby 等其他编程语言中使用您首选编程语言的 JSON 库。
  • 在处理 JSON 数据的命令行工具中,如 jq

    • 为 AWS 区域输出当前的 x86_64aarch64 AMI,如 us-west-1

      对于 x86_64

      $ openshift-install coreos print-stream-json | jq -r '.architectures.x86_64.images.aws.regions["us-west-1"].image'

      输出示例

      ami-0d3e625f84626bbda

      对于 aarch64

      $ openshift-install coreos print-stream-json | jq -r '.architectures.aarch64.images.aws.regions["us-west-1"].image'

      输出示例

      ami-0af1d3b7fa5be2131

      这个命令的输出是您指定的架构和 us-west-1 区域的 AWS AMI ID。AMI 必须与集群属于同一区域。

6.13.14. AWS 基础架构的 RHCOS AMI

红帽提供了对可手动为 OpenShift Container Platform 节点指定的各种 AWS 区域和实例架构有效的 Red Hat Enterprise Linux CoreOS(RHCOS)AMI。

注意

通过导入您自己的 AMI,您还可以安装到没有公布的 RHCOS AMI 的区域。

表 6.48. x86_64 RHCOS AMIs

AWS 区AWS AMI

af-south-1

ami-073850a7021953a5c

ap-east-1

ami-0f8800a05c09be42d

ap-northeast-1

ami-0a226dbcc9a561c40

ap-northeast-2

ami-041ae0537e2eddec1

ap-northeast-3

ami-0bb8d9b69dc5b7670

ap-south-1

ami-0e9c18058fc5f94fd

ap-southeast-1

ami-03022d358ba2168be

ap-southeast-2

ami-09ffdc5be9b973be0

ap-southeast-3

ami-0facf1a0edeb20314

ca-central-1

ami-028cea206c2d03317

eu-central-1

ami-002eb441f329ccb0f

eu-north-1

ami-0b1a1fb68b3b9fee7

eu-south-1

ami-0bd0fd41a1d3f799a

eu-west-1

ami-04504e8799057980c

eu-west-2

ami-0cc9297ddb3bce971

eu-west-3

ami-06f98f607a50937c6

me-south-1

ami-0fe39da7871a5b2a5

sa-east-1

ami-08265cc3226697767

us-east-1

ami-0fe05b1aa8dacfa90

us-east-2

ami-0ff64f495c7e977cf

us-gov-east-1

ami-0c99658076c41872a

us-gov-west-1

ami-0ca4acd5b8ba1cb1d

us-west-1

ami-01dc5d8e6bb6f23f4

us-west-2

ami-0404a109adfd00019

表 6.49. aarch64 RHCOS AMI

AWS 区AWS AMI

af-south-1

ami-0574bcc5f80b0ad9a

ap-east-1

ami-0a65e79822ae2d235

ap-northeast-1

ami-0f7ef19d48e22353b

ap-northeast-2

ami-051dc6de359975e3c

ap-northeast-3

ami-0fd0b4222595650ac

ap-south-1

ami-05f9d14fe4a90ed6f

ap-southeast-1

ami-0afdb9133d22fba5f

ap-southeast-2

ami-0ef979abe82d07d44

ap-southeast-3

ami-025f9103ac4310e7f

ca-central-1

ami-0588cdf59e5c14847

eu-central-1

ami-0ef24c0e18f93fa42

eu-north-1

ami-0439e2a3bf315df1a

eu-south-1

ami-0714e7c2e0106cdd3

eu-west-1

ami-0b960e76764ccd0c3

eu-west-2

ami-02621f50de62b3b89

eu-west-3

ami-0933ce7f5e2bfb50e

me-south-1

ami-074bde61a2ab740ee

sa-east-1

ami-03b4f97cfc8033ae0

us-east-1

ami-02a574449d4f4d280

us-east-2

ami-020e5600ef28c60ae

us-gov-east-1

ami-069f60e1dcf766d24

us-gov-west-1

ami-0db3cda4dbaccda02

us-west-1

ami-0c90cabeb5dee3178

us-west-2

ami-0f96437a23aeae53f

6.13.14.1. 没有公布的 RHCOS AMI 的 AWS 区域

您可以将 OpenShift Container Platform 集群部署到 Amazon Web Services(AWS)区域,而无需对 Red Hat Enterprise Linux CoreOS(RHCOS)Amazon Machine Image(AMI)或 AWS 软件开发 kit(SDK)的原生支持。如果 AWS 区域没有可用的已公布的 AMI,您可以在安装集群前上传自定义 AMI。

如果您要部署到 AWS SDK 不支持的区域,且您没有指定自定义 AMI,安装程序会自动将 us-east-1 AMI 复制到用户帐户。然后,安装程序使用默认或用户指定的密钥管理服务(KMS)密钥创建带有加密 EBS 卷的 control plane 机器。这允许 AMI 跟踪与公布的 RHCOS AMI 相同的进程工作流。

在集群创建过程中,无法从终端中选择没有原生支持 RHCOS AMI 的区域,因为它没有发布。但是,您可以通过在 install-config.yaml 文件中配置自定义 AMI 来安装到这个区域。

6.13.14.2. 在 AWS 中上传自定义 RHCOS AMI

如果要部署到自定义 Amazon Web Services(AWS)区域,您必须上传属于该区域的自定义 Red Hat Enterprise Linux CoreOS(RHCOS)Amazon Machine Image(AMI)。

先决条件

  • 已配置了一个 AWS 帐户。
  • 已使用所需的 IAM 服务角色创建 Amazon S3 存储桶。
  • 将 RHCOS VMDK 文件上传到 Amazon S3。RHCOS VMDK 文件必须是小于或等于您要安装的 OpenShift Container Platform 版本的最高版本。
  • 您下载了 AWS CLI 并安装到您的计算机上。请参阅使用捆绑安装程序安装 AWS CLI

流程

  1. 将 AWS 配置集导出为环境变量:

    $ export AWS_PROFILE=<aws_profile> 1
  2. 将与自定义 AMI 关联的区域导出为环境变量:

    $ export AWS_DEFAULT_REGION=<aws_region> 1
  3. 将上传至 Amazon S3 的 RHCOS 版本导出为环境变量:

    $ export RHCOS_VERSION=<version> 1
    1 1 1
    RHCOS VMDK 版本,如 4.12.0
  4. 将 Amazon S3 存储桶名称导出为环境变量:

    $ export VMIMPORT_BUCKET_NAME=<s3_bucket_name>
  5. 创建 containers.json 文件并定义 RHCOS VMDK 文件:

    $ cat <<EOF > containers.json
    {
       "Description": "rhcos-${RHCOS_VERSION}-x86_64-aws.x86_64",
       "Format": "vmdk",
       "UserBucket": {
          "S3Bucket": "${VMIMPORT_BUCKET_NAME}",
          "S3Key": "rhcos-${RHCOS_VERSION}-x86_64-aws.x86_64.vmdk"
       }
    }
    EOF
  6. 将 RHCOS 磁盘导入为 Amazon EBS 快照:

    $ aws ec2 import-snapshot --region ${AWS_DEFAULT_REGION} \
         --description "<description>" \ 1
         --disk-container "file://<file_path>/containers.json" 2
    1
    导入 RHCOS 磁盘的描述,如 rhcos-${RHCOS_VERSION}-x86_64-aws.x86_64
    2
    描述 RHCOS 磁盘的 JSON 文件的文件路径。JSON 文件应包含您的 Amazon S3 存储桶名称和密钥。
  7. 检查镜像导入的状态:

    $ watch -n 5 aws ec2 describe-import-snapshot-tasks --region ${AWS_DEFAULT_REGION}

    输出示例

    {
        "ImportSnapshotTasks": [
            {
                "Description": "rhcos-4.7.0-x86_64-aws.x86_64",
                "ImportTaskId": "import-snap-fh6i8uil",
                "SnapshotTaskDetail": {
                    "Description": "rhcos-4.7.0-x86_64-aws.x86_64",
                    "DiskImageSize": 819056640.0,
                    "Format": "VMDK",
                    "SnapshotId": "snap-06331325870076318",
                    "Status": "completed",
                    "UserBucket": {
                        "S3Bucket": "external-images",
                        "S3Key": "rhcos-4.7.0-x86_64-aws.x86_64.vmdk"
                    }
                }
            }
        ]
    }

    复制 SnapshotId 以注册镜像。

  8. 从 RHCOS 快照创建自定义 RHCOS AMI:

    $ aws ec2 register-image \
       --region ${AWS_DEFAULT_REGION} \
       --architecture x86_64 \ 1
       --description "rhcos-${RHCOS_VERSION}-x86_64-aws.x86_64" \ 2
       --ena-support \
       --name "rhcos-${RHCOS_VERSION}-x86_64-aws.x86_64" \ 3
       --virtualization-type hvm \
       --root-device-name '/dev/xvda' \
       --block-device-mappings 'DeviceName=/dev/xvda,Ebs={DeleteOnTermination=true,SnapshotId=<snapshot_ID>}' 4
    1
    RHCOS VMDK 架构类型,如 x86_64, aarch64, s390x, 或 ppc64le
    2
    来自导入快照的 Description
    3
    RHCOS AMI 的名称。
    4
    导入的快照中的 SnapshotID

如需了解更多有关这些 API 的信息,请参阅 AWS 文档 导入快照创建由 EBS 支持的 AMI

6.13.15. 在 AWS 中创建 bootstrap 节点

您必须在 Amazon Web Services (AWS) 中创建 bootstrap 节点,以便在 OpenShift Container Platform 集群初始化过程中使用。您可以按照以下方法:

  • 为集群提供 bootstrap.ign Ignition 配置文件的位置。此文件位于您的安装目录中。提供的 CloudFormation 模板假定集群的 Ignition 配置文件由 S3 存储桶提供。如果选择从其他位置提供文件,您必须修改模板。
  • 使用提供的 CloudFormation 模板和自定义参数文件来创建 AWS 资源堆栈。堆栈代表 OpenShift Container Platform 安装所需的 bootstrap 节点。
注意

如果不使用提供的 CloudFormation 模板来创建 bootstrap 节点,您必须检查提供的信息并手动创建基础架构。如果集群没有正确初始化,您可能需要联系红帽支持并提供您的安装日志。

先决条件

  • 已配置了一个 AWS 帐户。
  • 您可以通过运行 aws configure,将 AWS 密钥和区域添加到本地 AWS 配置集中。
  • 已为集群生成 Ignition 配置文件。
  • 您在 AWS 中创建并配置了 VPC 及相关子网。
  • 您在 AWS 中创建并配置了 DNS、负载均衡器和监听程序。
  • 您在 AWS 中创建了集群所需的安全组和角色。

流程

  1. 运行以下命令来创建存储桶:

    $ aws s3 mb s3://<cluster-name>-infra 1
    1
    <cluster-name>-infra 是存储桶名称。在创建 install-config.yaml 文件时,将 <cluster-name> 替换为为集群指定的名称。

    如果需要,您必须为 S3 存储桶使用预签名 URL,而不是 s3:// 模式:

    • 部署到具有与 AWS SDK 不同端点的区域。
    • 部署代理。
    • 提供您自己的自定义端点。
  2. 运行以下命令,将 bootstrap.ign Ignition 配置文件上传到存储桶:

    $ aws s3 cp <installation_directory>/bootstrap.ign s3://<cluster-name>-infra/bootstrap.ign 1
    1
    对于 <installation_directory>,请指定安装文件保存到的目录的路径。
  3. 运行以下命令验证文件是否已上传:

    $ aws s3 ls s3://<cluster-name>-infra/

    输出示例

    2019-04-03 16:15:16     314878 bootstrap.ign

    注意

    bootstrap Ignition 配置文件包含 secret,如 X.509 密钥。以下步骤为 S3 存储桶提供基本安全性。若要提供额外的安全性,您可以启用 S3 存储桶策略,仅允许某些用户(如 OpenShift IAM 用户)访问存储桶中包含的对象。您可以完全避开 S3,并从 bootstrap 可访问的任意地址提供 bootstrap Ignition 配置文件。

  4. 创建一个 JSON 文件,其包含模板所需的参数值:

    [
      {
        "ParameterKey": "InfrastructureName", 1
        "ParameterValue": "mycluster-<random_string>" 2
      },
      {
        "ParameterKey": "RhcosAmi", 3
        "ParameterValue": "ami-<random_string>" 4
      },
      {
        "ParameterKey": "AllowedBootstrapSshCidr", 5
        "ParameterValue": "0.0.0.0/0" 6
      },
      {
        "ParameterKey": "PublicSubnet", 7
        "ParameterValue": "subnet-<random_string>" 8
      },
      {
        "ParameterKey": "MasterSecurityGroupId", 9
        "ParameterValue": "sg-<random_string>" 10
      },
      {
        "ParameterKey": "VpcId", 11
        "ParameterValue": "vpc-<random_string>" 12
      },
      {
        "ParameterKey": "BootstrapIgnitionLocation", 13
        "ParameterValue": "s3://<bucket_name>/bootstrap.ign" 14
      },
      {
        "ParameterKey": "AutoRegisterELB", 15
        "ParameterValue": "yes" 16
      },
      {
        "ParameterKey": "RegisterNlbIpTargetsLambdaArn", 17
        "ParameterValue": "arn:aws:lambda:<aws_region>:<account_number>:function:<dns_stack_name>-RegisterNlbIpTargets-<random_string>" 18
      },
      {
        "ParameterKey": "ExternalApiTargetGroupArn", 19
        "ParameterValue": "arn:aws:elasticloadbalancing:<aws_region>:<account_number>:targetgroup/<dns_stack_name>-Exter-<random_string>" 20
      },
      {
        "ParameterKey": "InternalApiTargetGroupArn", 21
        "ParameterValue": "arn:aws:elasticloadbalancing:<aws_region>:<account_number>:targetgroup/<dns_stack_name>-Inter-<random_string>" 22
      },
      {
        "ParameterKey": "InternalServiceTargetGroupArn", 23
        "ParameterValue": "arn:aws:elasticloadbalancing:<aws_region>:<account_number>:targetgroup/<dns_stack_name>-Inter-<random_string>" 24
      }
    ]
    1
    您的 Ignition 配置文件中为集群编码的集群基础架构名称。
    2
    指定从 Ignition 配置文件元数据中提取的基础架构名称,其格式为 <cluster-name>-<random-string>
    3
    根据您选择的架构,当前 Red Hat Enterprise Linux CoreOS (RHCOS) AMI 用于 bootstrap 节点。
    4
    指定有效的 AWS::EC2::Image::Id 值。
    5
    允许通过 SSH 访问 bootstrap 节点的 CIDR 块。
    6
    x.x.x.x/16-24 格式指定 CIDR 块。
    7
    与 VPC 关联的公共子网,将 bootstrap 节点启动到其中。
    8
    指定 VPC 的 CloudFormation 模板输出的 PublicSubnetIds 值。
    9
    master 安全组 ID(用于注册临时规则)
    10
    指定安全组和角色的 CloudFormation 模板输出的 MasterSecurityGroupId 值。
    11
    创建的资源将从属于的 VPC。
    12
    指定 VPC 的 CloudFormation 模板输出的 VpcId 值。
    13
    从中获取 bootstrap Ignition 配置文件的位置。
    14
    指定 S3 存储桶和文件名,格式为 s3://<bucket_name>/bootstrap.ign
    15
    是否要注册网络负载均衡器 (NLB) 。
    16
    指定 yesno。如果指定 yes,您必须提供一个 Lambda Amazon Resource Name (ARN) 值。
    17
    NLB IP 目标注册 lambda 组的 ARN。
    18
    指定 DNS 和负载均衡的 CloudFormation 模板输出的 RegisterNlbIpTargetsLambda 值。如果将集群部署到 AWS GovCloud 区域,请使用 arn:aws-us-gov
    19
    外部 API 负载均衡器目标组的 ARN。
    20
    指定 DNS 和负载均衡的 CloudFormation 模板输出的 ExternalApiTargetGroupArn 值。如果将集群部署到 AWS GovCloud 区域,请使用 arn:aws-us-gov
    21
    内部 API 负载均衡器目标组群的 ARN。
    22
    指定 DNS 和负载均衡的 CloudFormation 模板输出的 InternalApiTargetGroupArn 值。如果将集群部署到 AWS GovCloud 区域,请使用 arn:aws-us-gov
    23
    内部服务负载均衡器目标组群的 ARN。
    24
    指定 DNS 和负载均衡的 CloudFormation 模板输出的 InternalServiceTargetGroupArn 值。如果将集群部署到 AWS GovCloud 区域,请使用 arn:aws-us-gov
  5. 复制本主题的 Bootstrap 机器的 CloudFormation 模板部分中的模板,并将它以 YAML 文件形式保存到计算机上。此模板描述了集群所需的 bootstrap 机器。
  6. 可选: 如果要使用代理部署集群,您必须更新模板中的 ignition 以添加 ignition.config.proxy 字段。另外,如果您已将 Amazon EC2、Elastic Load Balancing 和 S3 VPC 端点添加到 VPC 中,您必须将这些端点添加到 noProxy 字段。
  7. 启动 CloudFormation 模板,以创建代表 bootstrap 节点的 AWS 资源堆栈:

    重要

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

    $ aws cloudformation create-stack --stack-name <name> 1
         --template-body file://<template>.yaml 2
         --parameters file://<parameters>.json 3
         --capabilities CAPABILITY_NAMED_IAM 4
    1
    <name> 是 CloudFormation 堆栈的名称,如 cluster-bootstrap。如果您删除集群,则需要此堆栈的名称。
    2
    <template> 是您保存的 CloudFormation 模板 YAML 文件的相对路径和名称。
    3
    <parameters> 是 CloudFormation 参数 JSON 文件的相对路径和名称。
    4
    您必须明确声明 CAPABILITY_NAMED_IAM 功能,因为提供的模板会创建一些 AWS::IAM::RoleAWS::IAM::InstanceProfile 资源。

    输出示例

    arn:aws:cloudformation:us-east-1:269333783861:stack/cluster-bootstrap/12944486-2add-11eb-9dee-12dace8e3a83

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

    $ aws cloudformation describe-stacks --stack-name <name>

    StackStatus 显示 CREATE_COMPLETE 后,输出会显示以下参数的值。您必须将这些参数值提供给您在创建集群时要运行的其他 CloudFormation 模板:

    BootstrapInstanceId

    bootstrap 实例 ID。

    BootstrapPublicIp

    bootstrap 节点公共 IP 地址。

    BootstrapPrivateIp

    bootstrap 节点专用 IP 地址。

6.13.15.1. bootstrap 机器的 CloudFormation 模板

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

例 6.47. bootstrap 机器的 CloudFormation 模板

AWSTemplateFormatVersion: 2010-09-09
Description: Template for OpenShift Cluster Bootstrap (EC2 Instance, Security Groups and IAM)

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 cloud resources and identify items owned or used by the cluster.
    Type: String
  RhcosAmi:
    Description: Current Red Hat Enterprise Linux CoreOS AMI to use for bootstrap.
    Type: AWS::EC2::Image::Id
  AllowedBootstrapSshCidr:
    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])(\/([0-9]|1[0-9]|2[0-9]|3[0-2]))$
    ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/0-32.
    Default: 0.0.0.0/0
    Description: CIDR block to allow SSH access to the bootstrap node.
    Type: String
  PublicSubnet:
    Description: The public subnet to launch the bootstrap node into.
    Type: AWS::EC2::Subnet::Id
  MasterSecurityGroupId:
    Description: The master security group ID for registering temporary rules.
    Type: AWS::EC2::SecurityGroup::Id
  VpcId:
    Description: The VPC-scoped resources will belong to this VPC.
    Type: AWS::EC2::VPC::Id
  BootstrapIgnitionLocation:
    Default: s3://my-s3-bucket/bootstrap.ign
    Description: Ignition config file location.
    Type: String
  AutoRegisterELB:
    Default: "yes"
    AllowedValues:
    - "yes"
    - "no"
    Description: Do you want to invoke NLB registration, which requires a Lambda ARN parameter?
    Type: String
  RegisterNlbIpTargetsLambdaArn:
    Description: ARN for NLB IP target registration lambda.
    Type: String
  ExternalApiTargetGroupArn:
    Description: ARN for external API load balancer target group.
    Type: String
  InternalApiTargetGroupArn:
    Description: ARN for internal API load balancer target group.
    Type: String
  InternalServiceTargetGroupArn:
    Description: ARN for internal service load balancer target group.
    Type: String
  BootstrapInstanceType:
    Description: Instance type for the bootstrap EC2 instance
    Default: "i3.large"
    Type: String

Metadata:
  AWS::CloudFormation::Interface:
    ParameterGroups:
    - Label:
        default: "Cluster Information"
      Parameters:
      - InfrastructureName
    - Label:
        default: "Host Information"
      Parameters:
      - RhcosAmi
      - BootstrapIgnitionLocation
      - MasterSecurityGroupId
    - Label:
        default: "Network Configuration"
      Parameters:
      - VpcId
      - AllowedBootstrapSshCidr
      - PublicSubnet
    - Label:
        default: "Load Balancer Automation"
      Parameters:
      - AutoRegisterELB
      - RegisterNlbIpTargetsLambdaArn
      - ExternalApiTargetGroupArn
      - InternalApiTargetGroupArn
      - InternalServiceTargetGroupArn
    ParameterLabels:
      InfrastructureName:
        default: "Infrastructure Name"
      VpcId:
        default: "VPC ID"
      AllowedBootstrapSshCidr:
        default: "Allowed SSH Source"
      PublicSubnet:
        default: "Public Subnet"
      RhcosAmi:
        default: "Red Hat Enterprise Linux CoreOS AMI ID"
      BootstrapIgnitionLocation:
        default: "Bootstrap Ignition Source"
      MasterSecurityGroupId:
        default: "Master Security Group ID"
      AutoRegisterELB:
        default: "Use Provided ELB Automation"

Conditions:
  DoRegistration: !Equals ["yes", !Ref AutoRegisterELB]

Resources:
  BootstrapIamRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
        - Effect: "Allow"
          Principal:
            Service:
            - "ec2.amazonaws.com"
          Action:
          - "sts:AssumeRole"
      Path: "/"
      Policies:
      - PolicyName: !Join ["-", [!Ref InfrastructureName, "bootstrap", "policy"]]
        PolicyDocument:
          Version: "2012-10-17"
          Statement:
          - Effect: "Allow"
            Action: "ec2:Describe*"
            Resource: "*"
          - Effect: "Allow"
            Action: "ec2:AttachVolume"
            Resource: "*"
          - Effect: "Allow"
            Action: "ec2:DetachVolume"
            Resource: "*"
          - Effect: "Allow"
            Action: "s3:GetObject"
            Resource: "*"

  BootstrapInstanceProfile:
    Type: "AWS::IAM::InstanceProfile"
    Properties:
      Path: "/"
      Roles:
      - Ref: "BootstrapIamRole"

  BootstrapSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: Cluster Bootstrap Security Group
      SecurityGroupIngress:
      - IpProtocol: tcp
        FromPort: 22
        ToPort: 22
        CidrIp: !Ref AllowedBootstrapSshCidr
      - IpProtocol: tcp
        ToPort: 19531
        FromPort: 19531
        CidrIp: 0.0.0.0/0
      VpcId: !Ref VpcId

  BootstrapInstance:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: !Ref RhcosAmi
      IamInstanceProfile: !Ref BootstrapInstanceProfile
      InstanceType: !Ref BootstrapInstanceType
      NetworkInterfaces:
      - AssociatePublicIpAddress: "true"
        DeviceIndex: "0"
        GroupSet:
        - !Ref "BootstrapSecurityGroup"
        - !Ref "MasterSecurityGroupId"
        SubnetId: !Ref "PublicSubnet"
      UserData:
        Fn::Base64: !Sub
        - '{"ignition":{"config":{"replace":{"source":"${S3Loc}"}},"version":"3.1.0"}}'
        - {
          S3Loc: !Ref BootstrapIgnitionLocation
        }

  RegisterBootstrapApiTarget:
    Condition: DoRegistration
    Type: Custom::NLBRegister
    Properties:
      ServiceToken: !Ref RegisterNlbIpTargetsLambdaArn
      TargetArn: !Ref ExternalApiTargetGroupArn
      TargetIp: !GetAtt BootstrapInstance.PrivateIp

  RegisterBootstrapInternalApiTarget:
    Condition: DoRegistration
    Type: Custom::NLBRegister
    Properties:
      ServiceToken: !Ref RegisterNlbIpTargetsLambdaArn
      TargetArn: !Ref InternalApiTargetGroupArn
      TargetIp: !GetAtt BootstrapInstance.PrivateIp

  RegisterBootstrapInternalServiceTarget:
    Condition: DoRegistration
    Type: Custom::NLBRegister
    Properties:
      ServiceToken: !Ref RegisterNlbIpTargetsLambdaArn
      TargetArn: !Ref InternalServiceTargetGroupArn
      TargetIp: !GetAtt BootstrapInstance.PrivateIp

Outputs:
  BootstrapInstanceId:
    Description: Bootstrap Instance ID.
    Value: !Ref BootstrapInstance

  BootstrapPublicIp:
    Description: The bootstrap node public IP address.
    Value: !GetAtt BootstrapInstance.PublicIp

  BootstrapPrivateIp:
    Description: The bootstrap node private IP address.
    Value: !GetAtt BootstrapInstance.PrivateIp

其他资源

6.13.16. 在 AWS 中创建 control plane 机器

您必须在集群要使用的 Amazon Web Services(AWS)中创建 control plane 机器。

您可以使用提供的 CloudFormation 模板和自定义参数文件,创建代表 control plane 节点的 AWS 资源堆栈。

重要

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

注意

如果不使用提供的 CloudFormation 模板来创建 control plane 节点,您必须检查提供的信息并手动创建基础架构。如果集群没有正确初始化,您可能需要联系红帽支持并提供您的安装日志。

先决条件

  • 已配置了一个 AWS 帐户。
  • 您可以通过运行 aws configure,将 AWS 密钥和区域添加到本地 AWS 配置集中。
  • 已为集群生成 Ignition 配置文件。
  • 您在 AWS 中创建并配置了 VPC 及相关子网。
  • 您在 AWS 中创建并配置了 DNS、负载均衡器和监听程序。
  • 您在 AWS 中创建了集群所需的安全组和角色。
  • 已创建 bootstrap 机器。

流程

  1. 创建一个 JSON 文件,其包含模板所需的参数值:

    [
      {
        "ParameterKey": "InfrastructureName", 1
        "ParameterValue": "mycluster-<random_string>" 2
      },
      {
        "ParameterKey": "RhcosAmi", 3
        "ParameterValue": "ami-<random_string>" 4
      },
      {
        "ParameterKey": "AutoRegisterDNS", 5
        "ParameterValue": "yes" 6
      },
      {
        "ParameterKey": "PrivateHostedZoneId", 7
        "ParameterValue": "<random_string>" 8
      },
      {
        "ParameterKey": "PrivateHostedZoneName", 9
        "ParameterValue": "mycluster.example.com" 10
      },
      {
        "ParameterKey": "Master0Subnet", 11
        "ParameterValue": "subnet-<random_string>" 12
      },
      {
        "ParameterKey": "Master1Subnet", 13
        "ParameterValue": "subnet-<random_string>" 14
      },
      {
        "ParameterKey": "Master2Subnet", 15
        "ParameterValue": "subnet-<random_string>" 16
      },
      {
        "ParameterKey": "MasterSecurityGroupId", 17
        "ParameterValue": "sg-<random_string>" 18
      },
      {
        "ParameterKey": "IgnitionLocation", 19
        "ParameterValue": "https://api-int.<cluster_name>.<domain_name>:22623/config/master" 20
      },
      {
        "ParameterKey": "CertificateAuthorities", 21
        "ParameterValue": "data:text/plain;charset=utf-8;base64,ABC...xYz==" 22
      },
      {
        "ParameterKey": "MasterInstanceProfileName", 23
        "ParameterValue": "<roles_stack>-MasterInstanceProfile-<random_string>" 24
      },
      {
        "ParameterKey": "MasterInstanceType", 25
        "ParameterValue": "" 26
      },
      {
        "ParameterKey": "AutoRegisterELB", 27
        "ParameterValue": "yes" 28
      },
      {
        "ParameterKey": "RegisterNlbIpTargetsLambdaArn", 29
        "ParameterValue": "arn:aws:lambda:<aws_region>:<account_number>:function:<dns_stack_name>-RegisterNlbIpTargets-<random_string>" 30
      },
      {
        "ParameterKey": "ExternalApiTargetGroupArn", 31
        "ParameterValue": "arn:aws:elasticloadbalancing:<aws_region>:<account_number>:targetgroup/<dns_stack_name>-Exter-<random_string>" 32
      },
      {
        "ParameterKey": "InternalApiTargetGroupArn", 33
        "ParameterValue": "arn:aws:elasticloadbalancing:<aws_region>:<account_number>:targetgroup/<dns_stack_name>-Inter-<random_string>" 34
      },
      {
        "ParameterKey": "InternalServiceTargetGroupArn", 35
        "ParameterValue": "arn:aws:elasticloadbalancing:<aws_region>:<account_number>:targetgroup/<dns_stack_name>-Inter-<random_string>" 36
      }
    ]
    1
    您的 Ignition 配置文件中为集群编码的集群基础架构名称。
    2
    指定从 Ignition 配置文件元数据中提取的基础架构名称,其格式为 <cluster-name>-<random-string>
    3
    根据您选择的架构,当前用于 control plane 机器的 Red Hat Enterprise Linux CoreOS (RHCOS) AMI。
    4
    指定 AWS::EC2::Image::Id 值。
    5
    是否要执行 DNS etcd 注册。
    6
    指定 yesno。如果指定 yes,您必须提供托管区信息。
    7
    用来注册 etcd 目标的 Route 53 专用区 ID。
    8
    指定 DNS 和负载均衡的 CloudFormation 模板输出的 PrivateHostedZoneId 值。
    9
    用来注册目标的 Route 53 区。
    10
    指定 <cluster_name>.<domain_name>,其中 <domain_name> 是您为集群生成 install-config.yaml 文件时所用的 Route 53 基域。请勿包含 AWS 控制台中显示的结尾句点 (.)。
    11 13 15
    在其中启动 control plane 机器的子网,最好是专用子网。
    12 14 16
    从 DNS 和负载均衡的 CloudFormation 模板输出的 PrivateSubnets 值指定子网。
    17
    与 control plane 节点关联的 master 安全组 ID。
    18
    指定安全组和角色的 CloudFormation 模板输出的 MasterSecurityGroupId 值。
    19
    从中获取 control plane Ignition 配置文件的位置。
    20
    指定生成的 Ignition 配置文件的位置,https://api-int.<cluster_name>.<domain_name>:22623/config/master
    21
    要使用的 base64 编码证书颁发机构字符串。
    22
    指定安装目录中 master.ign 文件中的值。这个值是一个长字符串,格式为 data:text/plain;charset=utf-8;base64,ABC…​xYz==
    23
    与 control plane 节点关联的 IAM 配置集。
    24
    指定安全组和角色的 CloudFormation 模板输出的 MasterInstanceProfile 参数值。
    25
    根据您选择的架构,用于 control plane 机器的 AWS 实例类型。
    26
    实例类型值与 control plane 机器的最低资源要求对应。例如,m6i.xlarge 是 AMD64 的类型,m6g.xlarge 是 ARM64 的类型。
    27
    是否要注册网络负载均衡器 (NLB) 。
    28
    指定 yesno。如果指定 yes,您必须提供一个 Lambda Amazon Resource Name (ARN) 值。
    29
    NLB IP 目标注册 lambda 组的 ARN。
    30
    指定 DNS 和负载均衡的 CloudFormation 模板输出的 RegisterNlbIpTargetsLambda 值。如果将集群部署到 AWS GovCloud 区域,请使用 arn:aws-us-gov
    31
    外部 API 负载均衡器目标组的 ARN。
    32
    指定 DNS 和负载均衡的 CloudFormation 模板输出的 ExternalApiTargetGroupArn 值。如果将集群部署到 AWS GovCloud 区域,请使用 arn:aws-us-gov
    33
    内部 API 负载均衡器目标组群的 ARN。
    34
    指定 DNS 和负载均衡的 CloudFormation 模板输出的 InternalApiTargetGroupArn 值。如果将集群部署到 AWS GovCloud 区域,请使用 arn:aws-us-gov
    35
    内部服务负载均衡器目标组群的 ARN。
    36
    指定 DNS 和负载均衡的 CloudFormation 模板输出的 InternalServiceTargetGroupArn 值。如果将集群部署到 AWS GovCloud 区域,请使用 arn:aws-us-gov
  2. 复制control plane 机器的 CloudFormation 模板一节中的模板,并将它以 YAML 文件形式保存到计算机上。此模板描述了集群所需的 control plane 机器。
  3. 如果您将 m5 实例类型指定为 MasterInstanceType 的值,请将该实例类型添加到 CloudFormation 模板中的 MasterInstanceType.AllowedValues 参数。
  4. 启动 CloudFormation 模板,以创建代表 control plane 节点的 AWS 资源堆栈:

    重要

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

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

    输出示例

    arn:aws:cloudformation:us-east-1:269333783861:stack/cluster-control-plane/21c7e2b0-2ee2-11eb-c6f6-0aa34627df4b

    注意

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

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

    $ aws cloudformation describe-stacks --stack-name <name>

6.13.16.1. control plane 机器的 CloudFormation 模板

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

例 6.48. control plane 机器的 CloudFormation 模板

AWSTemplateFormatVersion: 2010-09-09
Description: Template for OpenShift Cluster Node Launch (EC2 master instances)

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
  AutoRegisterDNS:
    Default: ""
    Description: unused
    Type: String
  PrivateHostedZoneId:
    Default: ""
    Description: unused
    Type: String
  PrivateHostedZoneName:
    Default: ""
    Description: unused
    Type: String
  Master0Subnet:
    Description: The subnets, recommend private, to launch the master nodes into.
    Type: AWS::EC2::Subnet::Id
  Master1Subnet:
    Description: The subnets, recommend private, to launch the master nodes into.
    Type: AWS::EC2::Subnet::Id
  Master2Subnet:
    Description: The subnets, recommend private, to launch the master nodes into.
    Type: AWS::EC2::Subnet::Id
  MasterSecurityGroupId:
    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/master
    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
  MasterInstanceProfileName:
    Description: IAM profile to associate with master nodes.
    Type: String
  MasterInstanceType:
    Default: m5.xlarge
    Type: String

  AutoRegisterELB:
    Default: "yes"
    AllowedValues:
    - "yes"
    - "no"
    Description: Do you want to invoke NLB registration, which requires a Lambda ARN parameter?
    Type: String
  RegisterNlbIpTargetsLambdaArn:
    Description: ARN for NLB IP target registration lambda. Supply the value from the cluster infrastructure or select "no" for AutoRegisterELB.
    Type: String
  ExternalApiTargetGroupArn:
    Description: ARN for external API load balancer target group. Supply the value from the cluster infrastructure or select "no" for AutoRegisterELB.
    Type: String
  InternalApiTargetGroupArn:
    Description: ARN for internal API load balancer target group. Supply the value from the cluster infrastructure or select "no" for AutoRegisterELB.
    Type: String
  InternalServiceTargetGroupArn:
    Description: ARN for internal service load balancer target group. Supply the value from the cluster infrastructure or select "no" for AutoRegisterELB.
    Type: String

Metadata:
  AWS::CloudFormation::Interface:
    ParameterGroups:
    - Label:
        default: "Cluster Information"
      Parameters:
      - InfrastructureName
    - Label:
        default: "Host Information"
      Parameters:
      - MasterInstanceType
      - RhcosAmi
      - IgnitionLocation
      - CertificateAuthorities
      - MasterSecurityGroupId
      - MasterInstanceProfileName
    - Label:
        default: "Network Configuration"
      Parameters:
      - VpcId
      - AllowedBootstrapSshCidr
      - Master0Subnet
      - Master1Subnet
      - Master2Subnet
    - Label:
        default: "Load Balancer Automation"
      Parameters:
      - AutoRegisterELB
      - RegisterNlbIpTargetsLambdaArn
      - ExternalApiTargetGroupArn
      - InternalApiTargetGroupArn
      - InternalServiceTargetGroupArn
    ParameterLabels:
      InfrastructureName:
        default: "Infrastructure Name"
      VpcId:
        default: "VPC ID"
      Master0Subnet:
        default: "Master-0 Subnet"
      Master1Subnet:
        default: "Master-1 Subnet"
      Master2Subnet:
        default: "Master-2 Subnet"
      MasterInstanceType:
        default: "Master Instance Type"
      MasterInstanceProfileName:
        default: "Master Instance Profile Name"
      RhcosAmi:
        default: "Red Hat Enterprise Linux CoreOS AMI ID"
      BootstrapIgnitionLocation:
        default: "Master Ignition Source"
      CertificateAuthorities:
        default: "Ignition CA String"
      MasterSecurityGroupId:
        default: "Master Security Group ID"
      AutoRegisterELB:
        default: "Use Provided ELB Automation"

Conditions:
  DoRegistration: !Equals ["yes", !Ref AutoRegisterELB]

Resources:
  Master0:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: !Ref RhcosAmi
      BlockDeviceMappings:
      - DeviceName: /dev/xvda
        Ebs:
          VolumeSize: "120"
          VolumeType: "gp2"
      IamInstanceProfile: !Ref MasterInstanceProfileName
      InstanceType: !Ref MasterInstanceType
      NetworkInterfaces:
      - AssociatePublicIpAddress: "false"
        DeviceIndex: "0"
        GroupSet:
        - !Ref "MasterSecurityGroupId"
        SubnetId: !Ref "Master0Subnet"
      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"

  RegisterMaster0:
    Condition: DoRegistration
    Type: Custom::NLBRegister
    Properties:
      ServiceToken: !Ref RegisterNlbIpTargetsLambdaArn
      TargetArn: !Ref ExternalApiTargetGroupArn
      TargetIp: !GetAtt Master0.PrivateIp

  RegisterMaster0InternalApiTarget:
    Condition: DoRegistration
    Type: Custom::NLBRegister
    Properties:
      ServiceToken: !Ref RegisterNlbIpTargetsLambdaArn
      TargetArn: !Ref InternalApiTargetGroupArn
      TargetIp: !GetAtt Master0.PrivateIp

  RegisterMaster0InternalServiceTarget:
    Condition: DoRegistration
    Type: Custom::NLBRegister
    Properties:
      ServiceToken: !Ref RegisterNlbIpTargetsLambdaArn
      TargetArn: !Ref InternalServiceTargetGroupArn
      TargetIp: !GetAtt Master0.PrivateIp

  Master1:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: !Ref RhcosAmi
      BlockDeviceMappings:
      - DeviceName: /dev/xvda
        Ebs:
          VolumeSize: "120"
          VolumeType: "gp2"
      IamInstanceProfile: !Ref MasterInstanceProfileName
      InstanceType: !Ref MasterInstanceType
      NetworkInterfaces:
      - AssociatePublicIpAddress: "false"
        DeviceIndex: "0"
        GroupSet:
        - !Ref "MasterSecurityGroupId"
        SubnetId: !Ref "Master1Subnet"
      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"

  RegisterMaster1:
    Condition: DoRegistration
    Type: Custom::NLBRegister
    Properties:
      ServiceToken: !Ref RegisterNlbIpTargetsLambdaArn
      TargetArn: !Ref ExternalApiTargetGroupArn
      TargetIp: !GetAtt Master1.PrivateIp

  RegisterMaster1InternalApiTarget:
    Condition: DoRegistration
    Type: Custom::NLBRegister
    Properties:
      ServiceToken: !Ref RegisterNlbIpTargetsLambdaArn
      TargetArn: !Ref InternalApiTargetGroupArn
      TargetIp: !GetAtt Master1.PrivateIp

  RegisterMaster1InternalServiceTarget:
    Condition: DoRegistration
    Type: Custom::NLBRegister
    Properties:
      ServiceToken: !Ref RegisterNlbIpTargetsLambdaArn
      TargetArn: !Ref InternalServiceTargetGroupArn
      TargetIp: !GetAtt Master1.PrivateIp

  Master2:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: !Ref RhcosAmi
      BlockDeviceMappings:
      - DeviceName: /dev/xvda
        Ebs:
          VolumeSize: "120"
          VolumeType: "gp2"
      IamInstanceProfile: !Ref MasterInstanceProfileName
      InstanceType: !Ref MasterInstanceType
      NetworkInterfaces:
      - AssociatePublicIpAddress: "false"
        DeviceIndex: "0"
        GroupSet:
        - !Ref "MasterSecurityGroupId"
        SubnetId: !Ref "Master2Subnet"
      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"

  RegisterMaster2:
    Condition: DoRegistration
    Type: Custom::NLBRegister
    Properties:
      ServiceToken: !Ref RegisterNlbIpTargetsLambdaArn
      TargetArn: !Ref ExternalApiTargetGroupArn
      TargetIp: !GetAtt Master2.PrivateIp

  RegisterMaster2InternalApiTarget:
    Condition: DoRegistration
    Type: Custom::NLBRegister
    Properties:
      ServiceToken: !Ref RegisterNlbIpTargetsLambdaArn
      TargetArn: !Ref InternalApiTargetGroupArn
      TargetIp: !GetAtt Master2.PrivateIp

  RegisterMaster2InternalServiceTarget:
    Condition: DoRegistration
    Type: Custom::NLBRegister
    Properties:
      ServiceToken: !Ref RegisterNlbIpTargetsLambdaArn
      TargetArn: !Ref InternalServiceTargetGroupArn
      TargetIp: !GetAtt Master2.PrivateIp

Outputs:
  PrivateIPs:
    Description: The control-plane node private IP addresses.
    Value:
      !Join [
        ",",
        [!GetAtt Master0.PrivateIp, !GetAtt Master1.PrivateIp, !GetAtt Master2.PrivateIp]
      ]

其他资源

6.13.17. 在 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": "" 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 的类型。
  2. 复制 worker 机器的 CloudFormation 模板一节中的模板,并将它以 YAML 文件形式保存到计算机上。此模板描述了集群所需的网络对象和负载均衡器。
  3. 可选:如果将 m5 实例类型指定为 WorkerInstanceType 的值,请将该实例类型添加到 CloudFormation 模板中的 WorkerInstanceType.AllowedValues 参数。
  4. 可选:如果您使用 AWS Marketplace 镜像部署,请使用从订阅获取的 AMI ID 更新 Worker0.type.properties.ImageID 参数。
  5. 使用 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 节点。

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

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

    重要

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

6.13.17.1. worker 机器的 CloudFormation 模板

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

例 6.49. 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

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

其他资源

6.13.18. 使用用户置备的基础架构在 AWS 上初始化 bootstrap 序列

在 Amazon Web Services(AWS)中创建所有所需的基础架构后,您可以启动初始化 OpenShift Container Platform control plane 的 bootstrap 序列。

先决条件

  • 已配置了一个 AWS 帐户。
  • 您可以通过运行 aws configure,将 AWS 密钥和区域添加到本地 AWS 配置集中。
  • 已为集群生成 Ignition 配置文件。
  • 您在 AWS 中创建并配置了 VPC 及相关子网。
  • 您在 AWS 中创建并配置了 DNS、负载均衡器和监听程序。
  • 您在 AWS 中创建了集群所需的安全组和角色。
  • 已创建 bootstrap 机器。
  • 已创建 control plane 机器。
  • 已创建 worker 节点。

流程

  1. 更改为包含安装程序的目录,并启动初始化 OpenShift Container Platform control plane 的 bootstrap 过程:

    $ ./openshift-install wait-for bootstrap-complete --dir <installation_directory> \ 1
        --log-level=info 2
    1
    对于 <installation_directory>,请指定安装文件保存到的目录的路径。
    2
    要查看不同的安装详情,请指定 warndebugerror,而不是 info

    输出示例

    INFO Waiting up to 20m0s for the Kubernetes API at https://api.mycluster.example.com:6443...
    INFO API v1.25.0 up
    INFO Waiting up to 30m0s for bootstrapping to complete...
    INFO It is now safe to remove the bootstrap resources
    INFO Time elapsed: 1s

    如果命令退出时没有 FATAL 警告,则 OpenShift Container Platform control plane 已被初始化。

    注意

    在 control plane 初始化后,它会设置计算节点,并以 Operator 的形式安装其他服务。

其他资源

6.13.19. 通过下载二进制文件安装 OpenShift CLI

您可以安装 OpenShift CLI(oc)来使用命令行界面与 OpenShift Container Platform 进行交互。您可以在 Linux、Windows 或 macOS 上安装 oc

重要

如果安装了旧版本的 oc,则无法使用 OpenShift Container Platform 4.12 中的所有命令。下载并安装新版本的 oc

在 Linux 上安装 OpenShift CLI

您可以按照以下流程在 Linux 上安装 OpenShift CLI(oc)二进制文件。

流程

  1. 导航到红帽客户门户网站上的 OpenShift Container Platform 下载页面
  2. 产品变体 下拉列表中选择架构。
  3. 版本 下拉列表中选择适当的版本。
  4. OpenShift v4.12 Linux Client 条目旁的 Download Now 来保存文件。
  5. 解包存档:

    $ tar xvf <file>
  6. oc 二进制文件放到 PATH 中的目录中

    要查看您的 PATH,请执行以下命令:

    $ echo $PATH

验证

  • 安装 OpenShift CLI 后,可以使用 oc 命令:

    $ oc <command>
在 Windows 上安装 OpenShift CLI

您可以按照以下流程在 Windows 上安装 OpenShift CLI(oc)二进制文件。

流程

  1. 导航到红帽客户门户网站上的 OpenShift Container Platform 下载页面
  2. 版本 下拉列表中选择适当的版本。
  3. OpenShift v4.12 Windows Client 条目旁的 Download Now 来保存文件。
  4. 使用 ZIP 程序解压存档。
  5. oc 二进制文件移到 PATH 中的目录中

    要查看您的 PATH,请打开命令提示并执行以下命令:

    C:\> path

验证

  • 安装 OpenShift CLI 后,可以使用 oc 命令:

    C:\> oc <command>
在 macOS 上安装 OpenShift CLI

您可以按照以下流程在 macOS 上安装 OpenShift CLI(oc)二进制文件。

流程

  1. 导航到红帽客户门户网站上的 OpenShift Container Platform 下载页面
  2. 版本 下拉列表中选择适当的版本。
  3. OpenShift v4.12 macOS Client 条目旁的 Download Now 来保存文件。

    注意

    对于 macOS arm64,请选择 OpenShift v4.12 macOS arm64 Client 条目。

  4. 解包和解压存档。
  5. oc 二进制文件移到 PATH 的目录中。

    要查看您的 PATH,请打开终端并执行以下命令:

    $ echo $PATH

验证

  • 安装 OpenShift CLI 后,可以使用 oc 命令:

    $ oc <command>

6.13.20. 使用 CLI 登录集群

您可以通过导出集群 kubeconfig 文件,以默认系统用户身份登录集群。kubeconfig 文件包含有关集群的信息,供 CLI 用于将客户端连接到正确的集群和 API 服务器。该文件特定于集群,在 OpenShift Container Platform 安装过程中创建。

先决条件

  • 已部署 OpenShift Container Platform 集群。
  • 已安装 oc CLI。

流程

  1. 导出 kubeadmin 凭证:

    $ export KUBECONFIG=<installation_directory>/auth/kubeconfig 1
    1
    对于 <installation_directory>,请指定安装文件保存到的目录的路径。
  2. 验证您可以使用导出的配置成功运行 oc 命令:

    $ oc whoami

    输出示例

    system:admin

6.13.21. 批准机器的证书签名请求

当您将机器添加到集群时,会为您添加的每台机器生成两个待处理证书签名请求(CSR)。您必须确认这些 CSR 已获得批准,或根据需要自行批准。必须首先批准客户端请求,然后批准服务器请求。

先决条件

  • 您已将机器添加到集群中。

流程

  1. 确认集群可以识别这些机器:

    $ oc get nodes

    输出示例

    NAME      STATUS    ROLES   AGE  VERSION
    master-0  Ready     master  63m  v1.25.0
    master-1  Ready     master  63m  v1.25.0
    master-2  Ready     master  64m  v1.25.0

    输出中列出了您创建的所有机器。

    注意

    在有些 CSR 被批准前,前面的输出可能不包括计算节点(也称为 worker 节点)。

  2. 检查待处理的 CSR,并确保添加到集群中的每台机器都有 PendingApproved 状态的客户端请求:

    $ oc get csr

    输出示例

    NAME        AGE     REQUESTOR                                                                   CONDITION
    csr-8b2br   15m     system:serviceaccount:openshift-machine-config-operator:node-bootstrapper   Pending
    csr-8vnps   15m     system:serviceaccount:openshift-machine-config-operator:node-bootstrapper   Pending
    ...

    在本例中,两台机器加入集群。您可能会在列表中看到更多已批准的 CSR。

  3. 如果 CSR 没有获得批准,在您添加的机器的所有待处理 CSR 都处于 Pending 状态 后,请批准集群机器的 CSR:

    注意

    由于 CSR 会自动轮转,因此请在将机器添加到集群后一小时内批准您的 CSR。如果没有在一小时内批准它们,证书将会轮转,每个节点会存在多个证书。您必须批准所有这些证书。批准客户端 CSR 后,Kubelet 为服务证书创建一个二级 CSR,这需要手动批准。然后,如果 Kubelet 请求具有相同参数的新证书,则后续提供证书续订请求由 machine-approver 自动批准。

    注意

    对于在未启用机器 API 的平台上运行的集群,如裸机和其他用户置备的基础架构,您必须实施一种方法来自动批准 kubelet 提供证书请求(CSR)。如果没有批准请求,则 oc exec、ocrshoc logs 命令将无法成功,因为 API 服务器连接到 kubelet 时需要服务证书。与 Kubelet 端点联系的任何操作都需要此证书批准。该方法必须监视新的 CSR,确认 CSR 由 system: nodesystem:admin 组中的 node-bootstrapper 服务帐户提交,并确认节点的身份。

    • 要单独批准,请对每个有效的 CSR 运行以下命令:

      $ oc adm certificate approve <csr_name> 1
      1
      <csr_name> 是当前 CSR 列表中 CSR 的名称。
    • 要批准所有待处理的 CSR,请运行以下命令:

      $ oc get csr -o go-template='{{range .items}}{{if not .status}}{{.metadata.name}}{{"\n"}}{{end}}{{end}}' | xargs --no-run-if-empty oc adm certificate approve
      注意

      在有些 CSR 被批准前,一些 Operator 可能无法使用。

  4. 现在,您的客户端请求已被批准,您必须查看添加到集群中的每台机器的服务器请求:

    $ oc get csr

    输出示例

    NAME        AGE     REQUESTOR                                                                   CONDITION
    csr-bfd72   5m26s   system:node:ip-10-0-50-126.us-east-2.compute.internal                       Pending
    csr-c57lv   5m26s   system:node:ip-10-0-95-157.us-east-2.compute.internal                       Pending
    ...

  5. 如果剩余的 CSR 没有被批准,且处于 Pending 状态,请批准集群机器的 CSR:

    • 要单独批准,请对每个有效的 CSR 运行以下命令:

      $ oc adm certificate approve <csr_name> 1
      1
      <csr_name> 是当前 CSR 列表中 CSR 的名称。
    • 要批准所有待处理的 CSR,请运行以下命令:

      $ oc get csr -o go-template='{{range .items}}{{if not .status}}{{.metadata.name}}{{"\n"}}{{end}}{{end}}' | xargs oc adm certificate approve
  6. 批准所有客户端和服务器 CSR 后,机器将 处于 Ready 状态。运行以下命令验证:

    $ oc get nodes

    输出示例

    NAME      STATUS    ROLES   AGE  VERSION
    master-0  Ready     master  73m  v1.25.0
    master-1  Ready     master  73m  v1.25.0
    master-2  Ready     master  74m  v1.25.0
    worker-0  Ready     worker  11m  v1.25.0
    worker-1  Ready     worker  11m  v1.25.0

    注意

    批准服务器 CSR 后可能需要几分钟时间让机器过渡到 Ready 状态

其他信息

6.13.22. 初始 Operator 配置

在 control plane 初始化后,您必须立即配置一些 Operator,以便它们都可用。

先决条件

  • 您的 control plane 已初始化。

流程

  1. 观察集群组件上线:

    $ watch -n5 oc get clusteroperators

    输出示例

    NAME                                       VERSION   AVAILABLE   PROGRESSING   DEGRADED   SINCE
    authentication                             4.12.0    True        False         False      19m
    baremetal                                  4.12.0    True        False         False      37m
    cloud-credential                           4.12.0    True        False         False      40m
    cluster-autoscaler                         4.12.0    True        False         False      37m
    config-operator                            4.12.0    True        False         False      38m
    console                                    4.12.0    True        False         False      26m
    csi-snapshot-controller                    4.12.0    True        False         False      37m
    dns                                        4.12.0    True        False         False      37m
    etcd                                       4.12.0    True        False         False      36m
    image-registry                             4.12.0    True        False         False      31m
    ingress                                    4.12.0    True        False         False      30m
    insights                                   4.12.0    True        False         False      31m
    kube-apiserver                             4.12.0    True        False         False      26m
    kube-controller-manager                    4.12.0    True        False         False      36m
    kube-scheduler                             4.12.0    True        False         False      36m
    kube-storage-version-migrator              4.12.0    True        False         False      37m
    machine-api                                4.12.0    True        False         False      29m
    machine-approver                           4.12.0    True        False         False      37m
    machine-config                             4.12.0    True        False         False      36m
    marketplace                                4.12.0    True        False         False      37m
    monitoring                                 4.12.0    True        False         False      29m
    network                                    4.12.0    True        False         False      38m
    node-tuning                                4.12.0    True        False         False      37m
    openshift-apiserver                        4.12.0    True        False         False      32m
    openshift-controller-manager               4.12.0    True        False         False      30m
    openshift-samples                          4.12.0    True        False         False      32m
    operator-lifecycle-manager                 4.12.0    True        False         False      37m
    operator-lifecycle-manager-catalog         4.12.0    True        False         False      37m
    operator-lifecycle-manager-packageserver   4.12.0    True        False         False      32m
    service-ca                                 4.12.0    True        False         False      38m
    storage                                    4.12.0    True        False         False      37m

  2. 配置不可用的 Operator。

6.13.22.1. 镜像 registry 存储配置

Amazon Web Services 提供默认存储,这意味着 Image Registry Operator 在安装后可用。但是,如果 Registry Operator 无法创建 S3 存储桶并自动配置存储,您需要手工配置 registry 存储。

示配置生产集群所需的持久性卷的说明。如果适用,显示有关将空目录配置为存储位置的说明,这仅适用于非生产集群。

另外还提供了在升级过程中使用 Recreate rollout 策略来允许镜像 registry 使用块存储类型的说明。

您可以在 AWS 中为用户置备的基础架构配置 registry 存储,以将 OpenShift Container Platform 部署到隐藏的区域。请参阅为 AWS 用户置备的基础架构配置 registry

6.13.22.1.1. 为使用用户置备的基础架构的 AWS 配置 registry 存储

在安装过程中,使用您的云凭据就可以创建一个 Amazon S3 存储桶,Registry Operator 将会自动配置存储。

如果 Registry Operator 无法创建 S3 存储桶或自动配置存储,您可以按照以下流程创建 S3 存储桶并配置存储。

先决条件

  • 在带有用户置备的基础架构的 AWS 上有一个集群。
  • 对于 Amazon S3 存储,secret 应该包含以下两个键:

    • REGISTRY_STORAGE_S3_ACCESSKEY
    • REGISTRY_STORAGE_S3_SECRETKEY

流程

如果 Registry Operator 无法创建 S3 存储桶并自动配置存储,请进行以下操作。

  1. 设置一个 Bucket Lifecycle Policy用来终止已有一天之久的未完成的分段上传操作。
  2. configs.imageregistry.operator.openshift.io/cluster中中输入存储配置:

    $ oc edit configs.imageregistry.operator.openshift.io/cluster

    配置示例

    storage:
      s3:
        bucket: <bucket-name>
        region: <region-name>

警告

为了保护 AWS 中 registry 镜像的安全,阻止对 S3 存储桶的公共访问

6.13.22.1.2. 在非生产集群中配置镜像 registry 存储

您必须为 Image Registry Operator 配置存储。对于非生产集群,您可以将镜像 registry 设置为空目录。如果您这样做,重启 registry 时会丢失所有镜像。

流程

  • 将镜像 registry 存储设置为空目录:

    $ oc patch configs.imageregistry.operator.openshift.io cluster --type merge --patch '{"spec":{"storage":{"emptyDir":{}}}}'
    警告

    仅为非生产集群配置这个选项。

    如果在 Image Registry Operator 初始化其组件前运行这个命令,oc patch 命令会失败并显示以下错误:

    Error from server (NotFound): configs.imageregistry.operator.openshift.io "cluster" not found

    等待几分钟,然后再次运行该命令。

6.13.23. 删除 bootstrap 资源:

完成集群的初始 Operator 配置后,从 Amazon Web Services (AWS) 中删除 bootstrap 资源。

先决条件

  • 已为集群完成初始的 Operator 配置。

流程

  1. 删除 bootstrap 资源。如果您使用了 CloudFormation 模板,请删除其堆栈

    • 使用 AWS CLI 删除堆栈:

      $ aws cloudformation delete-stack --stack-name <name> 1
      1
      <name> 是 bootstrap 堆栈的名称。
    • 使用 AWS CloudFormation 控制台删除堆栈。

6.13.24. 创建 Ingress DNS 记录

如果您删除了 DNS 区配置,请手动创建指向 Ingress 负载均衡器的 DNS 记录。您可以创建一个 wildcard 记录或具体的记录。以下流程使用了 A 记录,但您可以使用其他所需记录类型,如 CNAME 或别名。

先决条件

流程

  1. 决定要创建的路由。

    • 要创建一个 wildcard 记录,请使用 *.apps.<cluster_name>.<domain_name>,其中 <cluster_name> 是集群名称,<domain_name> 是 OpenShift Container Platform 集群的 Route 53 基域。
    • 要创建特定的记录,您必须为集群使用的每个路由创建一个记录,如下所示:

      $ oc get --all-namespaces -o jsonpath='{range .items[*]}{range .status.ingress[*]}{.host}{"\n"}{end}{end}' routes

      输出示例

      oauth-openshift.apps.<cluster_name>.<domain_name>
      console-openshift-console.apps.<cluster_name>.<domain_name>
      downloads-openshift-console.apps.<cluster_name>.<domain_name>
      alertmanager-main-openshift-monitoring.apps.<cluster_name>.<domain_name>
      prometheus-k8s-openshift-monitoring.apps.<cluster_name>.<domain_name>

  2. 获取 Ingress Operator 负载均衡器状态,并记录其使用的外部 IP 地址值,如 EXTERNAL-IP 列所示:

    $ oc -n openshift-ingress get service router-default

    输出示例

    NAME             TYPE           CLUSTER-IP      EXTERNAL-IP                            PORT(S)                      AGE
    router-default   LoadBalancer   172.30.62.215   ab3...28.us-east-2.elb.amazonaws.com   80:31499/TCP,443:30693/TCP   5m

  3. 为负载均衡器定位托管区 ID:

    $ aws elb describe-load-balancers | jq -r '.LoadBalancerDescriptions[] | select(.DNSName == "<external_ip>").CanonicalHostedZoneNameID' 1
    1
    对于 <external_ip>,请指定您获取的 Ingress Operator 负载均衡器的外部 IP 地址值。

    输出示例

    Z3AADJGX6KTTL2

    这个命令的输出是负载均衡器托管区 ID。

  4. 获取集群域的公共托管区 ID:

    $ aws route53 list-hosted-zones-by-name \
                --dns-name "<domain_name>" \ 1
                --query 'HostedZones[? Config.PrivateZone != `true` && Name == `<domain_name>.`].Id' 2
                --output text
    1 2
    对于 <domain_name>,请为 OpenShift Container Platform 集群指定 Route 53 基域。

    输出示例

    /hostedzone/Z3URY6TWQ91KVV

    命令输出中会显示您的域的公共托管区 ID。在本例中是 Z3URY6TWQ91KVV

  5. 在您的私有区中添加别名记录:

    $ aws route53 change-resource-record-sets --hosted-zone-id "<private_hosted_zone_id>" --change-batch '{ 1
    >   "Changes": [
    >     {
    >       "Action": "CREATE",
    >       "ResourceRecordSet": {
    >         "Name": "\\052.apps.<cluster_domain>", 2
    >         "Type": "A",
    >         "AliasTarget":{
    >           "HostedZoneId": "<hosted_zone_id>", 3
    >           "DNSName": "<external_ip>.", 4
    >           "EvaluateTargetHealth": false
    >         }
    >       }
    >     }
    >   ]
    > }'
    1
    对于 <private_hosted_zone_id>,指定 DNS 和负载均衡的 CloudFormation 模板输出的值。
    2
    对于 <cluster_domain>,请指定用于 OpenShift Container Platform 集群的域或子域。
    3
    对于 <hosted_zone_id>,请为您获得的负载均衡器指定公共托管区 ID。
    4
    对于 <external_ip>,请指定 Ingress Operator 负载均衡器的外部 IP 地址值。请确定在该参数值中包含最后的句点(.)。
  6. 在您的公共区中添加记录:

    $ aws route53 change-resource-record-sets --hosted-zone-id "<public_hosted_zone_id>"" --change-batch '{ 1
    >   "Changes": [
    >     {
    >       "Action": "CREATE",
    >       "ResourceRecordSet": {
    >         "Name": "\\052.apps.<cluster_domain>", 2
    >         "Type": "A",
    >         "AliasTarget":{
    >           "HostedZoneId": "<hosted_zone_id>", 3
    >           "DNSName": "<external_ip>.", 4
    >           "EvaluateTargetHealth": false
    >         }
    >       }
    >     }
    >   ]
    > }'
    1
    对于 <public_hosted_zone_id>,请为您的域指定公共托管区。
    2
    对于 <cluster_domain>,请指定用于 OpenShift Container Platform 集群的域或子域。
    3
    对于 <hosted_zone_id>,请为您获得的负载均衡器指定公共托管区 ID。
    4
    对于 <external_ip>,请指定 Ingress Operator 负载均衡器的外部 IP 地址值。请确定在该参数值中包含最后的句点(.)。

6.13.25. 在用户置备的基础架构上完成 AWS 安装

在用户置备的基础架构 Amazon Web Service (AWS) 上启动 OpenShift Container Platform 安装后,监视进程并等待安装完成。

先决条件

  • 您在用户置备的 AWS 基础架构上为 OpenShift Container Platform 集群删除了 bootstrap 节点。
  • 已安装 oc CLI。

流程

  • 在包含安装程序的目录中完成集群安装:

    $ ./openshift-install --dir <installation_directory> wait-for install-complete 1
    1
    对于 <installation_directory>,请指定安装文件保存到的目录的路径。

    输出示例

    INFO Waiting up to 40m0s for the cluster at https://api.mycluster.example.com:6443 to initialize...
    INFO Waiting up to 10m0s for the openshift-console route to be created...
    INFO Install complete!
    INFO To access the cluster as the system:admin user when using 'oc', run 'export KUBECONFIG=/home/myuser/install_dir/auth/kubeconfig'
    INFO Access the OpenShift web-console here: https://console-openshift-console.apps.mycluster.example.com
    INFO Login to the console with user: "kubeadmin", and password: "password"
    INFO Time elapsed: 1s

    重要
    • 安装程序生成的 Ignition 配置文件包含在 24 小时后过期的证书,然后在过期时进行续订。如果在更新证书前关闭集群,且集群在 24 小时后重启,集群会自动恢复过期的证书。一个例外是,您必须手动批准待处理的 node-bootstrapper 证书签名请求(CSR)来恢复 kubelet 证书。如需更多信息,请参阅从过期的 control plane 证书 中恢复的文档。
    • 建议您在 Ignition 配置文件生成后的 12 小时内使用它们,因为 24 小时的证书会在集群安装后的 16 小时到 22 小时间进行轮转。通过在 12 小时内使用 Ignition 配置文件,您可以避免在安装过程中因为执行了证书更新而导致安装失败的问题。

6.13.26. 使用 Web 控制台登录到集群

kubeadmin 用户默认在 OpenShift Container Platform 安装后存在。您可以使用 OpenShift Container Platform Web 控制台以 kubeadmin 用户身份登录集群。

先决条件

  • 有访问安装主机的访问权限。
  • 您完成了集群安装,所有集群 Operator 都可用。

流程

  1. 从安装主机上的 kubeadmin -password 文件中获取 kubeadmin 用户的密码:

    $ cat <installation_directory>/auth/kubeadmin-password
    注意

    另外,您还可以从安装主机上的 <installation_directory>/.openshift_install.log 日志文件获取 kubeadmin 密码。

  2. 列出 OpenShift Container Platform Web 控制台路由:

    $ oc get routes -n openshift-console | grep 'console-openshift'
    注意

    另外,您还可以从安装主机上的 <installation_directory>/.openshift_install.log 日志 文件获取 OpenShift Container Platform 路由。

    输出示例

    console     console-openshift-console.apps.<cluster_name>.<base_domain>            console     https   reencrypt/Redirect   None

  3. 在 Web 浏览器中导航到上一命令输出中包括的路由,以 kubeadmin 用户身份登录。

6.13.27. OpenShift Container Platform 的 Telemetry 访问

在 OpenShift Container Platform 4.12 中,默认运行的 Telemetry 服务提供有关集群健康状况和成功更新的指标,需要访问互联网。如果您的集群连接到互联网,Telemetry 会自动运行,并且集群会注册到 OpenShift Cluster Manager Hybrid Cloud Console

确认 OpenShift Cluster Manager Hybrid Cloud Console 清单正确后,可以由 Telemetry 自动维护,也可以使用 OpenShift Cluster Manager 手动维护,使用订阅监控来跟踪帐户或多集群级别的 OpenShift Container Platform 订阅。

其他资源

6.13.28. 其他资源

6.13.29. 后续步骤