在 AWS 上安装
在 AWS 上安装 OpenShift Container Platform 4.3
摘要
第 1 章 在 AWS 上安装
1.1. 配置 AWS 帐户
在安装 OpenShift Container Platform 之前,您必须先配置 Amazon Web Services (AWS) 帐户。
1.1.1. 配置 Route53
要安装 OpenShift Container Platform,您使用的 Amazon Web Services (AWS) 帐户必须在 Route53 服务中有一个专用的公共托管区。此区域必须对域具有权威。Route53 服务为集群外部连接提供集群 DNS 解析和名称查询。
流程
标识您的域或子域,以及注册商(registrar)。您可以转移现有的域和注册商,或通过 AWS 或其他来源获取新的域和注册商。
注意如果您通过 AWS 购买了一个新域,则需要一定时间来传播相关的 DNS 更改信息。有关通过 AWS 购买域的更多信息,请参阅 AWS 文档中的使用 Amazon Route 53 注册域名。
- 如果您使用现有的域和注册商,请将其 DNS 迁移到 AWS。请参阅 AWS 文档中的使 Amazon Route 53 成为现有域的 DNS 服务。
为您的域或子域创建一个公共托管区。请参阅 AWS 文档中的创建公共托管区。
使用合适的根域(如
openshiftcorp.com
)或子域(如clusters.openshiftcorp.com
)。- 从托管区记录中提取新的权威名称服务器。请参阅 AWS 文档中的获取公共托管区的名称服务器。
- 更新域所用 AWS Route53 名称服务器的注册商记录。例如,如果您将域注册到不同帐户中的 Route53 服务,请参阅 AWS 文档中的以下主题:添加或更改名称服务器或粘附记录。
- 如果使用子域,请将其委托记录添加到父域中。这为子域赋予 Amazon Route53 责任。按照父域的 DNS 供应商概述的委托程序。请参阅 创建使用 Amazon Route 53 作为 DNS 服务的子域,而无需迁移 AWS 文档 中的父域以获取示例高级流程。
1.1.2. AWS 帐户限值
OpenShift Container Platform 集群使用诸多 Amazon Web Services (AWS) 组件,默认的服务限值会影响您安装 OpenShift Container Platform 集群的能力。如果您使用特定的集群配置,在某些 AWS 区域部署集群,或者从您的帐户运行多个集群,您可能需要为 AWS 帐户请求其他资源。
下表总结了 AWS 组件,它们的限值可能会影响您安装和运行 OpenShift Container Platform 集群的能力。
组件 | 默认可用的集群数 | 默认 AWS 限值 | 描述 |
---|---|---|---|
实例限值 | 可变 | 可变 | 默认情况下,每个集群创建以下实例:
这些实例类型数量在新帐户的默认限值之内。若要部署更多 worker 节点、启用自动扩展、部署大型工作负载或使用不同的实例类型,请检查您的帐户限制,以确保集群可以部署您需要的机器。
在大多数区域里,Bootstrap 和 worker 机器使用 |
弹性 IP (EIP) | 0 到 1 | 每个帐户 5 个 EIP | 要在高可用性配置中置备集群,安装程序将为区域中的每个可用区创建一个公共和专用子网。每个专用子网都需要 NAT 网关,每个 NAT 网关需要单独的弹性 IP。查看 AWS 区域图来确定每个区域有多少个可用区。要利用默认高可用性,请在至少含有三个可用区的区域安装集群。要在有超过五个可用区的区域安装集群,您必须提高 EIP 限值。 重要
要使用 |
虚拟私有云 (VPC) | 5 | 每个区域 5 个 VPC | 每个集群创建自己的 VPC。 |
弹性负载均衡 (ELB/NLB) | 3 | 每个区域 20 个 | 在默认情况下,每个集群为 master API 服务器创建一个内部和外部网络负载均衡器,并为路由器创建一个典型的弹性负载均衡器。部署更多 Kubernetes LoadBalancer Service 对象将生成额外的负载均衡器。 |
NAT 网关 | 5 | 每个可用区 5 个 | 集群在每个可用区中部署一个 NAT 网关。 |
弹性网络接口 (ENI) | 至少 12 个 | 每个区域 350 个 |
默认安装创建 21 个 ENI,并为区域中的每个可用区创建一个 ENI。例如, 针对根据集群使用情况和部署的工作负载创建的额外机器和弹性负载均衡器,为其创建额外的 ENI。 |
VPC 网关 | 20 | 每个帐户 20 个 | 每个集群创建一个 VPC 网关来访问 S3。 |
S3 存储桶 | 99 | 每个帐户有 100 个存储桶 | 因为安装过程会创建一个临时存储桶,并且每个集群中的 registry 组件会创建一个存储桶,所以您只能为每个 AWS 帐户创建 99 个 OpenShift Container Platform 集群。 |
安全组 | 250 | 每个帐户 2,500 个 | 每个集群创建 10 个不同的安全组。 |
1.1.3. 所需的 AWS 权限
将 AdministratorAccess
策略附加到您在 Amazon Web Services (AWS) 中创建的 IAM 用户时,授予该用户所有需要的权限。要部署 OpenShift Container Platform 集群的所有组件,IAM 用户需要以下权限:
安装所需的 EC2 权限
-
ec2:AllocateAddress
-
ec2:AssociateAddress
-
ec2:AuthorizeSecurityGroupEgress
-
ec2:AuthorizeSecurityGroupIngress
-
ec2:CopyImage
-
ec2:CreateNetworkInterface
-
ec2:CreateSecurityGroup
-
ec2:CreateTags
-
ec2:CreateVolume
-
ec2:DeleteSecurityGroup
-
ec2:DeleteSnapshot
-
ec2:DeregisterImage
-
ec2:DescribeAccountAttributes
-
ec2:DescribeAddresses
-
ec2:DescribeAvailabilityZones
-
ec2:DescribeDhcpOptions
-
ec2:DescribeImages
-
ec2:DescribeInstanceAttribute
-
ec2:DescribeInstanceCreditSpecifications
-
ec2:DescribeInstances
-
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:ModifyInstanceAttribute
-
ec2:ModifyNetworkInterfaceAttribute
-
ec2:ReleaseAddress
-
ec2:RevokeSecurityGroupEgress
-
ec2:RevokeSecurityGroupIngress
-
ec2:RunInstances
-
ec2:TerminateInstances
安装过程中创建网络资源所需的权限
-
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,您的帐户不需要这些权限来创建网络资源。
安装所需的 Elasticloadbalancing 权限
-
elasticloadbalancing:AddTags
-
elasticloadbalancing:ApplySecurityGroupsToLoadBalancer
-
elasticloadbalancing:AttachLoadBalancerToSubnets
-
elasticloadbalancing:ConfigureHealthCheck
-
elasticloadbalancing:CreateListener
-
elasticloadbalancing:CreateLoadBalancer
-
elasticloadbalancing:CreateLoadBalancerListeners
-
elasticloadbalancing:CreateTargetGroup
-
elasticloadbalancing:DeleteLoadBalancer
-
elasticloadbalancing:DeregisterInstancesFromLoadBalancer
-
elasticloadbalancing:DeregisterTargets
-
elasticloadbalancing:DescribeInstanceHealth
-
elasticloadbalancing:DescribeListeners
-
elasticloadbalancing:DescribeLoadBalancerAttributes
-
elasticloadbalancing:DescribeLoadBalancers
-
elasticloadbalancing:DescribeTags
-
elasticloadbalancing:DescribeTargetGroupAttributes
-
elasticloadbalancing:DescribeTargetHealth
-
elasticloadbalancing:ModifyLoadBalancerAttributes
-
elasticloadbalancing:ModifyTargetGroup
-
elasticloadbalancing:ModifyTargetGroupAttributes
-
elasticloadbalancing:RegisterInstancesWithLoadBalancer
-
elasticloadbalancing:RegisterTargets
-
elasticloadbalancing:SetLoadBalancerPoliciesOfListener
安装所需的 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
安装所需的 Route53 权限
-
route53:ChangeResourceRecordSets
-
route53:ChangeTagsForResource
-
route53:CreateHostedZone
-
route53:DeleteHostedZone
-
route53:GetChange
-
route53:GetHostedZone
-
route53:ListHostedZones
-
route53:ListHostedZonesByName
-
route53:ListResourceRecordSets
-
route53:ListTagsForResource
-
route53:UpdateHostedZoneComment
安装所需的 S3 权限
-
s3:CreateBucket
-
s3:DeleteBucket
-
s3:GetAccelerateConfiguration
-
s3:GetBucketCors
-
s3:GetBucketLocation
-
s3:GetBucketLogging
-
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
集群 Operators 所需的 S3 权限
-
s3:DeleteObject
-
s3:GetObject
-
s3:GetObjectAcl
-
s3:GetObjectTagging
-
s3:GetObjectVersion
-
s3:PutObject
-
s3:PutObjectAcl
-
s3:PutObjectTagging
删除基本集群资源所需的权限
-
autoscaling:DescribeAutoScalingGroups
-
ec2:DeleteNetworkInterface
-
ec2:DeleteVolume
-
elasticloadbalancing:DeleteTargetGroup
-
elasticloadbalancing:DescribeTargetGroups
-
iam:ListInstanceProfiles
-
iam:ListRolePolicies
-
iam:ListUserPolicies
-
s3:DeleteObject
-
tag:GetResources
删除网络资源所需的权限
-
ec2:DeleteDhcpOptions
-
ec2:DeleteInternetGateway
-
ec2:DeleteNatGateway
-
ec2:DeleteRoute
-
ec2:DeleteRouteTable
-
ec2:DeleteSubnet
-
ec2:DeleteVpc
-
ec2:DeleteVpcEndpoints
-
ec2:DetachInternetGateway
-
ec2:DisassociateRouteTable
-
ec2:ReplaceRouteTableAssociation
如果您使用现有的 VPC,您的帐户不需要这些权限来删除网络资源。
创建清单所需的额外 IAM 和 S3 权限
-
iam:CreateAccessKey
-
iam:CreateUser
-
iam:DeleteAccessKey
-
iam:DeleteUser
-
iam:DeleteUserPolicy
-
iam:GetUserPolicy
-
iam:ListAccessKeys
-
iam:PutUserPolicy
-
iam:TagUser
-
iam:GetUserPolicy
-
iam:ListAccessKeys
-
s3:PutBucketPublicAccessBlock
-
s3:GetBucketPublicAccessBlock
-
s3:PutLifecycleConfiguration
-
s3:HeadBucket
-
s3:ListBucketMultipartUploads
-
s3:AbortMultipartUpload
1.1.4. 创建 IAM 用户
每个 Amazon Web Services (AWS) 帐户都包含一个根用户帐户,它基于您用来创建帐户的电子邮件地址。这是一个高权限帐户,建议仅用于初始帐户和账单配置、创建初始用户集,以及保护帐户安全。
在安装 OpenShift Container Platform 之前,请创建一个辅助 IAM 管理用户。完成 AWS 文档中所述的在 AWS 帐户中创建 IAM 用户流程时,请设置以下选项:
流程
-
指定 IAM 用户名并选择
Programmatic access
。 附加
AdministratorAccess
策略,以确保帐户有充足的权限来创建集群。此策略让集群能够为每个 OpenShift Container Platform 组件授予凭证。集群只为组件授予它们需要的凭证。注意虽然可以创建赋予所有所需 AWS 权限的策略并将其附加到用户,但这不是首选的选项。集群将无法为各个组件授予额外的凭证,因此所有组件都使用相同的凭证。
- 可选:通过附加标签向用户添加元数据。
-
确认您指定的用户名被授予了
AdministratorAccess
策略。 记录访问密钥 ID 和 Secret 访问密钥值。在配置本地机器时,您必须使用这些值来运行安装程序。
重要在部署集群时,您无法在使用多因素验证设备来验证 AWS 的同时使用您生成的临时会话令牌。在集群的整个生命周期中,集群会持续使用您的当前 AWS 凭证来创建 AWS 资源,因此您必须使用基于密钥的长期凭证。
1.1.5. 支持的 AWS 区域
您可以将 OpenShift Container Platform 集群部署到以下区域:
- ap-northeast-1(东京)
- ap-northeast-2 (首尔)
- ap-south-1(孟买)
- ap-southeast-1(新加坡)
- ap-southeast-2(悉尼)
- ca-central-1(中部)
- eu-central-1(法拉克福)
- eu-north-1(斯德哥尔摩)
- eu-west-1(爱尔兰)
- eu-west-2(伦敦)
- eu-west-3(巴黎)
- sa-east-1 (圣保罗)
- us-east-1(北弗吉尼亚)
- us-east-2(俄亥俄)
- us-west-1(北加利福尼亚)
- us-west-2(俄勒冈)
1.1.6. 后续步骤
安装 OpenShift Container Platform 集群:
1.2. 在 AWS 上快速安装集群
在 OpenShift Container Platform 版本 4.3 中,您可以使用默认配置选项在 Amazon Web Services (AWS) 上安装集群。
1.2.1. 先决条件
- 查看有关 OpenShift Container Platform 安装和更新流程的详细信息。
配置 AWS 帐户以托管集群。
重要如果您的计算机上存储有 AWS 配置集,则不要在使用多因素验证设备的同时使用您生成的临时会话令牌。在集群的整个生命周期中,集群会持续使用您的当前 AWS 凭证来创建 AWS 资源,因此您必须使用基于密钥的长期凭证。要生成适当的密钥,请参阅 AWS 文档中的管理 IAM 用户的访问密钥。您可在运行安装程序时提供密钥。
- 如果使用防火墙,则必须将其配置为允许集群需要访问的站点。
- 如果不允许系统管理身份和访问管理(IAM),集群管理员可以手动创建和维护 IAM 凭证。手动模式也可以用于云 IAM API 无法访问的环境中。
1.2.2. OpenShift Container Platform 对互联网和 Telemetry 的访问
在 OpenShift Container Platform 4.3 中,您需要访问互联网来安装集群。默认运行的 Telemetry 服务提供有关集群健康状况和成功更新的指标,这也需要访问互联网。如果您的集群连接到互联网,Telemetry 会自动运行,而且集群会注册到 Red Hat OpenShift Cluster Manager(OCM)。
确认 Red Hat OpenShift Cluster Manager 清单正确后,可以由 Telemetry 自动维护,也可以使用 OCM 手动维护,使用订阅监控 来跟踪帐户或多集群级别的 OpenShift Container Platform 订阅。
您必须具有以下互联网访问权限:
- 访问 Red Hat OpenShift Cluster Manager 页面,以下载安装程序并执行订阅管理。如果集群可以访问互联网,并且没有禁用 Telemetry,该服务会自动授权您的集群。
- 访问 Quay.io,以获取安装集群所需的软件包。
- 获取执行集群更新所需的软件包。
如果您的集群无法直接访问互联网,则可以在置备的某些类基础架构上执行受限网络安装。在此过程中,您要下载所需的内容,并使用它在镜像 registry(mirror registry) 中填充安装集群并生成安装程序所需的软件包。对于某些安装类型,集群要安装到的环境不需要访问互联网。在更新集群之前,要更新 registry 镜像系统中的内容。
1.2.3. 生成 SSH 私钥并将其添加到代理中
如果要在集群上执行安装调试或灾难恢复,则必须为 ssh-agent
和安装程序提供 SSH 密钥。
在生产环境中,您需要进行灾难恢复和调试。
您可以使用此密钥以 core
用户身份通过 SSH 连接到 master 节点。在部署集群时,此密钥会添加到 core
用户的 ~/.ssh/authorized_keys
列表中。
您必须使用一个本地密钥,而不要使用在特定平台上配置的密钥,如 AWS 密钥对。
流程
如果还没有为计算机上免密码身份验证而配置的 SSH 密钥,请创建一个。例如,在使用 Linux 操作系统的计算机上运行以下命令:
$ ssh-keygen -t rsa -b 4096 -N '' \ -f <path>/<file_name> 1
- 1
- 指定 SSH 密钥的路径和文件名,如
~/.ssh/id_rsa
。不要指定已存在的 SSH 密钥,因为它会被覆盖。
运行此命令会在指定的位置生成不需要密码的 SSH 密钥。
作为后台任务启动
ssh-agent
进程:$ eval "$(ssh-agent -s)" Agent pid 31874
将 SSH 私钥添加到
ssh-agent
:$ ssh-add <path>/<file_name> 1 Identity added: /home/<you>/<path>/<file_name> (<computer_name>)
- 1
- 指定 SSH 私钥的路径和文件名,如
~/.ssh/id_rsa
后续步骤
- 在安装 OpenShift Container Platform 时,为安装程序提供 SSH 公钥。
1.2.4. 获取安装程序
在安装 OpenShift Container Platform 之前,将安装文件下载到本地计算机上。
先决条件
- 必须从使用 Linux 或 macOS 的计算机安装集群。
- 需要 500 MB 本地磁盘空间来下载安装程序。
流程
- 访问 Red Hat OpenShift Cluster Manager 网站的 Infrastructure Provider 页面。如果您有红帽帐号,请使用自己的凭证登录。如果没有,请创建一个帐户。
进入适用于您的安装类型的页面,下载您的操作系统的安装程序,并将文件放在要保存安装配置文件的目录中。。
重要安装程序会在用来安装集群的计算机上创建若干文件。在完成集群安装后,您必须保留安装程序和安装程序所创建的文件。
重要删除安装程序创建的文件不会删除您的集群,即使集群在安装过程中失败也是如此。您必须完成针对特定云供应商的 OpenShift Container Platform 卸载流程,才能完全删除您的集群。
提取安装程序。例如,在使用 Linux 操作系统的计算机上运行以下命令:
$ tar xvf <installation_program>.tar.gz
-
在 Red Hat OpenShift Cluster Manager 站点的 Pull Secret 页面中,下载您的安装 pull secret 的
.txt
文件。通过此 pull secret,您可以进行所含授权机构提供的服务的身份验证,这些服务包括为 OpenShift Container Platform 组件提供容器镜像的 Quay.io。
1.2.5. 部署集群
您可以在兼容云平台中安装 OpenShift Container Platform。
安装程序的 create cluster
命令只能在初始安装过程中运行一次。
先决条件
- 配置托管集群的云平台的帐户。
- 获取 OpenShift Container Platform 安装程序以及集群的 pull secret。
流程
运行安装程序:
$ ./openshift-install create cluster --dir=<installation_directory> \ 1 --log-level=info 2
重要指定一个空目录。一些安装信息,如 bootstrap X.509 证书,有较短的过期间隔,因此不要重复使用安装目录。如果要重复使用另一个集群安装中的个别文件,可以将其复制到您的目录中。但是,一些安装数据的文件名可能会在发行版本之间有所改变。从 OpenShift Container Platform 老版本中复制安装文件时要格外小心。
在提示符处提供值:
可选:选择用来访问集群机器的 SSH 密钥。
注意对于您要在其上执行安装调试或灾难恢复的生产环境 OpenShift Container Platform 集群,请指定
ssh-agent
进程使用的 SSH 密钥。- 选择 aws 作为目标平台。
- 如果计算机上没有保存 Amazon Web Services (AWS) 配置集,请为您配置用于运行安装程序的用户输入 AWS 访问密钥 ID 和 Secret 访问密钥。
- 选择要将集群部署到的 AWS 区域。
- 选择您为集群配置的 Route53 服务的基域。
- 为集群输入一个描述性名称。
- 粘贴从 Red Hat OpenShift Cluster Manager 站点的 Pull Secret 页面中获取的 pull secret。
注意如果您在主机上配置的云供应商帐户没有足够的权限来部署集群,安装过程将会停止,并且显示缺少的权限。
集群部署完成后,终端会显示访问集群的信息,包括指向其 Web 控制台的链接和
kubeadmin
用户的凭证。重要安装程序生成的 Ignition 配置文件中所含的证书会在 24 小时后过期。您必须以非降级状态持续运行集群 24 小时,以确保完成第一次证书轮转。
重要您不得删除安装程序或安装程序所创建的文件。需要这两者才能删除集群。
-
可选:从您用来安装集群的 IAM 帐户删除或禁用
AdministratorAccess
策略。
1.2.6. 通过下载二进制文件安装 CLI
您需要安装 CLI(oc
) 来使用命令行界面与 OpenShift Container Platform 进行交互。您可在 Linux 、Windows 或 macOS 上安装 oc
。
如果安装了旧版本的 oc
,则无法使用 OpenShift Container Platform 4.3 中的所有命令。下载并安装新版本的 oc
。
1.2.6.1. 在 Linux 上安装 CLI
您可以按照以下流程在 Linux 上安装 OpenShift CLI(oc
)二进制文件。
流程
- 访问 Red Hat OpenShift Cluster Manager 网站的 Infrastructure Provider 页面。
- 选择您的基础架构供应商及安装类型。
- 在 Command-line interface 部分,从下拉菜单中选择 Linux,并点 Download command-line tools。
解包存档:
$ tar xvzf <file>
把
oc
二进制代码放到PATH
中的目录中。执行以下命令可以查看当前的
PATH
设置:$ echo $PATH
安装 CLI 后,就可以使用oc
命令:
$ oc <command>
1.2.6.2. 在 Windows 上安装 CLI
您可以按照以下流程在 Windows 上安装 OpenShift CLI(oc
)二进制代码。
流程
- 访问 Red Hat OpenShift Cluster Manager 网站的 Infrastructure Provider 页面。
- 选择您的基础架构供应商及安装类型。
- 在 Command-line interface 部分,从下拉菜单中选择 Windows,点 Download command-line tools。
- 使用 ZIP 程序解压存档。
把
oc
二进制代码放到PATH
中的目录中。要查看您的
PATH
,请打开命令提示窗口并执行以下命令:C:\> path
安装 CLI 后,就可以使用oc
命令:
C:\> oc <command>
1.2.6.3. 在 macOS 上安装 CLI
您可以按照以下流程在 macOS 上安装 OpenShift CLI(oc
)二进制代码。
流程
- 访问 Red Hat OpenShift Cluster Manager 网站的 Infrastructure Provider 页面。
- 选择您的基础架构供应商及安装类型。
- 在 Command-line interface 部分,从下拉菜单中选择 MacOS,并点 Download command-line tools。
- 解包和解压存档。
将
oc
二进制文件移到 PATH 的目录中。要查看您的
PATH
,打开一个终端窗口并执行以下命令:$ echo $PATH
安装 CLI 后,就可以使用oc
命令:
$ oc <command>
1.2.7. 登录集群
您可以通过导出集群 kubeconfig
文件,以默认系统用户身份登录集群。kubeconfig
文件包含关于集群的信息,供 CLI 用于将客户端连接到正确集群和 API 服务器。该文件特只适用于一个特定的集群,在 OpenShift Container Platform 安装过程中创建。
先决条件
- 部署 OpenShift Container Platform 集群。
-
安装
oc
CLI。
流程
导出
kubeadmin
凭证:$ export KUBECONFIG=<installation_directory>/auth/kubeconfig 1
- 1
- 对于
<installation_directory>
,请指定安装文件保存到的目录的路径。
使用导出的配置,验证能否成功运行
oc
命令:$ oc whoami system:admin
1.2.8. 后续步骤
- 自定义集群。
- 若有需要,您可以选择不使用远程健康报告。
1.3. 使用自定义在 AWS 上安装集群
在 OpenShift Container Platform 版本 4.3 中,您可以在安装程序在 Amazon Web Services (AWS) 中置备的基础架构上安装自定义集群。要自定义安装,请在安装集群前修改 install-config.yaml
文件中的参数。
1.3.1. 先决条件
- 查看有关 OpenShift Container Platform 安装和更新流程的详细信息。
配置 AWS 帐户以托管集群。
重要如果您的计算机上存储有 AWS 配置集,则不要在使用多因素验证设备的同时使用您生成的临时会话令牌。在集群的整个生命周期中,集群会持续使用您的当前 AWS 凭证来创建 AWS 资源,因此您必须使用长期凭证。要生成适当的密钥,请参阅 AWS 文档中的管理 IAM 用户的访问密钥。您可在运行安装程序时提供密钥。
- 如果使用防火墙,则必须将其配置为允许集群需要访问的站点。
- 如果不允许系统管理身份和访问管理(IAM),集群管理员可以手动创建和维护 IAM 凭证。手动模式也可以用于云 IAM API 无法访问的环境中。
1.3.2. OpenShift Container Platform 对互联网和 Telemetry 的访问
在 OpenShift Container Platform 4.3 中,您需要访问互联网来安装集群。默认运行的 Telemetry 服务提供有关集群健康状况和成功更新的指标,这也需要访问互联网。如果您的集群连接到互联网,Telemetry 会自动运行,而且集群会注册到 Red Hat OpenShift Cluster Manager(OCM)。
确认 Red Hat OpenShift Cluster Manager 清单正确后,可以由 Telemetry 自动维护,也可以使用 OCM 手动维护,使用订阅监控 来跟踪帐户或多集群级别的 OpenShift Container Platform 订阅。
您必须具有以下互联网访问权限:
- 访问 Red Hat OpenShift Cluster Manager 页面,以下载安装程序并执行订阅管理。如果集群可以访问互联网,并且没有禁用 Telemetry,该服务会自动授权您的集群。
- 访问 Quay.io,以获取安装集群所需的软件包。
- 获取执行集群更新所需的软件包。
如果您的集群无法直接访问互联网,则可以在置备的某些类基础架构上执行受限网络安装。在此过程中,您要下载所需的内容,并使用它在镜像 registry(mirror registry) 中填充安装集群并生成安装程序所需的软件包。对于某些安装类型,集群要安装到的环境不需要访问互联网。在更新集群之前,要更新 registry 镜像系统中的内容。
1.3.3. 生成 SSH 私钥并将其添加到代理中
如果要在集群上执行安装调试或灾难恢复,则必须为 ssh-agent
和安装程序提供 SSH 密钥。
在生产环境中,您需要进行灾难恢复和调试。
您可以使用此密钥以 core
用户身份通过 SSH 连接到 master 节点。在部署集群时,此密钥会添加到 core
用户的 ~/.ssh/authorized_keys
列表中。
您必须使用一个本地密钥,而不要使用在特定平台上配置的密钥,如 AWS 密钥对。
流程
如果还没有为计算机上免密码身份验证而配置的 SSH 密钥,请创建一个。例如,在使用 Linux 操作系统的计算机上运行以下命令:
$ ssh-keygen -t rsa -b 4096 -N '' \ -f <path>/<file_name> 1
- 1
- 指定 SSH 密钥的路径和文件名,如
~/.ssh/id_rsa
。不要指定已存在的 SSH 密钥,因为它会被覆盖。
运行此命令会在指定的位置生成不需要密码的 SSH 密钥。
作为后台任务启动
ssh-agent
进程:$ eval "$(ssh-agent -s)" Agent pid 31874
将 SSH 私钥添加到
ssh-agent
:$ ssh-add <path>/<file_name> 1 Identity added: /home/<you>/<path>/<file_name> (<computer_name>)
- 1
- 指定 SSH 私钥的路径和文件名,如
~/.ssh/id_rsa
后续步骤
- 在安装 OpenShift Container Platform 时,为安装程序提供 SSH 公钥。
1.3.4. 获取安装程序
在安装 OpenShift Container Platform 之前,将安装文件下载到本地计算机上。
先决条件
- 必须从使用 Linux 或 macOS 的计算机安装集群。
- 需要 500 MB 本地磁盘空间来下载安装程序。
流程
- 访问 Red Hat OpenShift Cluster Manager 网站的 Infrastructure Provider 页面。如果您有红帽帐号,请使用自己的凭证登录。如果没有,请创建一个帐户。
进入适用于您的安装类型的页面,下载您的操作系统的安装程序,并将文件放在要保存安装配置文件的目录中。。
重要安装程序会在用来安装集群的计算机上创建若干文件。在完成集群安装后,您必须保留安装程序和安装程序所创建的文件。
重要删除安装程序创建的文件不会删除您的集群,即使集群在安装过程中失败也是如此。您必须完成针对特定云供应商的 OpenShift Container Platform 卸载流程,才能完全删除您的集群。
提取安装程序。例如,在使用 Linux 操作系统的计算机上运行以下命令:
$ tar xvf <installation_program>.tar.gz
-
在 Red Hat OpenShift Cluster Manager 站点的 Pull Secret 页面中,下载您的安装 pull secret 的
.txt
文件。通过此 pull secret,您可以进行所含授权机构提供的服务的身份验证,这些服务包括为 OpenShift Container Platform 组件提供容器镜像的 Quay.io。
1.3.5. 创建安装配置文件
您可以自定义 Amazon Web Services (AWS) 上的 OpenShift Container Platform 安装。
先决条件
- 获取 OpenShift Container Platform 安装程序以及集群的 pull secret。
流程
创建
install-config.yaml
文件。运行以下命令:
$ ./openshift-install create install-config --dir=<installation_directory> 1
- 1
- 对于
<installation_directory>
,请指定用于保存安装程序所创建的文件的目录名称。
重要指定一个空目录。一些安装信息,如 bootstrap X.509 证书,有较短的过期间隔,因此不要重复使用安装目录。如果要重复使用另一个集群安装中的个别文件,可以将其复制到您的目录中。但是,一些安装数据的文件名可能会在发行版本之间有所改变。从 OpenShift Container Platform 老版本中复制安装文件时要格外小心。
在提示符处,提供您的云的配置详情:
可选:选择用来访问集群机器的 SSH 密钥。
注意对于您要在其上执行安装调试或灾难恢复的生产环境 OpenShift Container Platform 集群,请指定
ssh-agent
进程使用的 SSH 密钥。- 选择 AWS 作为目标平台。
- 如果计算机上没有保存 Amazon Web Services (AWS) 配置集,请为您配置用于运行安装程序的用户输入 AWS 访问密钥 ID 和 Secret 访问密钥。
- 选择要将集群部署到的 AWS 区域。
- 选择您为集群配置的 Route53 服务的基域。
- 为集群输入一个描述性名称。
- 粘贴从 Red Hat OpenShift Cluster Manager 站点的 Pull Secret 页面中获取的 pull secret。
-
修改
install-config.yaml
文件。您可以在安装配置参数部分中找到有关可用参数的更多信息。 备份
install-config.yaml
文件,以便用于安装多个集群。重要install-config.yaml
文件会在安装过程中消耗掉。如果要重复使用此文件,必须现在备份。
1.3.5.1. 安装配置参数
在部署 OpenShift Container Platform 集群前,您可以提供参数值,以描述托管集群的云平台的帐户并选择性地自定义集群平台。在创建 install-config.yaml
安装配置文件时,您可以通过命令行来提供所需的参数的值。如果要自定义集群,可以修改 install-config.yaml
文件来提供关于平台的更多信息。
安装之后,您无法修改 install-config.yaml
文件中的这些参数。
参数 | 描述 | 值 |
---|---|---|
|
云供应商的基域。此值用于创建到 OpenShift Container Platform 集群组件的路由。集群的完整 DNS 名称是 |
完全限定域名或子域名,如 |
|
托管 control plane 机器的云供应商。此参数值必须与 |
|
|
托管 worker 机器的云供应商。此参数值必须与 |
|
| 集群的名称。 |
包含大写字母或小写字母的字符串,如 |
| 集群要部署到的区域。 |
云的有效区域,如 AWS 的 |
| 从 Red Hat OpenShift Cluster Manager 站点的 Pull Secret 页面中获取的 pull secret。您可以使用此 pull secret 来进行所含授权机构提供的服务的身份验证,这些服务包括为 OpenShift Container Platform 组件提供容器镜像的 Quay.io。 |
{ "auths":{ "cloud.openshift.com":{ "auth":"b3Blb=", "email":"you@example.com" }, "quay.io":{ "auth":"b3Blb=", "email":"you@example.com" } } } |
参数 | 描述 | 值 |
---|---|---|
| 用于访问集群机器的 SSH 密钥。 注意
对于您要在其上执行安装调试或灾难恢复的生产环境 OpenShift Container Platform 集群,请指定 |
添加到 |
| 是否启用或禁用 FIPS 模式。默认情况下不启用 FIPS 模式。如果启用了 FIPS 模式,运行 OpenShift Container Platform 的 Red Hat Enterprise Linux CoreOS (RHCOS) 机器会绕过默认的 Kubernetes 加密套件,并使用由 RHCOS 提供的加密模块。 |
|
| 如何发布集群的面向用户的端点。 |
|
|
是否在计算机器上启用或禁用并发多线程或 重要 如果禁用并发多线程,请确保在容量规划时考虑到机器性能可能会显著降低的问题。 |
|
| 要置备的计算机器数量,也称为 worker 机器。 |
大于或等于 |
|
是否在 control plane 机器上启用或禁用并发多线程或 重要 如果禁用并发多线程,请确保在容量规划时考虑到机器性能可能会显著降低的问题。 |
|
| 要置备的 control plane 机器数量。 |
大于或等于 |
参数 | 描述 | 值 |
---|---|---|
| 为根卷保留的每秒输入/输出操作 (IOPS) 数。 |
整数,如 |
| 以 GiB 为单位的根卷大小。 |
整数,如 |
| 根卷的实例类型。 |
有效的 AWS EBS 实例类型,如 |
| 计算机器的 EC2 实例类型。 |
有效的 AWS 实例类型,如 |
| 安装程序在其中为计算 MachinePool 创建机器的可用区。如果您提供自己的 VPC,则必须在那个可用域中提供一个子网。 |
有效 AWS 可用区的列表,如 |
| 安装程序在其中创建计算资源的 AWS 区域。 |
有效的 AWS 区域,如 |
| control plane 机器的 EC2 实例类型。 |
有效的 AWS 实例类型,如 |
| 安装程序在其中为 control plane MachinePool 创建机器的可用区。 |
有效 AWS 可用区的列表,如 |
| 安装程序在其中创建 control plane 资源的 AWS 区域。 |
有效的 AWS 区域,如 |
| 键与值的映射,安装程序将其作为标签添加到它所创建的所有资源。 |
任何有效的 YAML 映射,如 |
|
如果您提供 VPC,而不是让安装程序为您创建 VPC,请指定要使用的集群子网。子网必须是您指定的同一 | 有效的子网 ID。 |
1.3.5.2. AWS 的自定义 install-config.yaml
文件示例
您可以自定义 install-config.yaml
文件,以指定有关 OpenShift Container Platform 集群平台的更多信息,或修改所需参数的值。
此示例 YAML 文件仅供参考。您必须使用安装程序来获取 install-config.yaml
文件,并且修改该文件。
apiVersion: v1 baseDomain: example.com 1 controlPlane: 2 hyperthreading: Enabled 3 4 name: master platform: aws: zones: - us-west-2a - us-west-2b rootVolume: iops: 4000 size: 500 type: io1 type: m5.xlarge 5 replicas: 3 compute: 6 - hyperthreading: Enabled 7 name: worker platform: aws: rootVolume: iops: 2000 size: 500 type: io1 8 type: c5.4xlarge zones: - us-west-2c replicas: 3 metadata: name: test-cluster 9 networking: clusterNetwork: - cidr: 10.128.0.0/14 hostPrefix: 23 machineCIDR: 10.0.0.0/16 networkType: OpenShiftSDN serviceNetwork: - 172.30.0.0/16 platform: aws: region: us-west-2 10 userTags: adminContact: jdoe costCenter: 7536 pullSecret: '{"auths": ...}' 11 fips: false 12 sshKey: ssh-ed25519 AAAA... 13
- 1 9 10 11
- 必需。安装程序会提示您输入这个值。
- 2 6
- 如果没有提供这些参数和值,安装程序会提供默认值。
- 3 7
controlPlane
部分是一个单映射,但 compute 部分是一系列映射。为满足不同数据结构的要求,compute
部分的第一行必须以连字符-
开头,controlPlane
部分的第一行则不可以连字符开头。虽然这两个部分目前都定义单个机器池,但未来的 OpenShift Container Platform 版本可能会支持在安装过程中定义多个计算池。只使用一个 control plane 池。- 4 5
- 是否要启用或禁用并发多线程或
超线程
。默认情况下,启用并发多线程以提高机器内核的性能。您可以通过将参数值设为Disabled
来禁用。如果您在某些集群机器上禁用并发多线程,则必须在所有集群机器上禁用。重要如果禁用并发多线程,请确保在容量规划时考虑到机器性能可能会显著降低的问题。如果您对机器禁用并发多线程,请使用较大的实例类型,如
m4.2xlarge
或m5.2xlarge
。 - 8
- 要为 etcd 配置更快的存储,特别是对于较大的集群,请将存储类型设置为
io1
,并将iops
设为2000
。 - 12
- 是否启用或禁用 FIPS 模式。默认情况下不启用 FIPS 模式。如果启用了 FIPS 模式,运行 OpenShift Container Platform 的 Red Hat Enterprise Linux CoreOS (RHCOS) 机器会绕过默认的 Kubernetes 加密套件,并使用由 RHCOS 提供的加密模块。
- 13
- 您可以选择提供您用来访问集群中机器的
sshKey
值。注意对于您要在其上执行安装调试或灾难恢复的生产环境 OpenShift Container Platform 集群,请指定
ssh-agent
进程使用的 SSH 密钥。
1.3.6. 部署集群
您可以在兼容云平台中安装 OpenShift Container Platform。
安装程序的 create cluster
命令只能在初始安装过程中运行一次。
先决条件
- 配置托管集群的云平台的帐户。
- 获取 OpenShift Container Platform 安装程序以及集群的 pull secret。
流程
运行安装程序:
$ ./openshift-install create cluster --dir=<installation_directory> \ 1 --log-level=info 2
注意如果您在主机上配置的云供应商帐户没有足够的权限来部署集群,安装过程将会停止,并且显示缺少的权限。
集群部署完成后,终端会显示访问集群的信息,包括指向其 Web 控制台的链接和
kubeadmin
用户的凭证。重要安装程序生成的 Ignition 配置文件中所含的证书会在 24 小时后过期。您必须以非降级状态持续运行集群 24 小时,以确保完成第一次证书轮转。
重要您不得删除安装程序或安装程序所创建的文件。需要这两者才能删除集群。
-
可选:从您用来安装集群的 IAM 帐户删除或禁用
AdministratorAccess
策略。
1.3.7. 通过下载二进制文件安装 CLI
您需要安装 CLI(oc
) 来使用命令行界面与 OpenShift Container Platform 进行交互。您可在 Linux 、Windows 或 macOS 上安装 oc
。
如果安装了旧版本的 oc
,则无法使用 OpenShift Container Platform 4.3 中的所有命令。下载并安装新版本的 oc
。
1.3.7.1. 在 Linux 上安装 CLI
您可以按照以下流程在 Linux 上安装 OpenShift CLI(oc
)二进制文件。
流程
- 访问 Red Hat OpenShift Cluster Manager 网站的 Infrastructure Provider 页面。
- 选择您的基础架构供应商及安装类型。
- 在 Command-line interface 部分,从下拉菜单中选择 Linux,并点 Download command-line tools。
解包存档:
$ tar xvzf <file>
把
oc
二进制代码放到PATH
中的目录中。执行以下命令可以查看当前的
PATH
设置:$ echo $PATH
安装 CLI 后,就可以使用oc
命令:
$ oc <command>
1.3.7.2. 在 Windows 上安装 CLI
您可以按照以下流程在 Windows 上安装 OpenShift CLI(oc
)二进制代码。
流程
- 访问 Red Hat OpenShift Cluster Manager 网站的 Infrastructure Provider 页面。
- 选择您的基础架构供应商及安装类型。
- 在 Command-line interface 部分,从下拉菜单中选择 Windows,点 Download command-line tools。
- 使用 ZIP 程序解压存档。
把
oc
二进制代码放到PATH
中的目录中。要查看您的
PATH
,请打开命令提示窗口并执行以下命令:C:\> path
安装 CLI 后,就可以使用oc
命令:
C:\> oc <command>
1.3.7.3. 在 macOS 上安装 CLI
您可以按照以下流程在 macOS 上安装 OpenShift CLI(oc
)二进制代码。
流程
- 访问 Red Hat OpenShift Cluster Manager 网站的 Infrastructure Provider 页面。
- 选择您的基础架构供应商及安装类型。
- 在 Command-line interface 部分,从下拉菜单中选择 MacOS,并点 Download command-line tools。
- 解包和解压存档。
将
oc
二进制文件移到 PATH 的目录中。要查看您的
PATH
,打开一个终端窗口并执行以下命令:$ echo $PATH
安装 CLI 后,就可以使用oc
命令:
$ oc <command>
1.3.8. 登录集群
您可以通过导出集群 kubeconfig
文件,以默认系统用户身份登录集群。kubeconfig
文件包含关于集群的信息,供 CLI 用于将客户端连接到正确集群和 API 服务器。该文件特只适用于一个特定的集群,在 OpenShift Container Platform 安装过程中创建。
先决条件
- 部署 OpenShift Container Platform 集群。
-
安装
oc
CLI。
流程
导出
kubeadmin
凭证:$ export KUBECONFIG=<installation_directory>/auth/kubeconfig 1
- 1
- 对于
<installation_directory>
,请指定安装文件保存到的目录的路径。
使用导出的配置,验证能否成功运行
oc
命令:$ oc whoami system:admin
1.3.9. 后续步骤
- 自定义集群。
- 若有需要,您可以选择不使用远程健康报告。
1.4. 使用自定义网络在 AWS 上安装集群
在 OpenShift Container Platform 版本 4.3 中,您可以使用自定义网络配置选项在 Amazon Web Services (AWS) 上安装集群。通过自定义网络配置,您的集群可以与环境中现有的 IP 地址分配共存,并与现有的 MTU 和 VXLAN 配置集成。
大部分网络配置参数必须在安装过程中设置,只有 kubeProxy
配置参数可以在运行的集群中修改。
1.4.1. 先决条件
- 查看有关 OpenShift Container Platform 安装和更新流程的详细信息。
配置 AWS 帐户以托管集群。
重要如果您的计算机上存储有 AWS 配置集,则不要在使用多因素验证设备的同时使用您生成的临时会话令牌。在集群的整个生命周期中,集群会持续使用您的当前 AWS 凭证来创建 AWS 资源,因此您必须使用基于密钥的长期凭证。要生成适当的密钥,请参阅 AWS 文档中的管理 IAM 用户的访问密钥。您可在运行安装程序时提供密钥。
- 如果使用防火墙,则必须将其配置为允许集群需要访问的站点。
- 如果不允许系统管理身份和访问管理(IAM),集群管理员可以手动创建和维护 IAM 凭证。手动模式也可以用于云 IAM API 无法访问的环境中。
1.4.2. OpenShift Container Platform 对互联网和 Telemetry 的访问
在 OpenShift Container Platform 4.3 中,您需要访问互联网来安装集群。默认运行的 Telemetry 服务提供有关集群健康状况和成功更新的指标,这也需要访问互联网。如果您的集群连接到互联网,Telemetry 会自动运行,而且集群会注册到 Red Hat OpenShift Cluster Manager(OCM)。
确认 Red Hat OpenShift Cluster Manager 清单正确后,可以由 Telemetry 自动维护,也可以使用 OCM 手动维护,使用订阅监控 来跟踪帐户或多集群级别的 OpenShift Container Platform 订阅。
您必须具有以下互联网访问权限:
- 访问 Red Hat OpenShift Cluster Manager 页面,以下载安装程序并执行订阅管理。如果集群可以访问互联网,并且没有禁用 Telemetry,该服务会自动授权您的集群。
- 访问 Quay.io,以获取安装集群所需的软件包。
- 获取执行集群更新所需的软件包。
如果您的集群无法直接访问互联网,则可以在置备的某些类基础架构上执行受限网络安装。在此过程中,您要下载所需的内容,并使用它在镜像 registry(mirror registry) 中填充安装集群并生成安装程序所需的软件包。对于某些安装类型,集群要安装到的环境不需要访问互联网。在更新集群之前,要更新 registry 镜像系统中的内容。
1.4.3. 生成 SSH 私钥并将其添加到代理中
如果要在集群上执行安装调试或灾难恢复,则必须为 ssh-agent
和安装程序提供 SSH 密钥。
在生产环境中,您需要进行灾难恢复和调试。
您可以使用此密钥以 core
用户身份通过 SSH 连接到 master 节点。在部署集群时,此密钥会添加到 core
用户的 ~/.ssh/authorized_keys
列表中。
您必须使用一个本地密钥,而不要使用在特定平台上配置的密钥,如 AWS 密钥对。
流程
如果还没有为计算机上免密码身份验证而配置的 SSH 密钥,请创建一个。例如,在使用 Linux 操作系统的计算机上运行以下命令:
$ ssh-keygen -t rsa -b 4096 -N '' \ -f <path>/<file_name> 1
- 1
- 指定 SSH 密钥的路径和文件名,如
~/.ssh/id_rsa
。不要指定已存在的 SSH 密钥,因为它会被覆盖。
运行此命令会在指定的位置生成不需要密码的 SSH 密钥。
作为后台任务启动
ssh-agent
进程:$ eval "$(ssh-agent -s)" Agent pid 31874
将 SSH 私钥添加到
ssh-agent
:$ ssh-add <path>/<file_name> 1 Identity added: /home/<you>/<path>/<file_name> (<computer_name>)
- 1
- 指定 SSH 私钥的路径和文件名,如
~/.ssh/id_rsa
后续步骤
- 在安装 OpenShift Container Platform 时,为安装程序提供 SSH 公钥。
1.4.4. 获取安装程序
在安装 OpenShift Container Platform 之前,将安装文件下载到本地计算机上。
先决条件
- 必须从使用 Linux 或 macOS 的计算机安装集群。
- 需要 500 MB 本地磁盘空间来下载安装程序。
流程
- 访问 Red Hat OpenShift Cluster Manager 网站的 Infrastructure Provider 页面。如果您有红帽帐号,请使用自己的凭证登录。如果没有,请创建一个帐户。
进入适用于您的安装类型的页面,下载您的操作系统的安装程序,并将文件放在要保存安装配置文件的目录中。。
重要安装程序会在用来安装集群的计算机上创建若干文件。在完成集群安装后,您必须保留安装程序和安装程序所创建的文件。
重要删除安装程序创建的文件不会删除您的集群,即使集群在安装过程中失败也是如此。您必须完成针对特定云供应商的 OpenShift Container Platform 卸载流程,才能完全删除您的集群。
提取安装程序。例如,在使用 Linux 操作系统的计算机上运行以下命令:
$ tar xvf <installation_program>.tar.gz
-
在 Red Hat OpenShift Cluster Manager 站点的 Pull Secret 页面中,下载您的安装 pull secret 的
.txt
文件。通过此 pull secret,您可以进行所含授权机构提供的服务的身份验证,这些服务包括为 OpenShift Container Platform 组件提供容器镜像的 Quay.io。
1.4.5. 创建安装配置文件
您可以自定义 Amazon Web Services (AWS) 上的 OpenShift Container Platform 安装。
先决条件
- 获取 OpenShift Container Platform 安装程序以及集群的 pull secret。
流程
创建
install-config.yaml
文件。运行以下命令:
$ ./openshift-install create install-config --dir=<installation_directory> 1
- 1
- 对于
<installation_directory>
,请指定用于保存安装程序所创建的文件的目录名称。
重要指定一个空目录。一些安装信息,如 bootstrap X.509 证书,有较短的过期间隔,因此不要重复使用安装目录。如果要重复使用另一个集群安装中的个别文件,可以将其复制到您的目录中。但是,一些安装数据的文件名可能会在发行版本之间有所改变。从 OpenShift Container Platform 老版本中复制安装文件时要格外小心。
在提示符处,提供您的云的配置详情:
可选:选择用来访问集群机器的 SSH 密钥。
注意对于您要在其上执行安装调试或灾难恢复的生产环境 OpenShift Container Platform 集群,请指定
ssh-agent
进程使用的 SSH 密钥。- 选择 AWS 作为目标平台。
- 如果计算机上没有保存 Amazon Web Services (AWS) 配置集,请为您配置用于运行安装程序的用户输入 AWS 访问密钥 ID 和 Secret 访问密钥。
- 选择要将集群部署到的 AWS 区域。
- 选择您为集群配置的 Route53 服务的基域。
- 为集群输入一个描述性名称。
- 粘贴从 Red Hat OpenShift Cluster Manager 站点的 Pull Secret 页面中获取的 pull secret。
-
修改
install-config.yaml
文件。您可以在安装配置参数部分中找到有关可用参数的更多信息。 备份
install-config.yaml
文件,以便用于安装多个集群。重要install-config.yaml
文件会在安装过程中消耗掉。如果要重复使用此文件,必须现在备份。
1.4.5.1. 安装配置参数
在部署 OpenShift Container Platform 集群前,您可以提供参数值,以描述托管集群的云平台的帐户并选择性地自定义集群平台。在创建 install-config.yaml
安装配置文件时,您可以通过命令行来提供所需的参数的值。如果要自定义集群,可以修改 install-config.yaml
文件来提供关于平台的更多信息。
安装之后,您无法修改 install-config.yaml
文件中的这些参数。
参数 | 描述 | 值 |
---|---|---|
|
云供应商的基域。此值用于创建到 OpenShift Container Platform 集群组件的路由。集群的完整 DNS 名称是 |
完全限定域名或子域名,如 |
|
托管 control plane 机器的云供应商。此参数值必须与 |
|
|
托管 worker 机器的云供应商。此参数值必须与 |
|
| 集群的名称。 |
包含大写字母或小写字母的字符串,如 |
| 集群要部署到的区域。 |
云的有效区域,如 AWS 的 |
| 从 Red Hat OpenShift Cluster Manager 站点的 Pull Secret 页面中获取的 pull secret。您可以使用此 pull secret 来进行所含授权机构提供的服务的身份验证,这些服务包括为 OpenShift Container Platform 组件提供容器镜像的 Quay.io。 |
{ "auths":{ "cloud.openshift.com":{ "auth":"b3Blb=", "email":"you@example.com" }, "quay.io":{ "auth":"b3Blb=", "email":"you@example.com" } } } |
参数 | 描述 | 值 |
---|---|---|
| 用于访问集群机器的 SSH 密钥。 注意
对于您要在其上执行安装调试或灾难恢复的生产环境 OpenShift Container Platform 集群,请指定 |
添加到 |
| 是否启用或禁用 FIPS 模式。默认情况下不启用 FIPS 模式。如果启用了 FIPS 模式,运行 OpenShift Container Platform 的 Red Hat Enterprise Linux CoreOS (RHCOS) 机器会绕过默认的 Kubernetes 加密套件,并使用由 RHCOS 提供的加密模块。 |
|
| 如何发布集群的面向用户的端点。 |
|
|
是否在计算机器上启用或禁用并发多线程或 重要 如果禁用并发多线程,请确保在容量规划时考虑到机器性能可能会显著降低的问题。 |
|
| 要置备的计算机器数量,也称为 worker 机器。 |
大于或等于 |
|
是否在 control plane 机器上启用或禁用并发多线程或 重要 如果禁用并发多线程,请确保在容量规划时考虑到机器性能可能会显著降低的问题。 |
|
| 要置备的 control plane 机器数量。 |
大于或等于 |
参数 | 描述 | 值 |
---|---|---|
| 为根卷保留的每秒输入/输出操作 (IOPS) 数。 |
整数,如 |
| 以 GiB 为单位的根卷大小。 |
整数,如 |
| 根卷的实例类型。 |
有效的 AWS EBS 实例类型,如 |
| 计算机器的 EC2 实例类型。 |
有效的 AWS 实例类型,如 |
| 安装程序在其中为计算 MachinePool 创建机器的可用区。如果您提供自己的 VPC,则必须在那个可用域中提供一个子网。 |
有效 AWS 可用区的列表,如 |
| 安装程序在其中创建计算资源的 AWS 区域。 |
有效的 AWS 区域,如 |
| control plane 机器的 EC2 实例类型。 |
有效的 AWS 实例类型,如 |
| 安装程序在其中为 control plane MachinePool 创建机器的可用区。 |
有效 AWS 可用区的列表,如 |
| 安装程序在其中创建 control plane 资源的 AWS 区域。 |
有效的 AWS 区域,如 |
| 键与值的映射,安装程序将其作为标签添加到它所创建的所有资源。 |
任何有效的 YAML 映射,如 |
|
如果您提供 VPC,而不是让安装程序为您创建 VPC,请指定要使用的集群子网。子网必须是您指定的同一 | 有效的子网 ID。 |
Open Virtual Networking (OVN) Kubernetes 网络插件只是技术预览功能。技术预览功能不被红帽产品服务等级协议 (SLA) 支持,且可能在功能方面有缺陷。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。
如需 OVN 技术预览支持范围的更多信息,请参阅 https://access.redhat.com/articles/4380121。
1.4.5.2. 网络配置参数
您可以在 install-config.yaml
配置文件中修改集群网络配置参数。下表描述了这些参数。
安装之后,您无法修改 install-config.yaml
文件中的这些参数。
参数 | 描述 | 值 |
---|---|---|
|
要部署的默认 Container Network Interface(CNI)网络供应商插件。 |
|
|
从中分配 Pod IP 地址的 IP 地址块。 |
CIDR 格式的 IP 地址分配。默认值为 |
|
分配给每个单独节点的子网前缀长度。例如,如果 |
子网前缀。默认值为 |
|
服务的 IP 地址块。 |
CIDR 格式的 IP 地址分配。默认值为 |
| OpenShift Container Platform 安装程序在安装集群时使用的 IP 地址块。该地址块不得与任何其他网络块重叠。 |
CIDR 格式的 IP 地址分配。默认值为 |
1.4.5.3. AWS 的自定义 install-config.yaml
文件示例
您可以自定义 install-config.yaml
文件,以指定有关 OpenShift Container Platform 集群平台的更多信息,或修改所需参数的值。
此示例 YAML 文件仅供参考。您必须使用安装程序来获取 install-config.yaml
文件,并且修改该文件。
apiVersion: v1 baseDomain: example.com 1 controlPlane: 2 hyperthreading: Enabled 3 4 name: master platform: aws: zones: - us-west-2a - us-west-2b rootVolume: iops: 4000 size: 500 type: io1 type: m5.xlarge 5 replicas: 3 compute: 6 - hyperthreading: Enabled 7 name: worker platform: aws: rootVolume: iops: 2000 size: 500 type: io1 8 type: c5.4xlarge zones: - us-west-2c replicas: 3 metadata: name: test-cluster 9 networking: 10 clusterNetwork: - cidr: 10.128.0.0/14 hostPrefix: 23 machineCIDR: 10.0.0.0/16 networkType: OpenShiftSDN serviceNetwork: - 172.30.0.0/16 platform: aws: region: us-west-2 11 userTags: adminContact: jdoe costCenter: 7536 pullSecret: '{"auths": ...}' 12 fips: false 13 sshKey: ssh-ed25519 AAAA... 14
- 1 9 11 12
- 必需。安装程序会提示您输入这个值。
- 2 6 10
- 如果没有提供这些参数和值,安装程序会提供默认值。
- 3 7
controlPlane
部分是一个单映射,但 compute 部分是一系列映射。为满足不同数据结构的要求,compute
部分的第一行必须以连字符-
开头,controlPlane
部分的第一行则不可以连字符开头。虽然这两个部分目前都定义单个机器池,但未来的 OpenShift Container Platform 版本可能会支持在安装过程中定义多个计算池。只使用一个 control plane 池。- 4 5
- 是否要启用或禁用并发多线程或
超线程
。默认情况下,启用并发多线程以提高机器内核的性能。您可以通过将参数值设为Disabled
来禁用。如果您在某些集群机器上禁用并发多线程,则必须在所有集群机器上禁用。重要如果禁用并发多线程,请确保在容量规划时考虑到机器性能可能会显著降低的问题。如果您对机器禁用并发多线程,请使用较大的实例类型,如
m4.2xlarge
或m5.2xlarge
。 - 8
- 要为 etcd 配置更快的存储,特别是对于较大的集群,请将存储类型设置为
io1
,并将iops
设为2000
。 - 13
- 是否启用或禁用 FIPS 模式。默认情况下不启用 FIPS 模式。如果启用了 FIPS 模式,运行 OpenShift Container Platform 的 Red Hat Enterprise Linux CoreOS (RHCOS) 机器会绕过默认的 Kubernetes 加密套件,并使用由 RHCOS 提供的加密模块。
- 14
- 您可以选择提供您用来访问集群中机器的
sshKey
值。注意对于您要在其上执行安装调试或灾难恢复的生产环境 OpenShift Container Platform 集群,请指定
ssh-agent
进程使用的 SSH 密钥。
1.4.6. 修改高级网络配置参数
您只能在安装集群前修改高级网络配置参数。通过自定义高级配置,您可以指定 MTU 或 VXLAN 端口,允许自定义 kube-proxy 设置,以及为 openshiftSDNConfig
参数指定不同的 mode
,从而将集群整合到现有的网络环境中。
不支持直接修改 OpenShift Container Platform 清单文件。
先决条件
-
创建
install-config.yaml
文件并完成对其所做的任何修改。
流程
使用以下命令来创建清单:
$ ./openshift-install create manifests --dir=<installation_directory> 1
- 1
- 对于
<installation_directory>
,请指定含有集群的install-config.yaml
文件的目录的名称。
修改
<installation_directory>/manifests/cluster-scheduler-02-config.yml
Kubernetes 清单文件,以防止在 control plane 机器上调度 Pod:-
打开
manifests/cluster-scheduler-02-config.yml
文件。 -
找到
mastersSchedulable
参数,并将其值设为False
。 - 保存并退出文件。
注意目前,由于 Kubernetes 限制,入口负载均衡器将无法访问在 control plane 机器上运行的路由器 Pod。
-
打开
在
<installation_directory>/manifests/
目录下,创建一个名为cluster-network-03-config.yml
的文件:$ touch <installation_directory>/manifests/cluster-network-03-config.yml 1
- 1
- 对于
<installation_directory>
,请指定包含集群的manifests/
目录的目录名称。
创建该文件后,
manifests/
目录中会包含多个网络配置文件,如下所示:$ ls <installation_directory>/manifests/cluster-network-*
输出示例
cluster-network-01-crd.yml cluster-network-02-config.yml cluster-network-03-config.yml
在编辑器中打开
cluster-network-03-config.yml
文件,然后输入描述您想要的 Operator 配置的 CR:apiVersion: operator.openshift.io/v1 kind: Network metadata: name: cluster spec: 1 clusterNetwork: - cidr: 10.128.0.0/14 hostPrefix: 23 serviceNetwork: - 172.30.0.0/16 defaultNetwork: type: OpenShiftSDN openshiftSDNConfig: mode: NetworkPolicy mtu: 1450 vxlanPort: 4789
- 1
spec
参数的参数仅作示例。在 CR 中为 Cluster Network Operator 指定配置。
CNO 为 CR 中的参数提供默认值,因此您必须只指定要更改的参数。
-
保存
cluster-network-03-config.yml
文件,再退出文本编辑器。 -
可选:备份
manifests/cluster-network-03-config.yml
文件。创建集群时,安装程序会删除manifests/
目录。
1.4.7. Cluster Network Operator 配置
集群网络的配置作为 Cluster Network Operator (CNO) 配置的一部分被指定,并存储在名为 cluster
的 CR 对象中。CR 指定 operator.openshift.io
API 组中的 Network
API 的参数。
您可以通过在 CNO CR 中设置 defaultNetwork
参数的值,为 OpenShift Container Platform 集群指定集群网络配置。以下 CR 显示了 CNO 的默认配置,并列出了您可以配置的参数和有效的参数值:
Cluster Network Operator CR
apiVersion: operator.openshift.io/v1 kind: Network metadata: name: cluster spec: clusterNetwork: 1 - cidr: 10.128.0.0/14 hostPrefix: 23 serviceNetwork: 2 - 172.30.0.0/16 defaultNetwork: 3 ... kubeProxyConfig: 4 iptablesSyncPeriod: 30s 5 proxyArguments: iptables-min-sync-period: 6 - 0s
- 1 2
- 在
install-config.yaml
文件中指定。 - 3
- 配置集群网络的默认 Container Network Interface(CNI)网络供应商。
- 4
- 此对象的参数指定
kube-proxy
配置。如果没有指定参数值,Cluster Network Operator 会使用显示的默认参数值。如果您使用 OVN-Kubernetes 默认 CNI 网络供应商,则 kube-proxy 的配置不会起作用。 - 5
- 注意
由于 OpenShift Container Platform 4.3 及更高版本中引进了性能上的改进,现在不再需要调整
iptablesSyncPeriod
参数。 - 6
1.4.7.1. OpenShift SDN 网络供应商的配置参数
以下 YAML 对象描述了 OpenShift SDN 默认 Container Network Interface(CNI)网络供应商的配置参数。
defaultNetwork: type: OpenShiftSDN 1 openshiftSDNConfig: 2 mode: NetworkPolicy 3 mtu: 1450 4 vxlanPort: 4789 5
- 1
- 在
install-config.yaml
文件中指定。 - 2
- 只有您要覆盖部分 OpenShift SDN 配置时才需要指定。
- 3
- 配置 OpenShift SDN 的网络隔离模式。允许的值有
Multitenant
、Subnet
或NetworkPolicy
。默认值为NetworkPolicy
。 - 4
- VXLAN 覆盖网络的最大传输单元 (MTU) 。这个值通常是自动配置的;但是,如果集群中的节点没有全部使用相同的 MTU,那么您必须将此值明确设置为比最小节点 MTU 的值小 50。
- 5
- 用于所有 VXLAN 数据包的端口。默认值为
4789
。如果您在虚拟环境中运行,并且现有节点是另一个 VXLAN 网络的一部分,那么可能需要更改此值。例如,当在 VMware NSX-T 上运行 OpenShift SDN 覆盖时,您必须为 VXLAN 选择一个备用端口,因为两个 SDN 都使用相同的默认 VXLAN 端口号。在 Amazon Web Services (AWS) 上,您可以在端口
9000
和端口9999
之间为 VXLAN 选择一个备用端口。
1.4.7.2. OVN-Kubernetes 网络供应商的配置参数
以下 YAML 对象描述了 OVN-Kubernetes Pod 网络供应商的配置参数:
defaultNetwork: type: OVNKubernetes 1 ovnKubernetesConfig: 2 mtu: 1400 3 genevePort: 6081 4
1.4.7.3. Cluster Network Operator 配置示例
下例中显示了 CNO 的一个完整 CR:
Cluster Network Operator 示例 CR
apiVersion: operator.openshift.io/v1 kind: Network metadata: name: cluster spec: clusterNetwork: - cidr: 10.128.0.0/14 hostPrefix: 23 serviceNetwork: - 172.30.0.0/16 defaultNetwork: type: OpenShiftSDN openshiftSDNConfig: mode: NetworkPolicy mtu: 1450 vxlanPort: 4789 kubeProxyConfig: iptablesSyncPeriod: 30s proxyArguments: iptables-min-sync-period: - 0s
1.4.8. 部署集群
您可以在兼容云平台中安装 OpenShift Container Platform。
安装程序的 create cluster
命令只能在初始安装过程中运行一次。
先决条件
- 配置托管集群的云平台的帐户。
- 获取 OpenShift Container Platform 安装程序以及集群的 pull secret。
流程
运行安装程序:
$ ./openshift-install create cluster --dir=<installation_directory> \ 1 --log-level=info 2
注意如果您在主机上配置的云供应商帐户没有足够的权限来部署集群,安装过程将会停止,并且显示缺少的权限。
集群部署完成后,终端会显示访问集群的信息,包括指向其 Web 控制台的链接和
kubeadmin
用户的凭证。重要安装程序生成的 Ignition 配置文件中所含的证书会在 24 小时后过期。您必须以非降级状态持续运行集群 24 小时,以确保完成第一次证书轮转。
重要您不得删除安装程序或安装程序所创建的文件。需要这两者才能删除集群。
-
可选:从您用来安装集群的 IAM 帐户删除或禁用
AdministratorAccess
策略。
1.4.9. 通过下载二进制文件安装 CLI
您需要安装 CLI(oc
) 来使用命令行界面与 OpenShift Container Platform 进行交互。您可在 Linux 、Windows 或 macOS 上安装 oc
。
如果安装了旧版本的 oc
,则无法使用 OpenShift Container Platform 4.3 中的所有命令。下载并安装新版本的 oc
。
1.4.9.1. 在 Linux 上安装 CLI
您可以按照以下流程在 Linux 上安装 OpenShift CLI(oc
)二进制文件。
流程
- 访问 Red Hat OpenShift Cluster Manager 网站的 Infrastructure Provider 页面。
- 选择您的基础架构供应商及安装类型。
- 在 Command-line interface 部分,从下拉菜单中选择 Linux,并点 Download command-line tools。
解包存档:
$ tar xvzf <file>
把
oc
二进制代码放到PATH
中的目录中。执行以下命令可以查看当前的
PATH
设置:$ echo $PATH
安装 CLI 后,就可以使用oc
命令:
$ oc <command>
1.4.9.2. 在 Windows 上安装 CLI
您可以按照以下流程在 Windows 上安装 OpenShift CLI(oc
)二进制代码。
流程
- 访问 Red Hat OpenShift Cluster Manager 网站的 Infrastructure Provider 页面。
- 选择您的基础架构供应商及安装类型。
- 在 Command-line interface 部分,从下拉菜单中选择 Windows,点 Download command-line tools。
- 使用 ZIP 程序解压存档。
把
oc
二进制代码放到PATH
中的目录中。要查看您的
PATH
,请打开命令提示窗口并执行以下命令:C:\> path
安装 CLI 后,就可以使用oc
命令:
C:\> oc <command>
1.4.9.3. 在 macOS 上安装 CLI
您可以按照以下流程在 macOS 上安装 OpenShift CLI(oc
)二进制代码。
流程
- 访问 Red Hat OpenShift Cluster Manager 网站的 Infrastructure Provider 页面。
- 选择您的基础架构供应商及安装类型。
- 在 Command-line interface 部分,从下拉菜单中选择 MacOS,并点 Download command-line tools。
- 解包和解压存档。
将
oc
二进制文件移到 PATH 的目录中。要查看您的
PATH
,打开一个终端窗口并执行以下命令:$ echo $PATH
安装 CLI 后,就可以使用oc
命令:
$ oc <command>
1.4.10. 登录集群
您可以通过导出集群 kubeconfig
文件,以默认系统用户身份登录集群。kubeconfig
文件包含关于集群的信息,供 CLI 用于将客户端连接到正确集群和 API 服务器。该文件特只适用于一个特定的集群,在 OpenShift Container Platform 安装过程中创建。
先决条件
- 部署 OpenShift Container Platform 集群。
-
安装
oc
CLI。
流程
导出
kubeadmin
凭证:$ export KUBECONFIG=<installation_directory>/auth/kubeconfig 1
- 1
- 对于
<installation_directory>
,请指定安装文件保存到的目录的路径。
使用导出的配置,验证能否成功运行
oc
命令:$ oc whoami system:admin
1.4.11. 后续步骤
- 自定义集群。
- 若有需要,您可以选择不使用远程健康报告。
1.5. 在 AWS 上将集群安装到现有的 VPC 中
在 OpenShift Container Platform 版本 4.3 中,您可以在 Amazon Web Services (AWS) 上将集群安装到现有 Amazon Virtual Private Cloud (VPC) 中。安装程序会置备所需基础架构的其余部分,您可以进一步定制这些基础架构。要自定义安装,请在安装集群前修改 install-config.yaml
文件中的参数。
1.5.1. 先决条件
- 查看有关 OpenShift Container Platform 安装和更新流程的详细信息。
配置 AWS 帐户以托管集群。
重要如果您的计算机上存储有 AWS 配置集,则不要在使用多因素验证设备的同时使用您生成的临时会话令牌。在集群的整个生命周期中,集群会持续使用您的当前 AWS 凭证来创建 AWS 资源,因此您必须使用长期凭证。要生成适当的密钥,请参阅 AWS 文档中的管理 IAM 用户的访问密钥。您可在运行安装程序时提供密钥。
- 如果使用防火墙,则必须将其配置为允许集群需要访问的站点。
- 如果不允许系统管理身份和访问管理(IAM),集群管理员可以手动创建和维护 IAM 凭证。手动模式也可以用于云 IAM API 无法访问的环境中。
1.5.2. 关于使用自定义 VPC
在 OpenShift Container Platform 4.3 中,您可以在 Amazon Web Services (AWS) 的现有 Amazon Virtual Private Cloud (VPC) 中将集群部署到现有子网中。通过将 OpenShift Container Platform 部署到现有的 AWS VPC 中,您可能会避开新帐户中的限制,或者更容易地利用公司所设置的操作限制。如果您无法获得您自己创建 VPC 所需的基础架构创建权限,请使用这个安装选项。
因为安装程序无法了解您现有子网中还有哪些其他组件,所以无法选择子网 CIDR 。您必须为安装集群的子网配置网络。
1.5.2.1. 使用 VPC 的要求
安装程序不再创建以下组件:
- 互联网网关
- NAT 网关
- 子网
- 路由表
- VPCs
- VPC DHCP 选项
- VPC 端点
如果您使用自定义 VPC,您必须为安装程序和集群正确配置它及其子网。安装程序不能为集群分配要使用的网络范围,为子网设置路由表,或者设置类似 DHCP 的 VPC 选项,因此您必须在安装集群前配置它们。
您的 VPC 必须满足以下特征:
-
VPC 的 CIDR 块必须包含
Networking.machineCIDR
,它是集群机器的 IP 地址池。 -
VPC 不能使用
kubernetes.io/cluster/.*: owned
标签。 -
您需要在您的 VPC 中启用
enableDnsSupport
和enableDnsHostnames
属性,以便集群可以使用附加到 VPC 中的 Route53 区来解析集群内部的 DNS 记录。请参阅 AWS 文档中的您的 VPC 中的 DNS 支持部分 。
如果您使用具有公共访问权限的集群,您必须为每个集群使用的可用区创建一个公共和私有子网。安装程序会修改子网以添加 kubernetes.io/cluster/.*: shared
标签,因此您的子网必须至少有一个可用的空闲标签插槽。请参阅 AWS 文档中的关于当前标签限制的部分,以确保安装程序可以为您指定的每个子网添加标签。
如果您在断开连接的环境中工作,您将无法访问 EC2 和 ELB 端点的公共 IP 地址。要解决这个问题,您必须创建一个 VPC 端点,并将其附加到集群使用的子网。端点应命名如下:
-
ec2.<region>.amazonaws.com
-
elasticloadbalancing.<region>.amazonaws.com
-
s3.<region>.amazonaws.com
所需的 VPC 组件
您必须提供合适的 VPC 和子网,以便与您的机器通信。
组件 | AWS 类型 | 描述 | |
---|---|---|---|
VPC |
| 您必须提供一个公共 VPC 供集群使用。VPC 使用引用每个子网的路由表的端点,以改进与托管在 S3 中的 registry 的通信。 | |
公共子网 |
| 您的 VPC 必须有 1 到 3 个可用区的公共子网,并将其与适当的入口规则关联。 | |
互联网网关 |
| 您必须有一个公共互联网网关,以及附加到 VPC 的公共路由。在提供的模板中,每个公共子网都有一个具有 EIP 地址的 NAT 网关。这些 NAT 网关允许集群资源(如专用子网实例)访问互联网,而有些受限网络或代理场景则不需要它们。 | |
网络访问控制 |
| 您必须允许 VPC 访问下列端口: | |
端口 | 原因 | ||
| 入站 HTTP 流量 | ||
| 入站 HTTPS 流量 | ||
| 入站 SSH 流量 | ||
| 入站临时流量 | ||
| 出站临时流量 | ||
专用子网 |
| 您的 VPC 可以具有私有子网。提供的 CloudFormation 模板可为 1 到 3 个可用区创建专用子网。如果您使用专用子网,必须为其提供适当的路由和表。 |
1.5.2.2. VPC 验证
要确保您提供的子网适合您的环境,安装程序会确认以下信息:
- 您指定的所有子网都存在。
- 您提供了私有子网。
- 子网 CIDR 属于您指定的机器 CIDR。
- 您为每个可用区提供子网。每个可用区不包含多于一个的公共子网和私有子网。如果您使用私有集群,为每个可用区只提供一个私有子网。否则,为每个可用区提供一个公共和私有子网。
- 您可以为每个私有子网可用区提供一个公共子网。机器不会在没有为其提供私有子网的可用区中置备。
如果您销毁使用现有 VPC 的集群,VPC 不会被删除。从 VPC 中删除 OpenShift Container Platform 集群时,kubernetes.io/cluster/.*: shared
标签会从使用它的子网中删除。
1.5.2.3. 权限划分
从 OpenShift Container Platform 4.3 开始,您不需要安装程序置备的基础架构集群部署所需的所有权限。这与您所在机构可能已有的权限划分类似:不同的个人可以在您的云中创建不同的资源。。例如,您可以创建针对于特定应用程序的对象,如实例、存储桶和负载均衡器,但不能创建与网络相关的组件,如 VPC 、子网或入站规则。
您在创建集群时使用的 AWS 凭证不需要 VPC 和 VPC 中的核心网络组件(如子网、路由表、互联网网关、NAT 和 VPN)所需的网络权限。您仍然需要获取集群中的机器需要的应用程序资源的权限,如 ELB 、安全组、S3 存储桶和节点。
1.5.2.4. 集群间隔离
如果您将 OpenShift Container Platform 部署到现有网络中,集群服务的隔离将在以下方面减少:
- 您可以在同一 VPC 中安装多个 OpenShift Container Platform 集群。
- 整个网络允许 ICMP 入站流量。
- 整个网络都允许 TCP 入站流量 (SSH)。
- 整个网络都允许 control plane TCP 6443 入站流量 (Kubernetes API)。
- 整个网络都允许 control plane TCP 22623 入站流量 (MCS) 。
1.5.3. OpenShift Container Platform 对互联网和 Telemetry 的访问
在 OpenShift Container Platform 4.3 中,您需要访问互联网来安装集群。默认运行的 Telemetry 服务提供有关集群健康状况和成功更新的指标,这也需要访问互联网。如果您的集群连接到互联网,Telemetry 会自动运行,而且集群会注册到 Red Hat OpenShift Cluster Manager(OCM)。
确认 Red Hat OpenShift Cluster Manager 清单正确后,可以由 Telemetry 自动维护,也可以使用 OCM 手动维护,使用订阅监控 来跟踪帐户或多集群级别的 OpenShift Container Platform 订阅。
您必须具有以下互联网访问权限:
- 访问 Red Hat OpenShift Cluster Manager 页面,以下载安装程序并执行订阅管理。如果集群可以访问互联网,并且没有禁用 Telemetry,该服务会自动授权您的集群。
- 访问 Quay.io,以获取安装集群所需的软件包。
- 获取执行集群更新所需的软件包。
如果您的集群无法直接访问互联网,则可以在置备的某些类基础架构上执行受限网络安装。在此过程中,您要下载所需的内容,并使用它在镜像 registry(mirror registry) 中填充安装集群并生成安装程序所需的软件包。对于某些安装类型,集群要安装到的环境不需要访问互联网。在更新集群之前,要更新 registry 镜像系统中的内容。
1.5.4. 生成 SSH 私钥并将其添加到代理中
如果要在集群上执行安装调试或灾难恢复,则必须为 ssh-agent
和安装程序提供 SSH 密钥。
在生产环境中,您需要进行灾难恢复和调试。
您可以使用此密钥以 core
用户身份通过 SSH 连接到 master 节点。在部署集群时,此密钥会添加到 core
用户的 ~/.ssh/authorized_keys
列表中。
您必须使用一个本地密钥,而不要使用在特定平台上配置的密钥,如 AWS 密钥对。
流程
如果还没有为计算机上免密码身份验证而配置的 SSH 密钥,请创建一个。例如,在使用 Linux 操作系统的计算机上运行以下命令:
$ ssh-keygen -t rsa -b 4096 -N '' \ -f <path>/<file_name> 1
- 1
- 指定 SSH 密钥的路径和文件名,如
~/.ssh/id_rsa
。不要指定已存在的 SSH 密钥,因为它会被覆盖。
运行此命令会在指定的位置生成不需要密码的 SSH 密钥。
作为后台任务启动
ssh-agent
进程:$ eval "$(ssh-agent -s)" Agent pid 31874
将 SSH 私钥添加到
ssh-agent
:$ ssh-add <path>/<file_name> 1 Identity added: /home/<you>/<path>/<file_name> (<computer_name>)
- 1
- 指定 SSH 私钥的路径和文件名,如
~/.ssh/id_rsa
后续步骤
- 在安装 OpenShift Container Platform 时,为安装程序提供 SSH 公钥。
1.5.5. 获取安装程序
在安装 OpenShift Container Platform 之前,将安装文件下载到本地计算机上。
先决条件
- 必须从使用 Linux 或 macOS 的计算机安装集群。
- 需要 500 MB 本地磁盘空间来下载安装程序。
流程
- 访问 Red Hat OpenShift Cluster Manager 网站的 Infrastructure Provider 页面。如果您有红帽帐号,请使用自己的凭证登录。如果没有,请创建一个帐户。
进入适用于您的安装类型的页面,下载您的操作系统的安装程序,并将文件放在要保存安装配置文件的目录中。。
重要安装程序会在用来安装集群的计算机上创建若干文件。在完成集群安装后,您必须保留安装程序和安装程序所创建的文件。
重要删除安装程序创建的文件不会删除您的集群,即使集群在安装过程中失败也是如此。您必须完成针对特定云供应商的 OpenShift Container Platform 卸载流程,才能完全删除您的集群。
提取安装程序。例如,在使用 Linux 操作系统的计算机上运行以下命令:
$ tar xvf <installation_program>.tar.gz
-
在 Red Hat OpenShift Cluster Manager 站点的 Pull Secret 页面中,下载您的安装 pull secret 的
.txt
文件。通过此 pull secret,您可以进行所含授权机构提供的服务的身份验证,这些服务包括为 OpenShift Container Platform 组件提供容器镜像的 Quay.io。
1.5.6. 创建安装配置文件
您可以自定义 Amazon Web Services (AWS) 上的 OpenShift Container Platform 安装。
先决条件
- 获取 OpenShift Container Platform 安装程序以及集群的 pull secret。
流程
创建
install-config.yaml
文件。运行以下命令:
$ ./openshift-install create install-config --dir=<installation_directory> 1
- 1
- 对于
<installation_directory>
,请指定用于保存安装程序所创建的文件的目录名称。
重要指定一个空目录。一些安装信息,如 bootstrap X.509 证书,有较短的过期间隔,因此不要重复使用安装目录。如果要重复使用另一个集群安装中的个别文件,可以将其复制到您的目录中。但是,一些安装数据的文件名可能会在发行版本之间有所改变。从 OpenShift Container Platform 老版本中复制安装文件时要格外小心。
在提示符处,提供您的云的配置详情:
可选:选择用来访问集群机器的 SSH 密钥。
注意对于您要在其上执行安装调试或灾难恢复的生产环境 OpenShift Container Platform 集群,请指定
ssh-agent
进程使用的 SSH 密钥。- 选择 AWS 作为目标平台。
- 如果计算机上没有保存 Amazon Web Services (AWS) 配置集,请为您配置用于运行安装程序的用户输入 AWS 访问密钥 ID 和 Secret 访问密钥。
- 选择要将集群部署到的 AWS 区域。
- 选择您为集群配置的 Route53 服务的基域。
- 为集群输入一个描述性名称。
- 粘贴从 Red Hat OpenShift Cluster Manager 站点的 Pull Secret 页面中获取的 pull secret。
-
修改
install-config.yaml
文件。您可以在安装配置参数部分中找到有关可用参数的更多信息。 备份
install-config.yaml
文件,以便用于安装多个集群。重要install-config.yaml
文件会在安装过程中消耗掉。如果要重复使用此文件,必须现在备份。
1.5.6.1. 安装配置参数
在部署 OpenShift Container Platform 集群前,您可以提供参数值,以描述托管集群的云平台的帐户并选择性地自定义集群平台。在创建 install-config.yaml
安装配置文件时,您可以通过命令行来提供所需的参数的值。如果要自定义集群,可以修改 install-config.yaml
文件来提供关于平台的更多信息。
安装之后,您无法修改 install-config.yaml
文件中的这些参数。
参数 | 描述 | 值 |
---|---|---|
|
云供应商的基域。此值用于创建到 OpenShift Container Platform 集群组件的路由。集群的完整 DNS 名称是 |
完全限定域名或子域名,如 |
|
托管 control plane 机器的云供应商。此参数值必须与 |
|
|
托管 worker 机器的云供应商。此参数值必须与 |
|
| 集群的名称。 |
包含大写字母或小写字母的字符串,如 |
| 集群要部署到的区域。 |
云的有效区域,如 AWS 的 |
| 从 Red Hat OpenShift Cluster Manager 站点的 Pull Secret 页面中获取的 pull secret。您可以使用此 pull secret 来进行所含授权机构提供的服务的身份验证,这些服务包括为 OpenShift Container Platform 组件提供容器镜像的 Quay.io。 |
{ "auths":{ "cloud.openshift.com":{ "auth":"b3Blb=", "email":"you@example.com" }, "quay.io":{ "auth":"b3Blb=", "email":"you@example.com" } } } |
参数 | 描述 | 值 |
---|---|---|
| 用于访问集群机器的 SSH 密钥。 注意
对于您要在其上执行安装调试或灾难恢复的生产环境 OpenShift Container Platform 集群,请指定 |
添加到 |
| 是否启用或禁用 FIPS 模式。默认情况下不启用 FIPS 模式。如果启用了 FIPS 模式,运行 OpenShift Container Platform 的 Red Hat Enterprise Linux CoreOS (RHCOS) 机器会绕过默认的 Kubernetes 加密套件,并使用由 RHCOS 提供的加密模块。 |
|
| 如何发布集群的面向用户的端点。 |
|
|
是否在计算机器上启用或禁用并发多线程或 重要 如果禁用并发多线程,请确保在容量规划时考虑到机器性能可能会显著降低的问题。 |
|
| 要置备的计算机器数量,也称为 worker 机器。 |
大于或等于 |
|
是否在 control plane 机器上启用或禁用并发多线程或 重要 如果禁用并发多线程,请确保在容量规划时考虑到机器性能可能会显著降低的问题。 |
|
| 要置备的 control plane 机器数量。 |
大于或等于 |
参数 | 描述 | 值 |
---|---|---|
| 为根卷保留的每秒输入/输出操作 (IOPS) 数。 |
整数,如 |
| 以 GiB 为单位的根卷大小。 |
整数,如 |
| 根卷的实例类型。 |
有效的 AWS EBS 实例类型,如 |
| 计算机器的 EC2 实例类型。 |
有效的 AWS 实例类型,如 |
| 安装程序在其中为计算 MachinePool 创建机器的可用区。如果您提供自己的 VPC,则必须在那个可用域中提供一个子网。 |
有效 AWS 可用区的列表,如 |
| 安装程序在其中创建计算资源的 AWS 区域。 |
有效的 AWS 区域,如 |
| control plane 机器的 EC2 实例类型。 |
有效的 AWS 实例类型,如 |
| 安装程序在其中为 control plane MachinePool 创建机器的可用区。 |
有效 AWS 可用区的列表,如 |
| 安装程序在其中创建 control plane 资源的 AWS 区域。 |
有效的 AWS 区域,如 |
| 键与值的映射,安装程序将其作为标签添加到它所创建的所有资源。 |
任何有效的 YAML 映射,如 |
|
如果您提供 VPC,而不是让安装程序为您创建 VPC,请指定要使用的集群子网。子网必须是您指定的同一 | 有效的子网 ID。 |
1.5.6.2. AWS 的自定义 install-config.yaml
文件示例
您可以自定义 install-config.yaml
文件,以指定有关 OpenShift Container Platform 集群平台的更多信息,或修改所需参数的值。
此示例 YAML 文件仅供参考。您必须使用安装程序来获取 install-config.yaml
文件,并且修改该文件。
apiVersion: v1 baseDomain: example.com 1 controlPlane: 2 hyperthreading: Enabled 3 4 name: master platform: aws: zones: - us-west-2a - us-west-2b rootVolume: iops: 4000 size: 500 type: io1 type: m5.xlarge 5 replicas: 3 compute: 6 - hyperthreading: Enabled 7 name: worker platform: aws: rootVolume: iops: 2000 size: 500 type: io1 8 type: c5.4xlarge zones: - us-west-2c replicas: 3 metadata: name: test-cluster 9 networking: clusterNetwork: - cidr: 10.128.0.0/14 hostPrefix: 23 machineCIDR: 10.0.0.0/16 networkType: OpenShiftSDN serviceNetwork: - 172.30.0.0/16 platform: aws: region: us-west-2 10 userTags: adminContact: jdoe costCenter: 7536 subnets: 11 - subnet-1 - subnet-2 - subnet-3 pullSecret: '{"auths": ...}' 12 fips: false 13 sshKey: ssh-ed25519 AAAA... 14
- 1 9 10 12
- 必需。安装程序会提示您输入这个值。
- 2 6
- 如果没有提供这些参数和值,安装程序会提供默认值。
- 3 7
controlPlane
部分是一个单映射,但 compute 部分是一系列映射。为满足不同数据结构的要求,compute
部分的第一行必须以连字符-
开头,controlPlane
部分的第一行则不可以连字符开头。虽然这两个部分目前都定义单个机器池,但未来的 OpenShift Container Platform 版本可能会支持在安装过程中定义多个计算池。只使用一个 control plane 池。- 4 5
- 是否要启用或禁用并发多线程或
超线程
。默认情况下,启用并发多线程以提高机器内核的性能。您可以通过将参数值设为Disabled
来禁用。如果您在某些集群机器上禁用并发多线程,则必须在所有集群机器上禁用。重要如果禁用并发多线程,请确保在容量规划时考虑到机器性能可能会显著降低的问题。如果您对机器禁用并发多线程,请使用较大的实例类型,如
m4.2xlarge
或m5.2xlarge
。 - 8
- 要为 etcd 配置更快的存储,特别是对于较大的集群,请将存储类型设置为
io1
,并将iops
设为2000
。 - 11
- 如果您提供自己的 VPC,为集群使用的每个可用区指定子网。
- 13
- 是否启用或禁用 FIPS 模式。默认情况下不启用 FIPS 模式。如果启用了 FIPS 模式,运行 OpenShift Container Platform 的 Red Hat Enterprise Linux CoreOS (RHCOS) 机器会绕过默认的 Kubernetes 加密套件,并使用由 RHCOS 提供的加密模块。
- 14
- 您可以选择提供您用来访问集群中机器的
sshKey
值。注意对于您要在其上执行安装调试或灾难恢复的生产环境 OpenShift Container Platform 集群,请指定
ssh-agent
进程使用的 SSH 密钥。
1.5.6.3. 在安装过程中配置集群范围代理
生产环境可能会拒绝直接访问互联网,而是提供 HTTP 或 HTTPS 代理。您可以通过在 install-config.yaml
文件中配置代理设置,将新的 OpenShift Container Platform 集群配置为使用代理。
先决条件
-
现有的
install-config.yaml
文件。 查看集群需要访问的站点,并决定是否需要绕过代理。默认情况下代理所有集群出口流量,包括对托管云供应商 API 的调用。若有需要,将站点添加到 Proxy 对象的
spec.noProxy
字段来绕过代理服务器。注意Proxy 对象的
status.noProxy
字段默认填充实例元数据端点 (169.254.169.254
),以及您的安装配置中networking.machineCIDR
、networking.clusterNetwork.cidr
和networking.serviceNetwork[]
字段的值。
流程
编辑
install-config.yaml
文件并添加代理设置。例如:apiVersion: v1 baseDomain: my.domain.com proxy: httpProxy: http://<username>:<pswd>@<ip>:<port> 1 httpsProxy: http://<username>:<pswd>@<ip>:<port> 2 noProxy: example.com 3 additionalTrustBundle: | 4 -----BEGIN CERTIFICATE----- <MY_TRUSTED_CA_CERT> -----END CERTIFICATE----- ...
- 1
- 用于创建集群外 HTTP 连接的代理 URL。URL 必须是
http
。如果您使用不要求额外代理配置但需要额外 CA 的 MITM 透明代理网络,则不得指定httpProxy
值。 - 2
- 用于创建集群外 HTTPS 连接的代理 URL。如果未指定此字段,
httpProxy
会同时用于 HTTP 和 HTTPS 连接。如果您使用不要求额外代理配置但需要额外 CA 的 MITM 透明代理网络,则不得指定httpsProxy
值。 - 3
- 要排除代理的目标域名、域、IP 地址或其他网络 CIDR 的逗号分隔列表。域之前加上前缀
.
可包含该域的所有子域。使用*
可对所有目的地绕过所有代理。 - 4
- 如果提供,安装程序会在
openshift-config
命名空间中生成名为user-ca-bundle
的 ConfigMap,其包含代理 HTTPS 连接所需的一个或多个额外 CA 证书。然后,Cluster Network Operator 会创建trusted-ca-bundle
ConfigMap,将这些内容与 Red Hat Enterprise Linux CoreOS (RHCOS) 信任捆绑包合并,Proxy 对象的trustedCA
字段中也会引用此 ConfigMap。additionalTrustBundle
字段是必需的,除非代理的身份证书由来自 RHCOS 信任捆绑包的颁发机构签名。如果您使用不要求额外代理配置但需要额外 CA 的 MITM 透明代理网络,您必须提供 MITM CA 证书。
注意安装程序不支持代理的
readinessEndpoints
字段。- 保存该文件,并在安装 OpenShift Container Platform 时引用。
安装程序会创建一个名为 cluster
的集群范围代理,该代理使用提供的 install-config.yaml
文件中的代理设置。如果没有提供代理设置,仍然会创建 cluster
Proxy 对象,但它会有一个零 spec
。
只支持名为 cluster
的 Proxy 对象,且无法创建额外的代理。
1.5.7. 部署集群
您可以在兼容云平台中安装 OpenShift Container Platform。
安装程序的 create cluster
命令只能在初始安装过程中运行一次。
先决条件
- 配置托管集群的云平台的帐户。
- 获取 OpenShift Container Platform 安装程序以及集群的 pull secret。
流程
运行安装程序:
$ ./openshift-install create cluster --dir=<installation_directory> \ 1 --log-level=info 2
注意如果您在主机上配置的云供应商帐户没有足够的权限来部署集群,安装过程将会停止,并且显示缺少的权限。
集群部署完成后,终端会显示访问集群的信息,包括指向其 Web 控制台的链接和
kubeadmin
用户的凭证。重要安装程序生成的 Ignition 配置文件中所含的证书会在 24 小时后过期。您必须以非降级状态持续运行集群 24 小时,以确保完成第一次证书轮转。
重要您不得删除安装程序或安装程序所创建的文件。需要这两者才能删除集群。
-
可选:从您用来安装集群的 IAM 帐户删除或禁用
AdministratorAccess
策略。
1.5.8. 通过下载二进制文件安装 CLI
您需要安装 CLI(oc
) 来使用命令行界面与 OpenShift Container Platform 进行交互。您可在 Linux 、Windows 或 macOS 上安装 oc
。
如果安装了旧版本的 oc
,则无法使用 OpenShift Container Platform 4.3 中的所有命令。下载并安装新版本的 oc
。
1.5.8.1. 在 Linux 上安装 CLI
您可以按照以下流程在 Linux 上安装 OpenShift CLI(oc
)二进制文件。
流程
- 访问 Red Hat OpenShift Cluster Manager 网站的 Infrastructure Provider 页面。
- 选择您的基础架构供应商及安装类型。
- 在 Command-line interface 部分,从下拉菜单中选择 Linux,并点 Download command-line tools。
解包存档:
$ tar xvzf <file>
把
oc
二进制代码放到PATH
中的目录中。执行以下命令可以查看当前的
PATH
设置:$ echo $PATH
安装 CLI 后,就可以使用oc
命令:
$ oc <command>
1.5.8.2. 在 Windows 上安装 CLI
您可以按照以下流程在 Windows 上安装 OpenShift CLI(oc
)二进制代码。
流程
- 访问 Red Hat OpenShift Cluster Manager 网站的 Infrastructure Provider 页面。
- 选择您的基础架构供应商及安装类型。
- 在 Command-line interface 部分,从下拉菜单中选择 Windows,点 Download command-line tools。
- 使用 ZIP 程序解压存档。
把
oc
二进制代码放到PATH
中的目录中。要查看您的
PATH
,请打开命令提示窗口并执行以下命令:C:\> path
安装 CLI 后,就可以使用oc
命令:
C:\> oc <command>
1.5.8.3. 在 macOS 上安装 CLI
您可以按照以下流程在 macOS 上安装 OpenShift CLI(oc
)二进制代码。
流程
- 访问 Red Hat OpenShift Cluster Manager 网站的 Infrastructure Provider 页面。
- 选择您的基础架构供应商及安装类型。
- 在 Command-line interface 部分,从下拉菜单中选择 MacOS,并点 Download command-line tools。
- 解包和解压存档。
将
oc
二进制文件移到 PATH 的目录中。要查看您的
PATH
,打开一个终端窗口并执行以下命令:$ echo $PATH
安装 CLI 后,就可以使用oc
命令:
$ oc <command>
1.5.9. 登录集群
您可以通过导出集群 kubeconfig
文件,以默认系统用户身份登录集群。kubeconfig
文件包含关于集群的信息,供 CLI 用于将客户端连接到正确集群和 API 服务器。该文件特只适用于一个特定的集群,在 OpenShift Container Platform 安装过程中创建。
先决条件
- 部署 OpenShift Container Platform 集群。
-
安装
oc
CLI。
流程
导出
kubeadmin
凭证:$ export KUBECONFIG=<installation_directory>/auth/kubeconfig 1
- 1
- 对于
<installation_directory>
,请指定安装文件保存到的目录的路径。
使用导出的配置,验证能否成功运行
oc
命令:$ oc whoami system:admin
1.5.10. 后续步骤
- 自定义集群。
- 若有需要,您可以选择不使用远程健康报告。
1.6. 在 AWS 上安装私有集群
在 OpenShift Container Platform 版本 4.3 中,您可以在 Amazon Web Services (AWS) 上将私有集群安装到现有的 VPC 中。安装程序会置备所需基础架构的其余部分,您可以进一步定制这些基础架构。要自定义安装,请在安装集群前修改 install-config.yaml
文件中的参数。
1.6.1. 先决条件
- 查看有关 OpenShift Container Platform 安装和更新流程的详细信息。
配置 AWS 帐户以托管集群。
重要如果您的计算机上存储有 AWS 配置集,则不要在使用多因素验证设备的同时使用您生成的临时会话令牌。在集群的整个生命周期中,集群会持续使用您的当前 AWS 凭证来创建 AWS 资源,因此您必须使用长期凭证。要生成适当的密钥,请参阅 AWS 文档中的管理 IAM 用户的访问密钥。您可在运行安装程序时提供密钥。
- 如果使用防火墙,则必须将其配置为允许集群需要访问的站点。
- 如果不允许系统管理身份和访问管理(IAM),集群管理员可以手动创建和维护 IAM 凭证。手动模式也可以用于云 IAM API 无法访问的环境中。
1.6.2. 私有集群
如果您的环境不需要外部互联网连接,您可以部署不公开外部端点的 OpenShift Container Platform 集群。私有集群只能从内部网络访问,且无法在互联网中看到。
默认情况下,OpenShift Container Platform 被置备为使用可公开访问的 DNS 和端点。私有集群在部署集群时将 DNS 、Ingress Controller 和 API 服务器设置为私有。这意味着,集群资源只能从您的内部网络访问,且不能在互联网中看到。
要部署私有集群,您必须使用符合您的要求的现有网络。您的集群资源可能会在网络中的其他集群间共享。
另外,您必须从可访问您置备的云的 API 服务、您置备的网络上的主机以及可以连接到互联网来获取安装介质的机器上部署私有集群。您可以使用符合这些访问要求的机器,并按照您的公司规定进行操作。例如,该机器可以是云网络中的堡垒主机,也可以是可通过 VPN 访问网络的机器。
1.6.2.1. AWS 中的私有集群
要在 Amazon Web Services (AWS) 上创建私有集群,您必须提供一个现有的私有 VPC 和子网来托管集群。安装程序还必须能够解析集群所需的 DNS 记录。安装程序将 Ingress Operator 和 API 服务器配置为只可以从私有网络访问。
集群仍然需要访问互联网来访问 AWS API。
安装私有集群时不需要或创建以下项目:
- 公共子网
- 支持公共入口的公共负载均衡器
-
与集群的
baseDomain
匹配的公共路由 53 区域
安装程序会使用您指定的 baseDomain
来创建专用的 Route 53 区域以及集群所需的记录。集群被配置,以便 Operator 不会为集群创建公共记录,且所有集群机器都放置在您指定的私有子网中。
1.6.2.1.1. 限制:
为私有集群添加公共功能的能力有限。
- 在安装后,您无法在不进行额外操作的情况下公开 Kubernetes API 端点。这些额外的操作包括为使用中的每个可用区在 VPC 中创建公共子网,创建公共负载均衡器,以及配置 control plane 安全组以便 6443 端口(Kubernetes API 端口)可以接受来自于互联网的网络流量。
-
如果使用公共服务类型负载均衡器,您必须在每个可用区中为公共子网添加
kubernetes.io/cluster/<cluster-infra-id>: shared
标签,以便 AWS 可使用它们来创建公共负载均衡器。
1.6.3. 关于使用自定义 VPC
在 OpenShift Container Platform 4.3 中,您可以在 Amazon Web Services (AWS) 的现有 Amazon Virtual Private Cloud (VPC) 中将集群部署到现有子网中。通过将 OpenShift Container Platform 部署到现有的 AWS VPC 中,您可能会避开新帐户中的限制,或者更容易地利用公司所设置的操作限制。如果您无法获得您自己创建 VPC 所需的基础架构创建权限,请使用这个安装选项。
因为安装程序无法了解您现有子网中还有哪些其他组件,所以无法选择子网 CIDR 。您必须为安装集群的子网配置网络。
1.6.3.1. 使用 VPC 的要求
安装程序不再创建以下组件:
- 互联网网关
- NAT 网关
- 子网
- 路由表
- VPCs
- VPC DHCP 选项
- VPC 端点
如果您使用自定义 VPC,您必须为安装程序和集群正确配置它及其子网。安装程序不能为集群分配要使用的网络范围,为子网设置路由表,或者设置类似 DHCP 的 VPC 选项,因此您必须在安装集群前配置它们。
您的 VPC 必须满足以下特征:
-
VPC 的 CIDR 块必须包含
Networking.machineCIDR
,它是集群机器的 IP 地址池。 -
VPC 不能使用
kubernetes.io/cluster/.*: owned
标签。 -
您需要在您的 VPC 中启用
enableDnsSupport
和enableDnsHostnames
属性,以便集群可以使用附加到 VPC 中的 Route53 区来解析集群内部的 DNS 记录。请参阅 AWS 文档中的您的 VPC 中的 DNS 支持部分 。
如果您使用具有公共访问权限的集群,您必须为每个集群使用的可用区创建一个公共和私有子网。安装程序会修改子网以添加 kubernetes.io/cluster/.*: shared
标签,因此您的子网必须至少有一个可用的空闲标签插槽。请参阅 AWS 文档中的关于当前标签限制的部分,以确保安装程序可以为您指定的每个子网添加标签。
如果您在断开连接的环境中工作,您将无法访问 EC2 和 ELB 端点的公共 IP 地址。要解决这个问题,您必须创建一个 VPC 端点,并将其附加到集群使用的子网。端点应命名如下:
-
ec2.<region>.amazonaws.com
-
elasticloadbalancing.<region>.amazonaws.com
-
s3.<region>.amazonaws.com
所需的 VPC 组件
您必须提供合适的 VPC 和子网,以便与您的机器通信。
组件 | AWS 类型 | 描述 | |
---|---|---|---|
VPC |
| 您必须提供一个公共 VPC 供集群使用。VPC 使用引用每个子网的路由表的端点,以改进与托管在 S3 中的 registry 的通信。 | |
公共子网 |
| 您的 VPC 必须有 1 到 3 个可用区的公共子网,并将其与适当的入口规则关联。 | |
互联网网关 |
| 您必须有一个公共互联网网关,以及附加到 VPC 的公共路由。在提供的模板中,每个公共子网都有一个具有 EIP 地址的 NAT 网关。这些 NAT 网关允许集群资源(如专用子网实例)访问互联网,而有些受限网络或代理场景则不需要它们。 | |
网络访问控制 |
| 您必须允许 VPC 访问下列端口: | |
端口 | 原因 | ||
| 入站 HTTP 流量 | ||
| 入站 HTTPS 流量 | ||
| 入站 SSH 流量 | ||
| 入站临时流量 | ||
| 出站临时流量 | ||
专用子网 |
| 您的 VPC 可以具有私有子网。提供的 CloudFormation 模板可为 1 到 3 个可用区创建专用子网。如果您使用专用子网,必须为其提供适当的路由和表。 |
1.6.3.2. VPC 验证
要确保您提供的子网适合您的环境,安装程序会确认以下信息:
- 您指定的所有子网都存在。
- 您提供了私有子网。
- 子网 CIDR 属于您指定的机器 CIDR。
- 您为每个可用区提供子网。每个可用区不包含多于一个的公共子网和私有子网。如果您使用私有集群,为每个可用区只提供一个私有子网。否则,为每个可用区提供一个公共和私有子网。
- 您可以为每个私有子网可用区提供一个公共子网。机器不会在没有为其提供私有子网的可用区中置备。
如果您销毁使用现有 VPC 的集群,VPC 不会被删除。从 VPC 中删除 OpenShift Container Platform 集群时,kubernetes.io/cluster/.*: shared
标签会从使用它的子网中删除。
1.6.3.3. 权限划分
从 OpenShift Container Platform 4.3 开始,您不需要安装程序置备的基础架构集群部署所需的所有权限。这与您所在机构可能已有的权限划分类似:不同的个人可以在您的云中创建不同的资源。。例如,您可以创建针对于特定应用程序的对象,如实例、存储桶和负载均衡器,但不能创建与网络相关的组件,如 VPC 、子网或入站规则。
您在创建集群时使用的 AWS 凭证不需要 VPC 和 VPC 中的核心网络组件(如子网、路由表、互联网网关、NAT 和 VPN)所需的网络权限。您仍然需要获取集群中的机器需要的应用程序资源的权限,如 ELB 、安全组、S3 存储桶和节点。
1.6.3.4. 集群间隔离
如果您将 OpenShift Container Platform 部署到现有网络中,集群服务的隔离将在以下方面减少:
- 您可以在同一 VPC 中安装多个 OpenShift Container Platform 集群。
- 整个网络允许 ICMP 入站流量。
- 整个网络都允许 TCP 入站流量 (SSH)。
- 整个网络都允许 control plane TCP 6443 入站流量 (Kubernetes API)。
- 整个网络都允许 control plane TCP 22623 入站流量 (MCS) 。
1.6.4. OpenShift Container Platform 对互联网和 Telemetry 的访问
在 OpenShift Container Platform 4.3 中,您需要访问互联网来安装集群。默认运行的 Telemetry 服务提供有关集群健康状况和成功更新的指标,这也需要访问互联网。如果您的集群连接到互联网,Telemetry 会自动运行,而且集群会注册到 Red Hat OpenShift Cluster Manager(OCM)。
确认 Red Hat OpenShift Cluster Manager 清单正确后,可以由 Telemetry 自动维护,也可以使用 OCM 手动维护,使用订阅监控 来跟踪帐户或多集群级别的 OpenShift Container Platform 订阅。
您必须具有以下互联网访问权限:
- 访问 Red Hat OpenShift Cluster Manager 页面,以下载安装程序并执行订阅管理。如果集群可以访问互联网,并且没有禁用 Telemetry,该服务会自动授权您的集群。
- 访问 Quay.io,以获取安装集群所需的软件包。
- 获取执行集群更新所需的软件包。
如果您的集群无法直接访问互联网,则可以在置备的某些类基础架构上执行受限网络安装。在此过程中,您要下载所需的内容,并使用它在镜像 registry(mirror registry) 中填充安装集群并生成安装程序所需的软件包。对于某些安装类型,集群要安装到的环境不需要访问互联网。在更新集群之前,要更新 registry 镜像系统中的内容。
1.6.5. 生成 SSH 私钥并将其添加到代理中
如果要在集群上执行安装调试或灾难恢复,则必须为 ssh-agent
和安装程序提供 SSH 密钥。
在生产环境中,您需要进行灾难恢复和调试。
您可以使用此密钥以 core
用户身份通过 SSH 连接到 master 节点。在部署集群时,此密钥会添加到 core
用户的 ~/.ssh/authorized_keys
列表中。
您必须使用一个本地密钥,而不要使用在特定平台上配置的密钥,如 AWS 密钥对。
流程
如果还没有为计算机上免密码身份验证而配置的 SSH 密钥,请创建一个。例如,在使用 Linux 操作系统的计算机上运行以下命令:
$ ssh-keygen -t rsa -b 4096 -N '' \ -f <path>/<file_name> 1
- 1
- 指定 SSH 密钥的路径和文件名,如
~/.ssh/id_rsa
。不要指定已存在的 SSH 密钥,因为它会被覆盖。
运行此命令会在指定的位置生成不需要密码的 SSH 密钥。
作为后台任务启动
ssh-agent
进程:$ eval "$(ssh-agent -s)" Agent pid 31874
将 SSH 私钥添加到
ssh-agent
:$ ssh-add <path>/<file_name> 1 Identity added: /home/<you>/<path>/<file_name> (<computer_name>)
- 1
- 指定 SSH 私钥的路径和文件名,如
~/.ssh/id_rsa
后续步骤
- 在安装 OpenShift Container Platform 时,为安装程序提供 SSH 公钥。
1.6.6. 获取安装程序
在安装 OpenShift Container Platform 之前,将安装文件下载到本地计算机上。
先决条件
- 必须从使用 Linux 或 macOS 的计算机安装集群。
- 需要 500 MB 本地磁盘空间来下载安装程序。
流程
- 访问 Red Hat OpenShift Cluster Manager 网站的 Infrastructure Provider 页面。如果您有红帽帐号,请使用自己的凭证登录。如果没有,请创建一个帐户。
进入适用于您的安装类型的页面,下载您的操作系统的安装程序,并将文件放在要保存安装配置文件的目录中。。
重要安装程序会在用来安装集群的计算机上创建若干文件。在完成集群安装后,您必须保留安装程序和安装程序所创建的文件。
重要删除安装程序创建的文件不会删除您的集群,即使集群在安装过程中失败也是如此。您必须完成针对特定云供应商的 OpenShift Container Platform 卸载流程,才能完全删除您的集群。
提取安装程序。例如,在使用 Linux 操作系统的计算机上运行以下命令:
$ tar xvf <installation_program>.tar.gz
-
在 Red Hat OpenShift Cluster Manager 站点的 Pull Secret 页面中,下载您的安装 pull secret 的
.txt
文件。通过此 pull secret,您可以进行所含授权机构提供的服务的身份验证,这些服务包括为 OpenShift Container Platform 组件提供容器镜像的 Quay.io。
1.6.7. 创建安装配置文件
您可以自定义 OpenShift Container Platform 安装
先决条件
- 获取 OpenShift Container Platform 安装程序以及集群的 pull secret。
流程
创建
install-config.yaml
文件。运行以下命令:
$ ./openshift-install create install-config --dir=<installation_directory> 1
- 1
- 对于
<installation_directory>
,请指定用于保存安装程序所创建的文件的目录名称。
重要指定一个空目录。一些安装信息,如 bootstrap X.509 证书,有较短的过期间隔,因此不要重复使用安装目录。如果要重复使用另一个集群安装中的个别文件,可以将其复制到您的目录中。但是,一些安装数据的文件名可能会在发行版本之间有所改变。从 OpenShift Container Platform 老版本中复制安装文件时要格外小心。
在提示符处,提供您的云的配置详情:
可选:选择用来访问集群机器的 SSH 密钥。
注意对于您要在其上执行安装调试或灾难恢复的生产环境 OpenShift Container Platform 集群,请指定
ssh-agent
进程使用的 SSH 密钥。- 为集群输入一个描述性名称。
- 粘贴从 Red Hat OpenShift Cluster Manager 站点的 Pull Secret 页面中获取的 pull secret。
-
修改
install-config.yaml
文件。您可以在安装配置参数部分中找到有关可用参数的更多信息。 备份
install-config.yaml
文件,以便用于安装多个集群。重要install-config.yaml
文件会在安装过程中消耗掉。如果要重复使用此文件,必须现在备份。
1.6.7.1. 安装配置参数
在部署 OpenShift Container Platform 集群前,您可以提供参数值,以描述托管集群的云平台的帐户并选择性地自定义集群平台。在创建 install-config.yaml
安装配置文件时,您可以通过命令行来提供所需的参数的值。如果要自定义集群,可以修改 install-config.yaml
文件来提供关于平台的更多信息。
安装之后,您无法修改 install-config.yaml
文件中的这些参数。
参数 | 描述 | 值 |
---|---|---|
|
云供应商的基域。此值用于创建到 OpenShift Container Platform 集群组件的路由。集群的完整 DNS 名称是 |
完全限定域名或子域名,如 |
|
托管 control plane 机器的云供应商。此参数值必须与 |
|
|
托管 worker 机器的云供应商。此参数值必须与 |
|
| 集群的名称。 |
包含大写字母或小写字母的字符串,如 |
| 集群要部署到的区域。 |
云的有效区域,如 AWS 的 |
| 从 Red Hat OpenShift Cluster Manager 站点的 Pull Secret 页面中获取的 pull secret。您可以使用此 pull secret 来进行所含授权机构提供的服务的身份验证,这些服务包括为 OpenShift Container Platform 组件提供容器镜像的 Quay.io。 |
{ "auths":{ "cloud.openshift.com":{ "auth":"b3Blb=", "email":"you@example.com" }, "quay.io":{ "auth":"b3Blb=", "email":"you@example.com" } } } |
参数 | 描述 | 值 |
---|---|---|
| 用于访问集群机器的 SSH 密钥。 注意
对于您要在其上执行安装调试或灾难恢复的生产环境 OpenShift Container Platform 集群,请指定 |
添加到 |
| 是否启用或禁用 FIPS 模式。默认情况下不启用 FIPS 模式。如果启用了 FIPS 模式,运行 OpenShift Container Platform 的 Red Hat Enterprise Linux CoreOS (RHCOS) 机器会绕过默认的 Kubernetes 加密套件,并使用由 RHCOS 提供的加密模块。 |
|
| 如何发布集群的面向用户的端点。 |
|
|
是否在计算机器上启用或禁用并发多线程或 重要 如果禁用并发多线程,请确保在容量规划时考虑到机器性能可能会显著降低的问题。 |
|
| 要置备的计算机器数量,也称为 worker 机器。 |
大于或等于 |
|
是否在 control plane 机器上启用或禁用并发多线程或 重要 如果禁用并发多线程,请确保在容量规划时考虑到机器性能可能会显著降低的问题。 |
|
| 要置备的 control plane 机器数量。 |
大于或等于 |
参数 | 描述 | 值 |
---|---|---|
| 为根卷保留的每秒输入/输出操作 (IOPS) 数。 |
整数,如 |
| 以 GiB 为单位的根卷大小。 |
整数,如 |
| 根卷的实例类型。 |
有效的 AWS EBS 实例类型,如 |
| 计算机器的 EC2 实例类型。 |
有效的 AWS 实例类型,如 |
| 安装程序在其中为计算 MachinePool 创建机器的可用区。如果您提供自己的 VPC,则必须在那个可用域中提供一个子网。 |
有效 AWS 可用区的列表,如 |
| 安装程序在其中创建计算资源的 AWS 区域。 |
有效的 AWS 区域,如 |
| control plane 机器的 EC2 实例类型。 |
有效的 AWS 实例类型,如 |
| 安装程序在其中为 control plane MachinePool 创建机器的可用区。 |
有效 AWS 可用区的列表,如 |
| 安装程序在其中创建 control plane 资源的 AWS 区域。 |
有效的 AWS 区域,如 |
| 键与值的映射,安装程序将其作为标签添加到它所创建的所有资源。 |
任何有效的 YAML 映射,如 |
|
如果您提供 VPC,而不是让安装程序为您创建 VPC,请指定要使用的集群子网。子网必须是您指定的同一 | 有效的子网 ID。 |
1.6.7.2. AWS 的自定义 install-config.yaml
文件示例
您可以自定义 install-config.yaml
文件,以指定有关 OpenShift Container Platform 集群平台的更多信息,或修改所需参数的值。
此示例 YAML 文件仅供参考。您必须使用安装程序来获取 install-config.yaml
文件,并且修改该文件。
apiVersion: v1 baseDomain: example.com 1 controlPlane: 2 hyperthreading: Enabled 3 4 name: master platform: aws: zones: - us-west-2a - us-west-2b rootVolume: iops: 4000 size: 500 type: io1 type: m5.xlarge 5 replicas: 3 compute: 6 - hyperthreading: Enabled 7 name: worker platform: aws: rootVolume: iops: 2000 size: 500 type: io1 8 type: c5.4xlarge zones: - us-west-2c replicas: 3 metadata: name: test-cluster 9 networking: clusterNetwork: - cidr: 10.128.0.0/14 hostPrefix: 23 machineCIDR: 10.0.0.0/16 networkType: OpenShiftSDN serviceNetwork: - 172.30.0.0/16 platform: aws: region: us-west-2 10 userTags: adminContact: jdoe costCenter: 7536 subnets: 11 - subnet-1 - subnet-2 - subnet-3 pullSecret: '{"auths": ...}' 12 fips: false 13 sshKey: ssh-ed25519 AAAA... 14 publish: Internal 15
- 1 9 10 12
- 必需。安装程序会提示您输入这个值。
- 2 6
- 如果没有提供这些参数和值,安装程序会提供默认值。
- 3 7
controlPlane
部分是一个单映射,但 compute 部分是一系列映射。为满足不同数据结构的要求,compute
部分的第一行必须以连字符-
开头,controlPlane
部分的第一行则不可以连字符开头。虽然这两个部分目前都定义单个机器池,但未来的 OpenShift Container Platform 版本可能会支持在安装过程中定义多个计算池。只使用一个 control plane 池。- 4 5
- 是否要启用或禁用并发多线程或
超线程
。默认情况下,启用并发多线程以提高机器内核的性能。您可以通过将参数值设为Disabled
来禁用。如果您在某些集群机器上禁用并发多线程,则必须在所有集群机器上禁用。重要如果禁用并发多线程,请确保在容量规划时考虑到机器性能可能会显著降低的问题。如果您对机器禁用并发多线程,请使用较大的实例类型,如
m4.2xlarge
或m5.2xlarge
。 - 8
- 要为 etcd 配置更快的存储,特别是对于较大的集群,请将存储类型设置为
io1
,并将iops
设为2000
。 - 11
- 如果您提供自己的 VPC,为集群使用的每个可用区指定子网。
- 13
- 是否启用或禁用 FIPS 模式。默认情况下不启用 FIPS 模式。如果启用了 FIPS 模式,运行 OpenShift Container Platform 的 Red Hat Enterprise Linux CoreOS (RHCOS) 机器会绕过默认的 Kubernetes 加密套件,并使用由 RHCOS 提供的加密模块。
- 14
- 您可以选择提供您用来访问集群中机器的
sshKey
值。注意对于您要在其上执行安装调试或灾难恢复的生产环境 OpenShift Container Platform 集群,请指定
ssh-agent
进程使用的 SSH 密钥。 - 15
- 如何发布集群的面向用户的端点。把
publish
设置为Internal
以部署一个私有集群,它不能被互联网访问。默认值为External
。
1.6.7.3. 在安装过程中配置集群范围代理
生产环境可能会拒绝直接访问互联网,而是提供 HTTP 或 HTTPS 代理。您可以通过在 install-config.yaml
文件中配置代理设置,将新的 OpenShift Container Platform 集群配置为使用代理。
先决条件
-
现有的
install-config.yaml
文件。 查看集群需要访问的站点,并决定是否需要绕过代理。默认情况下代理所有集群出口流量,包括对托管云供应商 API 的调用。若有需要,将站点添加到 Proxy 对象的
spec.noProxy
字段来绕过代理服务器。注意Proxy 对象的
status.noProxy
字段默认填充实例元数据端点 (169.254.169.254
),以及您的安装配置中networking.machineCIDR
、networking.clusterNetwork.cidr
和networking.serviceNetwork[]
字段的值。
流程
编辑
install-config.yaml
文件并添加代理设置。例如:apiVersion: v1 baseDomain: my.domain.com proxy: httpProxy: http://<username>:<pswd>@<ip>:<port> 1 httpsProxy: http://<username>:<pswd>@<ip>:<port> 2 noProxy: example.com 3 additionalTrustBundle: | 4 -----BEGIN CERTIFICATE----- <MY_TRUSTED_CA_CERT> -----END CERTIFICATE----- ...
- 1
- 用于创建集群外 HTTP 连接的代理 URL。URL 必须是
http
。如果您使用不要求额外代理配置但需要额外 CA 的 MITM 透明代理网络,则不得指定httpProxy
值。 - 2
- 用于创建集群外 HTTPS 连接的代理 URL。如果未指定此字段,
httpProxy
会同时用于 HTTP 和 HTTPS 连接。如果您使用不要求额外代理配置但需要额外 CA 的 MITM 透明代理网络,则不得指定httpsProxy
值。 - 3
- 要排除代理的目标域名、域、IP 地址或其他网络 CIDR 的逗号分隔列表。域之前加上前缀
.
可包含该域的所有子域。使用*
可对所有目的地绕过所有代理。 - 4
- 如果提供,安装程序会在
openshift-config
命名空间中生成名为user-ca-bundle
的 ConfigMap,其包含代理 HTTPS 连接所需的一个或多个额外 CA 证书。然后,Cluster Network Operator 会创建trusted-ca-bundle
ConfigMap,将这些内容与 Red Hat Enterprise Linux CoreOS (RHCOS) 信任捆绑包合并,Proxy 对象的trustedCA
字段中也会引用此 ConfigMap。additionalTrustBundle
字段是必需的,除非代理的身份证书由来自 RHCOS 信任捆绑包的颁发机构签名。如果您使用不要求额外代理配置但需要额外 CA 的 MITM 透明代理网络,您必须提供 MITM CA 证书。
注意安装程序不支持代理的
readinessEndpoints
字段。- 保存该文件,并在安装 OpenShift Container Platform 时引用。
安装程序会创建一个名为 cluster
的集群范围代理,该代理使用提供的 install-config.yaml
文件中的代理设置。如果没有提供代理设置,仍然会创建 cluster
Proxy 对象,但它会有一个零 spec
。
只支持名为 cluster
的 Proxy 对象,且无法创建额外的代理。
1.6.8. 部署集群
您可以在兼容云平台中安装 OpenShift Container Platform。
安装程序的 create cluster
命令只能在初始安装过程中运行一次。
先决条件
- 配置托管集群的云平台的帐户。
- 获取 OpenShift Container Platform 安装程序以及集群的 pull secret。
流程
运行安装程序:
$ ./openshift-install create cluster --dir=<installation_directory> \ 1 --log-level=info 2
注意如果您在主机上配置的云供应商帐户没有足够的权限来部署集群,安装过程将会停止,并且显示缺少的权限。
集群部署完成后,终端会显示访问集群的信息,包括指向其 Web 控制台的链接和
kubeadmin
用户的凭证。重要安装程序生成的 Ignition 配置文件中所含的证书会在 24 小时后过期。您必须以非降级状态持续运行集群 24 小时,以确保完成第一次证书轮转。
重要您不得删除安装程序或安装程序所创建的文件。需要这两者才能删除集群。
1.6.9. 通过下载二进制文件安装 CLI
您需要安装 CLI(oc
) 来使用命令行界面与 OpenShift Container Platform 进行交互。您可在 Linux 、Windows 或 macOS 上安装 oc
。
如果安装了旧版本的 oc
,则无法使用 OpenShift Container Platform 4.3 中的所有命令。下载并安装新版本的 oc
。
1.6.9.1. 在 Linux 上安装 CLI
您可以按照以下流程在 Linux 上安装 OpenShift CLI(oc
)二进制文件。
流程
- 访问 Red Hat OpenShift Cluster Manager 网站的 Infrastructure Provider 页面。
- 选择您的基础架构供应商及安装类型。
- 在 Command-line interface 部分,从下拉菜单中选择 Linux,并点 Download command-line tools。
解包存档:
$ tar xvzf <file>
把
oc
二进制代码放到PATH
中的目录中。执行以下命令可以查看当前的
PATH
设置:$ echo $PATH
安装 CLI 后,就可以使用oc
命令:
$ oc <command>
1.6.9.2. 在 Windows 上安装 CLI
您可以按照以下流程在 Windows 上安装 OpenShift CLI(oc
)二进制代码。
流程
- 访问 Red Hat OpenShift Cluster Manager 网站的 Infrastructure Provider 页面。
- 选择您的基础架构供应商及安装类型。
- 在 Command-line interface 部分,从下拉菜单中选择 Windows,点 Download command-line tools。
- 使用 ZIP 程序解压存档。
把
oc
二进制代码放到PATH
中的目录中。要查看您的
PATH
,请打开命令提示窗口并执行以下命令:C:\> path
安装 CLI 后,就可以使用oc
命令:
C:\> oc <command>
1.6.9.3. 在 macOS 上安装 CLI
您可以按照以下流程在 macOS 上安装 OpenShift CLI(oc
)二进制代码。
流程
- 访问 Red Hat OpenShift Cluster Manager 网站的 Infrastructure Provider 页面。
- 选择您的基础架构供应商及安装类型。
- 在 Command-line interface 部分,从下拉菜单中选择 MacOS,并点 Download command-line tools。
- 解包和解压存档。
将
oc
二进制文件移到 PATH 的目录中。要查看您的
PATH
,打开一个终端窗口并执行以下命令:$ echo $PATH
安装 CLI 后,就可以使用oc
命令:
$ oc <command>
1.6.10. 登录集群
您可以通过导出集群 kubeconfig
文件,以默认系统用户身份登录集群。kubeconfig
文件包含关于集群的信息,供 CLI 用于将客户端连接到正确集群和 API 服务器。该文件特只适用于一个特定的集群,在 OpenShift Container Platform 安装过程中创建。
先决条件
- 部署 OpenShift Container Platform 集群。
-
安装
oc
CLI。
流程
导出
kubeadmin
凭证:$ export KUBECONFIG=<installation_directory>/auth/kubeconfig 1
- 1
- 对于
<installation_directory>
,请指定安装文件保存到的目录的路径。
使用导出的配置,验证能否成功运行
oc
命令:$ oc whoami system:admin
1.6.11. 后续步骤
- 自定义集群。
- 若有需要,您可以选择不使用远程健康报告。
1.7. 使用 CloudFormation 模板在 AWS 中用户置备的基础架构上安装集群
在 OpenShift Container Platform 版本 4.3 中,您可以使用您提供的基础架构在 Amazon Web Services (AWS) 上安装集群。
创建此基础架构的一种方法是使用提供的 CloudFormation 模板。您可以修改模板来自定义基础架构,或使用其包含的信息来按照公司策略创建 AWS 对象。
1.7.1. 先决条件
- 查看有关 OpenShift Container Platform 安装和更新流程的详细信息。
配置 AWS 帐户以托管集群。
重要如果您的计算机上存储有 AWS 配置集,则不要在使用多因素验证设备的同时使用您生成的临时会话令牌。在集群的整个生命周期中,集群会持续使用您的当前 AWS 凭证来创建 AWS 资源,因此您必须使用基于密钥的长期凭证。要生成适当的密钥,请参阅 AWS 文档中的管理 IAM 用户的访问密钥。您可在运行安装程序时提供密钥。
- 下载 AWS CLI 并安装到您的计算机上。请参阅 AWS 文档中的使用捆绑安装程序(Linux、macOS 或 Unix)安装 AWS CLI。
如果使用防火墙,则必须将其配置为允许集群需要访问的站点。
注意如果您要配置代理,请务必也要查看此站点列表。
- 如果不允许系统管理身份和访问管理(IAM),集群管理员可以手动创建和维护 IAM 凭证。手动模式也可以用于云 IAM API 无法访问的环境中。
1.7.2. OpenShift Container Platform 对互联网和 Telemetry 的访问
在 OpenShift Container Platform 4.3 中,您需要访问互联网来安装集群。默认运行的 Telemetry 服务提供有关集群健康状况和成功更新的指标,这也需要访问互联网。如果您的集群连接到互联网,Telemetry 会自动运行,而且集群会注册到 Red Hat OpenShift Cluster Manager(OCM)。
确认 Red Hat OpenShift Cluster Manager 清单正确后,可以由 Telemetry 自动维护,也可以使用 OCM 手动维护,使用订阅监控 来跟踪帐户或多集群级别的 OpenShift Container Platform 订阅。
您必须具有以下互联网访问权限:
- 访问 Red Hat OpenShift Cluster Manager 页面,以下载安装程序并执行订阅管理。如果集群可以访问互联网,并且没有禁用 Telemetry,该服务会自动授权您的集群。
- 访问 Quay.io,以获取安装集群所需的软件包。
- 获取执行集群更新所需的软件包。
如果您的集群无法直接访问互联网,则可以在置备的某些类基础架构上执行受限网络安装。在此过程中,您要下载所需的内容,并使用它在镜像 registry(mirror registry) 中填充安装集群并生成安装程序所需的软件包。对于某些安装类型,集群要安装到的环境不需要访问互联网。在更新集群之前,要更新 registry 镜像系统中的内容。
1.7.3. 所需的 AWS 基础架构组件
要在 Amazon Web Services (AWS) 中用户置备的基础架构上安装 OpenShift Container Platform,您必须手动创建机器及其支持的基础架构。
如需有关不同平台集成测试的更多信息,请参阅 OpenShift Container Platform 4.x Tested Integrations页面。
您可以使用提供的 CloudFormation 模板创建此基础架构,也可以手动创建组件,或者重复使用满足集群要求的现有基础架构。查看 CloudFormation 模板,了解组件如何相互连接的更多详情。
1.7.3.1. 集群机器
以下机器需要 AWS::EC2::Instance
对象:
- bootstrap 机器。安装过程中需要此机器,但可在集群部署后删除。
- 至少三台 control plane 机器。control plane 机器不受 MachineSet 的管控。
- 计算机器。在安装过程中创建至少两台计算(compute)机器(也称为 worker 机器)。这些机器不受 MachineSet 的管控。
您可以通过提供的 CloudFormation 模板,为集群机器使用以下实例类型。
如果您的区域中没有 m4
实例类型,例如 eu-west-3
,请改为使用 m5
类型。
实例类型 | bootstrap | Control plane | Compute |
---|---|---|---|
| x | ||
| x | ||
| x | x | |
| x | x | |
| x | x | |
| x | x | |
| x | x | |
| x | x | |
| x | ||
| x | ||
| x | x | |
| x | x | |
| x | x | |
| x | ||
| x | x | |
| x | x | |
| x | x | |
| x | x | |
| x | x |
您可能能够使用符合这些实例类型规格的其他实例类型。
1.7.3.2. 证书签名请求管理
在使用您置备的基础架构时,集群只能有限地访问自动机器管理,因此您必须提供一种在安装后批准集群证书签名请求 (CSR) 的机制。kube-controller-manager
只能批准 kubelet 客户端 CSR。machine-approver
无法保证使用 kubelet 凭证请求的提供证书的有效性,因为它不能确认是正确的机器发出了该请求。您必须决定并实施一种方法,以验证 kubelet 提供证书请求的有效性并进行批准。
1.7.3.3. 其他基础架构组件
- VPC
- DNS 条目
- 负载均衡器(典型或网络)和监听器
- 公共和专用 Route53 区
- 安全组
- IAM 角色
- S3 存储桶
如果您在断开连接的环境中工作,您将无法访问 EC2 和 ELB 端点的公共 IP 地址。要解决这个问题,您必须创建一个 VPC 端点,并将其附加到集群使用的子网。端点应命名如下:
-
ec2.<region>.amazonaws.com
-
elasticloadbalancing.<region>.amazonaws.com
-
s3.<region>.amazonaws.com
所需的 VPC 组件
您必须提供合适的 VPC 和子网,以便与您的机器通信。
组件 | AWS 类型 | 描述 | |
---|---|---|---|
VPC |
| 您必须提供一个公共 VPC 供集群使用。VPC 使用引用每个子网的路由表的端点,以改进与托管在 S3 中的 registry 的通信。 | |
公共子网 |
| 您的 VPC 必须有 1 到 3 个可用区的公共子网,并将其与适当的入口规则关联。 | |
互联网网关 |
| 您必须有一个公共互联网网关,以及附加到 VPC 的公共路由。在提供的模板中,每个公共子网都有一个具有 EIP 地址的 NAT 网关。这些 NAT 网关允许集群资源(如专用子网实例)访问互联网,而有些受限网络或代理场景则不需要它们。 | |
网络访问控制 |
| 您必须允许 VPC 访问下列端口: | |
端口 | 原因 | ||
| 入站 HTTP 流量 | ||
| 入站 HTTPS 流量 | ||
| 入站 SSH 流量 | ||
| 入站临时流量 | ||
| 出站临时流量 | ||
专用子网 |
| 您的 VPC 可以具有私有子网。提供的 CloudFormation 模板可为 1 到 3 个可用区创建专用子网。如果您使用专用子网,必须为其提供适当的路由和表。 |
所需的 DNS 和负载均衡组件
您的 DNS 和负载均衡器配置需要使用公共托管区,并可使用类似安装程序使用的专用托管区(如果安装程序置备了集群的基础架构)。您必须创建一个解析到负载均衡器的 DNS 条目。api.<cluster_name>.<domain>
的条目必须指向外部负载均衡器,api-int.<cluster_name>.<domain>
的条目则必须指向内部负载均衡器。
集群还需要负载均衡器,以及监听端口 6443(用于 Kubernetes API 及其扩展)和端口 22623(用于新机器的 Ignition 配置文件)的监听程序。目标是 master 节点。集群外的客户端和集群内的节点都必须能够访问端口 6443。集群内的节点必须能够访问端口 22623。
组件 | AWS 类型 | 描述 |
---|---|---|
DNS |
| 内部 DNS 的托管区。 |
etcd 记录集 |
| control plane 机器的 etcd 注册记录。 |
公共负载均衡器 |
| 公共子网的负载均衡器。 |
外部 API 服务器记录 |
| 外部 API 服务器的别名记录。 |
外部监听程序 |
| 为外部负载均衡器监听端口 6443 的监听程序。 |
外部目标组 |
| 外部负载均衡器的目标组。 |
专用负载均衡器 |
| 专用子网的负载均衡器。 |
内部 API 服务器记录 |
| 内部 API 服务器的别名记录。 |
内部监听程序 |
| 为内部负载均衡器监听端口 22623 的监听程序。 |
内部目标组 |
| 内部负载均衡器的目标组。 |
内部监听程序 |
| 为内部负载均衡器监听端口 6443 的监听程序。 |
内部目标组 |
| 内部负载均衡器的目标组。 |
安全组
control plane 和 worker 机器需要访问下列端口:
组 | 类型 | IP 协议 | 端口范围 |
---|---|---|---|
MasterSecurityGroup |
|
|
|
|
| ||
|
| ||
|
| ||
WorkerSecurityGroup |
|
|
|
|
| ||
BootstrapSecurityGroup |
|
|
|
|
|
control plane 入口
control plane 机器需要以下入口组。每个入口组都是 AWS::EC2::SecurityGroupIngress
资源。
入口组 | 描述 | IP 协议 | 端口范围 |
---|---|---|---|
| etcd |
|
|
| Vxlan 数据包 |
|
|
| Vxlan 数据包 |
|
|
| 内部集群通信和 Kubernetes 代理指标 |
|
|
| 内部集群通信 |
|
|
| kubernetes kubelet、调度程序和控制器管理器 |
|
|
| kubernetes kubelet、调度程序和控制器管理器 |
|
|
| Kubernetes 入口服务 |
|
|
| Kubernetes 入口服务 |
|
|
worker 入口
worker 机器需要以下入口组。每个入口组都是 AWS::EC2::SecurityGroupIngress
资源。
入口组 | 描述 | IP 协议 | 端口范围 |
---|---|---|---|
| Vxlan 数据包 |
|
|
| Vxlan 数据包 |
|
|
| 内部集群通信 |
|
|
| 内部集群通信 |
|
|
| kubernetes kubelet、调度程序和控制器管理器 |
|
|
| kubernetes kubelet、调度程序和控制器管理器 |
|
|
| Kubernetes 入口服务 |
|
|
| Kubernetes 入口服务 |
|
|
角色和实例配置集
您必须在 AWS 中为机器授予权限。提供的 CloudFormation 模板通过以下 AWS::IAM::Role
对象为机器授予权限,并为每一组角色提供 AWS::IAM::InstanceProfile
。如果不使用模板,您可以为机器授予以下宽泛权限或单独权限。
角色 | 影响 | 操作 | 资源 |
---|---|---|---|
Master |
|
|
|
|
|
| |
|
|
| |
|
|
| |
Worker |
|
|
|
bootstrap |
|
|
|
|
|
| |
|
|
|
1.7.3.4. 所需的 AWS 权限
将 AdministratorAccess
策略附加到您在 Amazon Web Services (AWS) 中创建的 IAM 用户时,授予该用户所有需要的权限。要部署 OpenShift Container Platform 集群的所有组件,IAM 用户需要以下权限:
安装所需的 EC2 权限
-
ec2:AllocateAddress
-
ec2:AssociateAddress
-
ec2:AuthorizeSecurityGroupEgress
-
ec2:AuthorizeSecurityGroupIngress
-
ec2:CopyImage
-
ec2:CreateNetworkInterface
-
ec2:CreateSecurityGroup
-
ec2:CreateTags
-
ec2:CreateVolume
-
ec2:DeleteSecurityGroup
-
ec2:DeleteSnapshot
-
ec2:DeregisterImage
-
ec2:DescribeAccountAttributes
-
ec2:DescribeAddresses
-
ec2:DescribeAvailabilityZones
-
ec2:DescribeDhcpOptions
-
ec2:DescribeImages
-
ec2:DescribeInstanceAttribute
-
ec2:DescribeInstanceCreditSpecifications
-
ec2:DescribeInstances
-
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:ModifyInstanceAttribute
-
ec2:ModifyNetworkInterfaceAttribute
-
ec2:ReleaseAddress
-
ec2:RevokeSecurityGroupEgress
-
ec2:RevokeSecurityGroupIngress
-
ec2:RunInstances
-
ec2:TerminateInstances
安装过程中创建网络资源所需的权限
-
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,您的帐户不需要这些权限来创建网络资源。
安装所需的 Elasticloadbalancing 权限
-
elasticloadbalancing:AddTags
-
elasticloadbalancing:ApplySecurityGroupsToLoadBalancer
-
elasticloadbalancing:AttachLoadBalancerToSubnets
-
elasticloadbalancing:ConfigureHealthCheck
-
elasticloadbalancing:CreateListener
-
elasticloadbalancing:CreateLoadBalancer
-
elasticloadbalancing:CreateLoadBalancerListeners
-
elasticloadbalancing:CreateTargetGroup
-
elasticloadbalancing:DeleteLoadBalancer
-
elasticloadbalancing:DeregisterInstancesFromLoadBalancer
-
elasticloadbalancing:DeregisterTargets
-
elasticloadbalancing:DescribeInstanceHealth
-
elasticloadbalancing:DescribeListeners
-
elasticloadbalancing:DescribeLoadBalancerAttributes
-
elasticloadbalancing:DescribeLoadBalancers
-
elasticloadbalancing:DescribeTags
-
elasticloadbalancing:DescribeTargetGroupAttributes
-
elasticloadbalancing:DescribeTargetHealth
-
elasticloadbalancing:ModifyLoadBalancerAttributes
-
elasticloadbalancing:ModifyTargetGroup
-
elasticloadbalancing:ModifyTargetGroupAttributes
-
elasticloadbalancing:RegisterInstancesWithLoadBalancer
-
elasticloadbalancing:RegisterTargets
-
elasticloadbalancing:SetLoadBalancerPoliciesOfListener
安装所需的 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
安装所需的 Route53 权限
-
route53:ChangeResourceRecordSets
-
route53:ChangeTagsForResource
-
route53:CreateHostedZone
-
route53:DeleteHostedZone
-
route53:GetChange
-
route53:GetHostedZone
-
route53:ListHostedZones
-
route53:ListHostedZonesByName
-
route53:ListResourceRecordSets
-
route53:ListTagsForResource
-
route53:UpdateHostedZoneComment
安装所需的 S3 权限
-
s3:CreateBucket
-
s3:DeleteBucket
-
s3:GetAccelerateConfiguration
-
s3:GetBucketCors
-
s3:GetBucketLocation
-
s3:GetBucketLogging
-
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
集群 Operators 所需的 S3 权限
-
s3:DeleteObject
-
s3:GetObject
-
s3:GetObjectAcl
-
s3:GetObjectTagging
-
s3:GetObjectVersion
-
s3:PutObject
-
s3:PutObjectAcl
-
s3:PutObjectTagging
删除基本集群资源所需的权限
-
autoscaling:DescribeAutoScalingGroups
-
ec2:DeleteNetworkInterface
-
ec2:DeleteVolume
-
elasticloadbalancing:DeleteTargetGroup
-
elasticloadbalancing:DescribeTargetGroups
-
iam:ListInstanceProfiles
-
iam:ListRolePolicies
-
iam:ListUserPolicies
-
s3:DeleteObject
-
tag:GetResources
删除网络资源所需的权限
-
ec2:DeleteDhcpOptions
-
ec2:DeleteInternetGateway
-
ec2:DeleteNatGateway
-
ec2:DeleteRoute
-
ec2:DeleteRouteTable
-
ec2:DeleteSubnet
-
ec2:DeleteVpc
-
ec2:DeleteVpcEndpoints
-
ec2:DetachInternetGateway
-
ec2:DisassociateRouteTable
-
ec2:ReplaceRouteTableAssociation
如果您使用现有的 VPC,您的帐户不需要这些权限来删除网络资源。
创建清单所需的额外 IAM 和 S3 权限
-
iam:CreateAccessKey
-
iam:CreateUser
-
iam:DeleteAccessKey
-
iam:DeleteUser
-
iam:DeleteUserPolicy
-
iam:GetUserPolicy
-
iam:ListAccessKeys
-
iam:PutUserPolicy
-
iam:TagUser
-
iam:GetUserPolicy
-
iam:ListAccessKeys
-
s3:PutBucketPublicAccessBlock
-
s3:GetBucketPublicAccessBlock
-
s3:PutLifecycleConfiguration
-
s3:HeadBucket
-
s3:ListBucketMultipartUploads
-
s3:AbortMultipartUpload
1.7.4. 获取安装程序
在安装 OpenShift Container Platform 之前,将安装文件下载到本地计算机上。
先决条件
- 必须从使用 Linux 或 macOS 的计算机安装集群。
- 需要 500 MB 本地磁盘空间来下载安装程序。
流程
- 访问 Red Hat OpenShift Cluster Manager 网站的 Infrastructure Provider 页面。如果您有红帽帐号,请使用自己的凭证登录。如果没有,请创建一个帐户。
进入适用于您的安装类型的页面,下载您的操作系统的安装程序,并将文件放在要保存安装配置文件的目录中。。
重要安装程序会在用来安装集群的计算机上创建若干文件。在完成集群安装后,您必须保留安装程序和安装程序所创建的文件。
重要删除安装程序创建的文件不会删除您的集群,即使集群在安装过程中失败也是如此。您必须完成针对特定云供应商的 OpenShift Container Platform 卸载流程,才能完全删除您的集群。
提取安装程序。例如,在使用 Linux 操作系统的计算机上运行以下命令:
$ tar xvf <installation_program>.tar.gz
-
在 Red Hat OpenShift Cluster Manager 站点的 Pull Secret 页面中,下载您的安装 pull secret 的
.txt
文件。通过此 pull secret,您可以进行所含授权机构提供的服务的身份验证,这些服务包括为 OpenShift Container Platform 组件提供容器镜像的 Quay.io。
1.7.5. 生成 SSH 私钥并将其添加到代理中
如果要在集群上执行安装调试或灾难恢复,则必须为 ssh-agent
和安装程序提供 SSH 密钥。
在生产环境中,您需要进行灾难恢复和调试。
您可以使用此密钥以 core
用户身份通过 SSH 连接到 master 节点。在部署集群时,此密钥会添加到 core
用户的 ~/.ssh/authorized_keys
列表中。
您必须使用一个本地密钥,而不要使用在特定平台上配置的密钥,如 AWS 密钥对。
流程
如果还没有为计算机上免密码身份验证而配置的 SSH 密钥,请创建一个。例如,在使用 Linux 操作系统的计算机上运行以下命令:
$ ssh-keygen -t rsa -b 4096 -N '' \ -f <path>/<file_name> 1
- 1
- 指定 SSH 密钥的路径和文件名,如
~/.ssh/id_rsa
。不要指定已存在的 SSH 密钥,因为它会被覆盖。
运行此命令会在指定的位置生成不需要密码的 SSH 密钥。
作为后台任务启动
ssh-agent
进程:$ eval "$(ssh-agent -s)" Agent pid 31874
将 SSH 私钥添加到
ssh-agent
:$ ssh-add <path>/<file_name> 1 Identity added: /home/<you>/<path>/<file_name> (<computer_name>)
- 1
- 指定 SSH 私钥的路径和文件名,如
~/.ssh/id_rsa
后续步骤
- 在安装 OpenShift Container Platform 时,为安装程序提供 SSH 公钥。如果在您置备的基础架构上安装集群,您必须将此密钥提供给集群的机器。
1.7.6. 创建用于 AWS 的安装文件
要使用用户置备的基础架构在 Amazon Web Services (AWS) 上安装 OpenShift Container Platform,您必须生成并修改安装程序部署集群所需的文件,以便集群只创建要使用的机器。您要生成并自定义 install-config.yaml
文件、Kubernetes 清单和 Ignition 配置文件。
1.7.6.1. 创建安装配置文件
生成并自定义安装程序部署集群所需的安装配置文件。
先决条件
- 获取 OpenShift Container Platform 安装程序以及集群的 pull secret。
流程
获取
install-config.yaml
文件。运行以下命令:
$ ./openshift-install create install-config --dir=<installation_directory> 1
- 1
- 对于
<installation_directory>
,请指定用于保存安装程序所创建的文件的目录名称。
重要指定一个空目录。一些安装信息,如 bootstrap X.509 证书,有较短的过期间隔,因此不要重复使用安装目录。如果要重复使用另一个集群安装中的个别文件,可以将其复制到您的目录中。但是,一些安装数据的文件名可能会在发行版本之间有所改变。从 OpenShift Container Platform 老版本中复制安装文件时要格外小心。
在提示符处,提供您的云的配置详情:
可选:选择用来访问集群机器的 SSH 密钥。
注意对于您要在其上执行安装调试或灾难恢复的生产环境 OpenShift Container Platform 集群,请指定
ssh-agent
进程使用的 SSH 密钥。- 选择 aws 作为目标平台。
- 如果计算机上没有保存 AWS 配置集,请为您配置用于运行安装程序的用户输入 AWS 访问密钥 ID 和 secret 访问密钥。
- 选择要将集群部署到的 AWS 区域。
- 选择您为集群配置的 Route53 服务的基域。
- 为集群输入一个描述性名称。
- 粘贴从 Red Hat OpenShift Cluster Manager 站点的 Pull Secret 页面中获取的 pull secret。
编辑
install-config.yaml
文件,将计算副本(也称为 worker 副本)数设为0
,如以下compute
小节中所示:compute: - hyperthreading: Enabled name: worker platform: {} replicas: 0
可选:备份
install-config.yaml
文件。重要install-config.yaml
文件会在安装过程中消耗掉。如果要重复使用此文件,必须现在备份。
1.7.6.2. 在安装过程中配置集群范围代理
生产环境可能会拒绝直接访问互联网,而是提供 HTTP 或 HTTPS 代理。您可以通过在 install-config.yaml
文件中配置代理设置,将新的 OpenShift Container Platform 集群配置为使用代理。
先决条件
-
现有的
install-config.yaml
文件。 查看集群需要访问的站点,并决定是否需要绕过代理。默认情况下代理所有集群出口流量,包括对托管云供应商 API 的调用。若有需要,将站点添加到 Proxy 对象的
spec.noProxy
字段来绕过代理服务器。注意Proxy 对象的
status.noProxy
字段默认填充实例元数据端点 (169.254.169.254
),以及您的安装配置中networking.machineCIDR
、networking.clusterNetwork.cidr
和networking.serviceNetwork[]
字段的值。
流程
编辑
install-config.yaml
文件并添加代理设置。例如:apiVersion: v1 baseDomain: my.domain.com proxy: httpProxy: http://<username>:<pswd>@<ip>:<port> 1 httpsProxy: http://<username>:<pswd>@<ip>:<port> 2 noProxy: example.com 3 additionalTrustBundle: | 4 -----BEGIN CERTIFICATE----- <MY_TRUSTED_CA_CERT> -----END CERTIFICATE----- ...
- 1
- 用于创建集群外 HTTP 连接的代理 URL。URL 必须是
http
。如果您使用不要求额外代理配置但需要额外 CA 的 MITM 透明代理网络,则不得指定httpProxy
值。 - 2
- 用于创建集群外 HTTPS 连接的代理 URL。如果未指定此字段,
httpProxy
会同时用于 HTTP 和 HTTPS 连接。如果您使用不要求额外代理配置但需要额外 CA 的 MITM 透明代理网络,则不得指定httpsProxy
值。 - 3
- 要排除代理的目标域名、域、IP 地址或其他网络 CIDR 的逗号分隔列表。域之前加上前缀
.
可包含该域的所有子域。使用*
可对所有目的地绕过所有代理。 - 4
- 如果提供,安装程序会在
openshift-config
命名空间中生成名为user-ca-bundle
的 ConfigMap,其包含代理 HTTPS 连接所需的一个或多个额外 CA 证书。然后,Cluster Network Operator 会创建trusted-ca-bundle
ConfigMap,将这些内容与 Red Hat Enterprise Linux CoreOS (RHCOS) 信任捆绑包合并,Proxy 对象的trustedCA
字段中也会引用此 ConfigMap。additionalTrustBundle
字段是必需的,除非代理的身份证书由来自 RHCOS 信任捆绑包的颁发机构签名。如果您使用不要求额外代理配置但需要额外 CA 的 MITM 透明代理网络,您必须提供 MITM CA 证书。
注意安装程序不支持代理的
readinessEndpoints
字段。- 保存该文件,并在安装 OpenShift Container Platform 时引用。
安装程序会创建一个名为 cluster
的集群范围代理,该代理使用提供的 install-config.yaml
文件中的代理设置。如果没有提供代理设置,仍然会创建 cluster
Proxy 对象,但它会有一个零 spec
。
只支持名为 cluster
的 Proxy 对象,且无法创建额外的代理。
1.7.6.3. 创建 Kubernetes 清单和 Ignition 配置文件
由于您必须修改一些集群定义文件并要手动启动集群机器,因此您必须生成 Kubernetes 清单和 Ignition 配置文件,集群需要这两项来创建其机器。
安装程序生成的 Ignition 配置文件中所含的证书会在 24 小时后过期。您必须完成集群安装,并使集群以非降级状态运行 24 小时,以确保完成第一次证书轮转。
先决条件
- 获取 OpenShift Container Platform 安装程序。
-
创建
install-config.yaml
安装配置文件。
流程
为集群生成 Kubernetes 清单:
$ ./openshift-install create manifests --dir=<installation_directory> 1 INFO Consuming Install Config from target directory WARNING Making control-plane schedulable by setting MastersSchedulable to true for Scheduler cluster settings
- 1
- 对于
<installation_directory>
,请指定含有您创建的install-config.yaml
文件的安装目录。
由于您稍后会在安装过程中自行创建计算机器,因此可以忽略这个警告。
删除定义 control plane 机器的 Kubernetes 清单文件:
$ rm -f <installation_directory>/openshift/99_openshift-cluster-api_master-machines-*.yaml
通过删除这些文件,您可以防止集群自动生成 control plane 机器。
删除定义 worker 机器的 Kubernetes 清单文件:
$ rm -f <installation_directory>/openshift/99_openshift-cluster-api_worker-machineset-*.yaml
由于您要自行创建并管理 worker 机器,因此不需要初始化这些机器。
修改
<installation_directory>/manifests/cluster-scheduler-02-config.yml
Kubernetes 清单文件,以防止在 control plane 机器上调度 Pod:-
打开
<installation_directory>/manifests/cluster-scheduler-02-config.yml
文件。 -
找到
mastersSchedulable
参数,并将其值设为False
。 - 保存并退出文件。
注意目前,由于 Kubernetes 限制,入口负载均衡器将无法访问在 control plane 机器上运行的路由器 Pod。以后的 OpenShift Container Platform 次要版本中可能不需要这一步骤。
-
打开
可选:如果您不希望 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: {}
如果您这样做,后续步骤中必须手动添加入口 DNS 记录。
获取 Ignition 配置文件:
$ ./openshift-install create ignition-configs --dir=<installation_directory> 1
- 1
- 对于
<installation_directory>
,请指定相同的安装目录。
该目录中将生成以下文件:
. ├── auth │ ├── kubeadmin-password │ └── kubeconfig ├── bootstrap.ign ├── master.ign ├── metadata.json └── worker.ign
1.7.7. 提取基础架构名称
Ignition 配置包含一个唯一集群标识符,您可以使用它在 Amazon Web Services (AWS) 中唯一地标识您的集群。提供的 CloudFormation 模板包含对此基础架构名称的引用,因此您必须提取它。
先决条件
- 获取 OpenShift Container Platform 安装程序以及集群的 pull secret。
- 为集群生成 Ignition 配置文件。
-
安装
jq
软件包。
1.7.8. 在 AWS 中创建 VPC
您必须在 Amazon Web Services (AWS) 中创建一个 VPC,供您的 OpenShift Container Platform 集群使用。您可以自定义 VPC 来满足您的要求,包括 VPN 和路由表。创建 VPC 的最简单方法是修改提供的 CloudFormation 模板。
如果不使用提供的 CloudFormation 模板来创建 AWS 基础架构,您必须检查提供的信息并手动创建基础架构。如果集群没有正确初始化,您可能需要联系红帽支持并提供您的安装日志。
先决条件
- 配置 AWS 帐户。
- 为集群生成 Ignition 配置文件。
流程
创建一个 JSON 文件,其包含模板所需的参数值:
[ { "ParameterKey": "VpcCidr", 1 "ParameterValue": "10.0.0.0/16" 2 }, { "ParameterKey": "AvailabilityZoneCount", 3 "ParameterValue": "1" 4 }, { "ParameterKey": "SubnetBits", 5 "ParameterValue": "12" 6 } ]
- 复制本主题的 VPC 的 CloudFormation 模板部分中的模板,并将它以 YAML 文件形式保存到计算机上。此模板描述了集群所需的 VPC。
启动模板:
重要您必须在一行内输入命令。
$ aws cloudformation create-stack --stack-name <name> 1 --template-body file://<template>.yaml 2 --parameters file://<parameters>.json 3
确认模板组件已存在:
$ aws cloudformation describe-stacks --stack-name <name>
在
StackStatus
显示CREATE_COMPLETE
后,输出会显示以下参数的值。您必须将这些参数值提供给您在创建集群时要运行的其他 CloudFormation 模板:VpcId
您的 VPC ID。
PublicSubnetIds
新公共子网的 ID。
PrivateSubnetIds
新专用子网的 ID。
1.7.8.1. VPC 的 CloudFormation 模板
您可以使用以下 CloudFormation 模板来部署 OpenShift Container Platform 集群所需的 VPC。
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"]] ]
1.7.9. 在 AWS 中创建网络和负载均衡组件
您必须在 Amazon Web Services (AWS) 中配置网络和负载均衡 (classic 或 network),以供您的 OpenShift Container Platform 集群使用。创建这些组件的最简单方法是修改提供的 CloudFormation 模板,该模板还可创建托管区和子网标签。
您可以在单个 VPC 内多次运行该模板。
如果不使用提供的 CloudFormation 模板来创建 AWS 基础架构,您必须检查提供的信息并手动创建基础架构。如果集群没有正确初始化,您可能需要联系红帽支持并提供您的安装日志。
先决条件
- 配置 AWS 帐户。
- 为集群生成 Ignition 配置文件。
- 在 AWS 中创建和配置 VPC 及相关子网。
流程
获取您在
install-config.yaml
文件中为集群指定的 Route53 区的托管区 ID。您可以从 AWS 控制台或运行以下命令来获取此 ID:重要您必须在一行内输入命令。
$ aws route53 list-hosted-zones-by-name | jq --arg name "<route53_domain>." \ 1 -r '.HostedZones | .[] | select(.Name=="\($name)") | .Id'
- 1
- 对于
<route53_domain>
,请指定您为集群生成install-config.yaml
文件时所用的 Route53 基域。
创建一个 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
- 用来注册目标的 Route53 公共区 ID。
- 6
- 指定 Route53 公共区 ID,其格式与
Z21IXYZABCZ2A4
类似。您可以从 AWS 控制台获取这个值。 - 7
- 用来注册目标的 Route53 区。
- 8
- 指定您为集群生成
install-config.yaml
文件时所用的 Route53 基域。请勿包含 AWS 控制台中显示的结尾句点 (.)。 - 9
- 为 VPC 创建的公共子网。
- 10
- 指定 VPC 的 CloudFormation 模板输出的
PublicSubnetIds
值。 - 11
- 为 VPC 创建的专用子网。
- 12
- 指定 VPC 的 CloudFormation 模板输出的
PrivateSubnetIds
值。 - 13
- 为集群创建的 VPC。
- 14
- 指定 VPC 的 CloudFormation 模板输出的
VpcId
值。
- 复制本主题的网络和负载均衡器的 CloudFormation 模板部分中的模板,并将它以 YAML 文件形式保存到计算机上。此模板描述了集群所需的网络和负载均衡对象。
启动模板:
重要您必须在一行内输入命令。
$ aws cloudformation create-stack --stack-name <name> 1 --template-body file://<template>.yaml 2 --parameters file://<parameters>.json 3 --capabilities CAPABILITY_NAMED_IAM
确认模板组件已存在:
$ 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。
1.7.9.1. 网络和负载均衡器的 CloudFormation 模板
您可以使用以下 CloudFormation 模板来部署 OpenShift Container Platform 集群所需的网络对象和负载均衡器。
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: 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: 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: 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.7" 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.7" 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
1.7.10. 在 AWS 中创建安全组和角色
您必须在 Amazon Web Services (AWS) 中创建安全组和角色,供您的 OpenShift Container Platform 集群使用。创建这些组件的最简单方法是修改提供的 CloudFormation 模板。
如果不使用提供的 CloudFormation 模板来创建 AWS 基础架构,您必须检查提供的信息并手动创建基础架构。如果集群没有正确初始化,您可能需要联系红帽支持并提供您的安装日志。
先决条件
- 配置 AWS 帐户。
- 为集群生成 Ignition 配置文件。
- 在 AWS 中创建和配置 VPC 及相关子网。
流程
创建一个 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 } ]
- 复制本主题的安全对象的 CloudFormation 模板部分中的模板,并将它以 YAML 文件形式保存到计算机上。此模板描述了集群所需的安全组和角色。
启动模板:
重要您必须在一行内输入命令。
$ aws cloudformation create-stack --stack-name <name> 1 --template-body file://<template>.yaml 2 --parameters file://<parameters>.json 3 --capabilities CAPABILITY_NAMED_IAM
确认模板组件已存在:
$ aws cloudformation describe-stacks --stack-name <name>
在
StackStatus
显示CREATE_COMPLETE
后,输出会显示以下参数的值。您必须将这些参数值提供给您在创建集群时要运行的其他 CloudFormation 模板:MasterSecurityGroupId
Master 安全组 ID
WorkerSecurityGroupId
worker 安全组 ID
MasterInstanceProfile
Master IAM 实例配置集
WorkerInstanceProfile
worker IAM 实例配置集
1.7.10.1. 安全对象的 CloudFormation 模板
您可以使用以下 CloudFormation 模板来部署 OpenShift Container Platform 集群所需的安全对象。
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 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 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:*" Resource: "*" - Effect: "Allow" Action: "elasticloadbalancing:*" Resource: "*" - Effect: "Allow" Action: "iam:PassRole" Resource: "*" - Effect: "Allow" Action: "s3:GetObject" 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:Describe*" 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
1.7.11. AWS 基础架构的 RHCOS AMI
您必须对 OpenShift Container Platform 节点的 Amazon Web Services (AWS) 区使用有效的 Red Hat Enterprise Linux CoreOS (RHCOS) AMI。
AWS 区 | AWS AMI |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1.7.12. 在 AWS 中创建 bootstrap 节点
您必须在 Amazon Web Services (AWS) 中创建 bootstrap 节点,以便在 OpenShift Container Platform 集群初始化过程中使用。创建此节点的最简单方法是修改提供的 CloudFormation 模板。
如果不使用提供的 CloudFormation 模板来创建 bootstrap 节点,您必须检查提供的信息并手动创建基础架构。如果集群没有正确初始化,您可能需要联系红帽支持并提供您的安装日志。
先决条件
- 配置 AWS 帐户。
- 为集群生成 Ignition 配置文件。
- 在 AWS 中创建和配置 VPC 及相关子网。
- 在 AWS 中创建并配置 DNS、负载均衡器和监听程序。
- 创建 control plane 和计算角色。
流程
提供一个位置,以便向集群提供
bootstrap.ign
Ignition 配置文件。此文件位于您的安装目录中。达成此目标的一种方式是在集群区域中创建一个 S3 存储桶,并将 Ignition 配置文件上传到其中。重要提供的 CloudFormation 模板假定集群的 Ignition 配置文件由 S3 存储桶提供。如果选择从其他位置提供文件,您必须修改模板。
注意bootstrap Ignition 配置文件包含 secret,如 X.509 密钥。以下步骤为 S3 存储桶提供基本安全性。若要提供额外的安全性,您可以启用 S3 存储桶策略,仅允许某些用户(如 OpenShift IAM 用户)访问存储桶中包含的对象。您可以完全避开 S3,并从 bootstrap 可访问的任意地址提供 bootstrap Ignition 配置文件。
创建存储桶:
$ aws s3 mb s3://<cluster-name>-infra 1
- 1
<cluster-name>-infra
是存储桶名称。
将
bootstrap.ign
Ignition 配置文件上传到存储桶:$ aws s3 cp bootstrap.ign s3://<cluster-name>-infra/bootstrap.ign
验证文件已经上传:
$ aws s3 ls s3://<cluster-name>-infra/ 2019-04-03 16:15:16 314878 bootstrap.ign
创建一个 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:<region>:<account_number>:function:<dns_stack_name>-RegisterNlbIpTargets-<random_string>" 18 }, { "ParameterKey": "ExternalApiTargetGroupArn", 19 "ParameterValue": "arn:aws:elasticloadbalancing:<region>:<account_number>:targetgroup/<dns_stack_name>-Exter-<random_string>" 20 }, { "ParameterKey": "InternalApiTargetGroupArn", 21 "ParameterValue": "arn:aws:elasticloadbalancing:<region>:<account_number>:targetgroup/<dns_stack_name>-Inter-<random_string>" 22 }, { "ParameterKey": "InternalServiceTargetGroupArn", 23 "ParameterValue": "arn:aws:elasticloadbalancing:<region>:<account_number>:targetgroup/<dns_stack_name>-Inter-<random_string>" 24 } ]
- 1
- 您的 Ignition 配置文件中为集群编码的集群基础架构名称。
- 2
- 指定从 Ignition 配置文件元数据中提取的基础架构名称,其格式为
<cluster-name>-<random-string>
。 - 3
- 用于 bootstrap 节点的当前 Red Hat Enterprise Linux CoreOS (RHCOS) AMI。
- 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
- 指定
yes
或no
。如果指定yes
,您必须提供一个 Lambda Amazon Resource Name (ARN) 值。 - 17
- NLB IP 目标注册 lambda 组的 ARN。
- 18
- 指定 DNS 和负载均衡的 CloudFormation 模板输出的
RegisterNlbIpTargetsLambda
值。 - 19
- 外部 API 负载均衡器目标组的 ARN。
- 20
- 指定 DNS 和负载均衡的 CloudFormation 模板输出的
ExternalApiTargetGroupArn
值。 - 21
- 内部 API 负载均衡器目标组群的 ARN。
- 22
- 指定 DNS 和负载均衡的 CloudFormation 模板输出的
InternalApiTargetGroupArn
值。 - 23
- 内部服务负载均衡器目标组群的 ARN。
- 24
- 指定 DNS 和负载均衡的 CloudFormation 模板输出的
InternalServiceTargetGroupArn
值。
- 复制本主题的 Bootstrap 机器的 CloudFormation 模板部分中的模板,并将它以 YAML 文件形式保存到计算机上。此模板描述了集群所需的 bootstrap 机器。
启动模板:
重要您必须在一行内输入命令。
$ aws cloudformation create-stack --stack-name <name> 1 --template-body file://<template>.yaml 2 --parameters file://<parameters>.json 3 --capabilities CAPABILITY_NAMED_IAM
确认模板组件已存在:
$ aws cloudformation describe-stacks --stack-name <name>
在
StackStatus
显示CREATE_COMPLETE
后,输出会显示以下参数的值。您必须将这些参数值提供给您在创建集群时要运行的其他 CloudFormation 模板:BootstrapInstanceId
bootstrap 实例 ID。
BootstrapPublicIp
bootstrap 节点公共 IP 地址。
BootstrapPrivateIp
bootstrap 节点专用 IP 地址。
1.7.12.1. bootstrap 机器的 CloudFormation 模板
您可以使用以下 CloudFormation 模板来部署 OpenShift Container Platform 集群所需的 bootstrap 机器。
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 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: "i3.large" NetworkInterfaces: - AssociatePublicIpAddress: "true" DeviceIndex: "0" GroupSet: - !Ref "BootstrapSecurityGroup" - !Ref "MasterSecurityGroupId" SubnetId: !Ref "PublicSubnet" UserData: Fn::Base64: !Sub - '{"ignition":{"config":{"replace":{"source":"${S3Loc}","verification":{}}},"timeouts":{},"version":"2.1.0"},"networkd":{},"passwd":{},"storage":{},"systemd":{}}' - { 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
1.7.13. 在 AWS 中创建 control plane 机器
您必须在 Amazon Web Services (AWS) 中创建 control plane 机器,供您的集群使用。创建这些节点的最简单方法是修改提供的 CloudFormation 模板。
如果不使用提供的 CloudFormation 模板来创建 control plane 节点,您必须检查提供的信息并手动创建基础架构。如果集群没有正确初始化,您可能需要联系红帽支持并提供您的安装日志。
先决条件
- 配置 AWS 帐户。
- 为集群生成 Ignition 配置文件。
- 在 AWS 中创建和配置 VPC 及相关子网。
- 在 AWS 中创建并配置 DNS、负载均衡器和监听程序。
- 创建 control plane 和计算角色。
- 创建 bootstrap 机器。
流程
创建一个 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": "m4.xlarge" 26 }, { "ParameterKey": "AutoRegisterELB", 27 "ParameterValue": "yes" 28 }, { "ParameterKey": "RegisterNlbIpTargetsLambdaArn", 29 "ParameterValue": "arn:aws:lambda:<region>:<account_number>:function:<dns_stack_name>-RegisterNlbIpTargets-<random_string>" 30 }, { "ParameterKey": "ExternalApiTargetGroupArn", 31 "ParameterValue": "arn:aws:elasticloadbalancing:<region>:<account_number>:targetgroup/<dns_stack_name>-Exter-<random_string>" 32 }, { "ParameterKey": "InternalApiTargetGroupArn", 33 "ParameterValue": "arn:aws:elasticloadbalancing:<region>:<account_number>:targetgroup/<dns_stack_name>-Inter-<random_string>" 34 }, { "ParameterKey": "InternalServiceTargetGroupArn", 35 "ParameterValue": "arn:aws:elasticloadbalancing:<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
- 指定
yes
或no
。如果指定yes
,您必须提供托管区信息。 - 7
- 用来注册 etcd 目标的 Route53 专用区 ID。
- 8
- 指定 DNS 和负载均衡的 CloudFormation 模板输出的
PrivateHostedZoneId
值。 - 9
- 用来注册目标的 Route53 区。
- 10
- 指定
<cluster_name>.<domain_name>
,其中<domain_name>
是您为集群生成install-config.yaml
文件时所用的 Route53 基域。请勿包含 AWS 控制台中显示的结尾句点 (.)。 - 11 13 15
- 在其中启动 control plane 机器的子网,最好是专用子网。
- 12 14 16
- 从 DNS 和负载均衡的 CloudFormation 模板输出的
PrivateSubnets
值指定子网。 - 17
- 与 master 节点关联的 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
- 与 master 节点关联的 IAM 配置集。
- 24
- 指定安全组和角色的 CloudFormation 模板输出的
MasterInstanceProfile
参数值。 - 25
- 用于 control plane 机器的 AWS 实例类型。
- 26
- 允许的值:
-
m4.xlarge
-
m4.2xlarge
-
m4.4xlarge
-
m4.8xlarge
-
m4.10xlarge
-
m4.16xlarge
-
c4.2xlarge
-
c4.4xlarge
-
c4.8xlarge
-
r4.xlarge
-
r4.2xlarge
-
r4.4xlarge
-
r4.8xlarge
r4.16xlarge
重要如果您的区域中没有
m4
实例类型,例如eu-west-3
,请改为指定m5
类型,如m5.xlarge
。
-
- 27
- 是否要注册网络负载均衡器 (NLB) 。
- 28
- 指定
yes
或no
。如果指定yes
,您必须提供一个 Lambda Amazon Resource Name (ARN) 值。 - 29
- NLB IP 目标注册 lambda 组的 ARN。
- 30
- 指定 DNS 和负载均衡的 CloudFormation 模板输出的
RegisterNlbIpTargetsLambda
值。 - 31
- 外部 API 负载均衡器目标组的 ARN。
- 32
- 指定 DNS 和负载均衡的 CloudFormation 模板输出的
ExternalApiTargetGroupArn
值。 - 33
- 内部 API 负载均衡器目标组群的 ARN。
- 34
- 指定 DNS 和负载均衡的 CloudFormation 模板输出的
InternalApiTargetGroupArn
值。 - 35
- 内部服务负载均衡器目标组群的 ARN。
- 36
- 指定 DNS 和负载均衡的 CloudFormation 模板输出的
InternalServiceTargetGroupArn
值。
- 复制control plane 机器的 CloudFormation 模板一节中的模板,并将它以 YAML 文件形式保存到计算机上。此模板描述了集群所需的 control plane 机器。
-
如果您将
m5
实例类型指定为MasterInstanceType
的值,请将该实例类型添加到 CloudFormation 模板中的MasterInstanceType.AllowedValues
参数。 启动模板:
重要您必须在一行内输入命令。
$ aws cloudformation create-stack --stack-name <name> 1 --template-body file://<template>.yaml 2 --parameters file://<parameters>.json 3
确认模板组件已存在:
$ aws cloudformation describe-stacks --stack-name <name>
1.7.13.1. control plane 机器的 CloudFormation 模板
您可以使用以下 CloudFormation 模板来部署 OpenShift Container Platform 集群所需的 control plane 机器。
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: "yes" AllowedValues: - "yes" - "no" Description: Do you want to invoke DNS etcd registration, which requires Hosted Zone information? Type: String PrivateHostedZoneId: Description: The Route53 private zone ID to register the etcd targets with, such as Z21IXYZABCZ2A4. Type: String PrivateHostedZoneName: Description: The Route53 zone to register the targets with, such as cluster.example.com. Omit the trailing period. 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: m4.xlarge Type: String AllowedValues: - "m4.xlarge" - "m4.2xlarge" - "m4.4xlarge" - "m4.8xlarge" - "m4.10xlarge" - "m4.16xlarge" - "c4.2xlarge" - "c4.4xlarge" - "c4.8xlarge" - "r4.xlarge" - "r4.2xlarge" - "r4.4xlarge" - "r4.8xlarge" - "r4.16xlarge" 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: "DNS" Parameters: - AutoRegisterDNS - PrivateHostedZoneName - PrivateHostedZoneId - 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" AutoRegisterDNS: default: "Use Provided DNS Automation" AutoRegisterELB: default: "Use Provided ELB Automation" PrivateHostedZoneName: default: "Private Hosted Zone Name" PrivateHostedZoneId: default: "Private Hosted Zone ID" Conditions: DoRegistration: !Equals ["yes", !Ref AutoRegisterELB] DoDns: !Equals ["yes", !Ref AutoRegisterDNS] 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":{"append":[{"source":"${SOURCE}","verification":{}}]},"security":{"tls":{"certificateAuthorities":[{"source":"${CA_BUNDLE}","verification":{}}]}},"timeouts":{},"version":"2.2.0"},"networkd":{},"passwd":{},"storage":{},"systemd":{}}' - { 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":{"append":[{"source":"${SOURCE}","verification":{}}]},"security":{"tls":{"certificateAuthorities":[{"source":"${CA_BUNDLE}","verification":{}}]}},"timeouts":{},"version":"2.2.0"},"networkd":{},"passwd":{},"storage":{},"systemd":{}}' - { 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":{"append":[{"source":"${SOURCE}","verification":{}}]},"security":{"tls":{"certificateAuthorities":[{"source":"${CA_BUNDLE}","verification":{}}]}},"timeouts":{},"version":"2.2.0"},"networkd":{},"passwd":{},"storage":{},"systemd":{}}' - { 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 EtcdSrvRecords: Condition: DoDns Type: AWS::Route53::RecordSet Properties: HostedZoneId: !Ref PrivateHostedZoneId Name: !Join [".", ["_etcd-server-ssl._tcp", !Ref PrivateHostedZoneName]] ResourceRecords: - !Join [ " ", ["0 10 2380", !Join [".", ["etcd-0", !Ref PrivateHostedZoneName]]], ] - !Join [ " ", ["0 10 2380", !Join [".", ["etcd-1", !Ref PrivateHostedZoneName]]], ] - !Join [ " ", ["0 10 2380", !Join [".", ["etcd-2", !Ref PrivateHostedZoneName]]], ] TTL: 60 Type: SRV Etcd0Record: Condition: DoDns Type: AWS::Route53::RecordSet Properties: HostedZoneId: !Ref PrivateHostedZoneId Name: !Join [".", ["etcd-0", !Ref PrivateHostedZoneName]] ResourceRecords: - !GetAtt Master0.PrivateIp TTL: 60 Type: A Etcd1Record: Condition: DoDns Type: AWS::Route53::RecordSet Properties: HostedZoneId: !Ref PrivateHostedZoneId Name: !Join [".", ["etcd-1", !Ref PrivateHostedZoneName]] ResourceRecords: - !GetAtt Master1.PrivateIp TTL: 60 Type: A Etcd2Record: Condition: DoDns Type: AWS::Route53::RecordSet Properties: HostedZoneId: !Ref PrivateHostedZoneId Name: !Join [".", ["etcd-2", !Ref PrivateHostedZoneName]] ResourceRecords: - !GetAtt Master2.PrivateIp TTL: 60 Type: A Outputs: PrivateIPs: Description: The control-plane node private IP addresses. Value: !Join [ ",", [!GetAtt Master0.PrivateIp, !GetAtt Master1.PrivateIp, !GetAtt Master2.PrivateIp] ]
1.7.14. 使用用户置备的基础架构在 AWS 上初始化 bootstrap 节点
在 Amazon Web Services (AWS) 中创建所有所需的基础架构后,就可以安装集群。
先决条件
- 配置 AWS 帐户。
- 为集群生成 Ignition 配置文件。
- 在 AWS 中创建和配置 VPC 及相关子网。
- 在 AWS 中创建并配置 DNS、负载均衡器和监听程序。
- 创建 control plane 和计算角色。
- 创建 bootstrap 机器。
- 创建 control plane 机器。
- 如果您计划手动管理 worker 机器,请创建 worker 机器。
流程
更改到包含安装程序的目录,再运行以下命令:
$ ./openshift-install wait-for bootstrap-complete --dir=<installation_directory> \ 1 --log-level=info 2
如果命令退出且不显示
FATAL
警告,则代表您的 control plane 已被初始化。
1.7.14.1. 在 AWS 中创建 worker 节点
您可以在 Amazon Web Services (AWS) 中创建 worker 节点,供集群使用。手动创建这些节点的最简单方法是修改提供的 CloudFormation 模板。
CloudFormation 模板会创建一个堆栈,其代表一台 worker 机器。您必须为每台 worker 机器创建一个堆栈。
如果不使用提供的 CloudFormation 模板来创建 worker 节点,您必须检查提供的信息并手动创建基础架构。如果集群没有正确初始化,您可能需要联系红帽支持并提供您的安装日志。
先决条件
- 配置 AWS 帐户。
- 为集群生成 Ignition 配置文件。
- 在 AWS 中创建和配置 VPC 及相关子网。
- 在 AWS 中创建并配置 DNS、负载均衡器和监听程序。
- 创建 control plane 和计算角色。
- 创建 bootstrap 机器。
- 创建 control plane 机器。
流程
创建一个 JSON 文件,其包含 CloudFormation 模板需要的参数值:
[ { "ParameterKey": "InfrastructureName", 1 "ParameterValue": "mycluster-<random_string>" 2 }, { "ParameterKey": "RhcosAmi", 3 "ParameterValue": "ami-<random_string>" 4 }, { "ParameterKey": "Subnet", 5 "ParameterValue": "subnet-<random_string>" 6 }, { "ParameterKey": "WorkerSecurityGroupId", 7 "ParameterValue": "sg-<random_string>" 8 }, { "ParameterKey": "IgnitionLocation", 9 "ParameterValue": "https://api-int.<cluster_name>.<domain_name>:22623/config/worker" 10 }, { "ParameterKey": "CertificateAuthorities", 11 "ParameterValue": "" 12 }, { "ParameterKey": "WorkerInstanceProfileName", 13 "ParameterValue": "" 14 }, { "ParameterKey": "WorkerInstanceType", 15 "ParameterValue": "m4.large" 16 } ]
- 1
- 您的 Ignition 配置文件中为集群编码的集群基础架构名称。
- 2
- 指定从 Ignition 配置文件元数据中提取的基础架构名称,其格式为
<cluster-name>-<random-string>
。 - 3
- 用于 worker 节点的当前 Red Hat Enterprise Linux CoreOS (RHCOS) AMI。
- 4
- 指定
AWS::EC2::Image::Id
值。 - 5
- 在其中启动 worker 节点的子网,最好是专用子网。
- 6
- 从 DNS 和负载均衡的 CloudFormation 模板输出的
PrivateSubnets
值指定子网。 - 7
- 与 worker 节点关联的 worker 安全组 ID。
- 8
- 指定安全组和角色的 CloudFormation 模板输出的
WorkerSecurityGroupId
值。 - 9
- 从中获取 bootstrap Ignition 配置文件的位置。
- 10
- 指定生成的 Ignition 配置的位置,
https://api-int.<cluster_name>.<domain_name>:22623/config/worker
。 - 11
- 要使用的 Base64 编码证书颁发机构字符串。
- 12
- 指定安装目录下
worker.ign
文件中的值。这个值是一个长字符串,格式为data:text/plain;charset=utf-8;base64,ABC…xYz==
。 - 13
- 与 worker 节点关联的 IAM 配置集。
- 14
- 指定安全组和角色的 CloudFormation 模板输出的
WorkerInstanceProfile
参数值。 - 15
- 用于 control plane 机器的 AWS 实例类型。
- 16
- 允许的值:
-
m4.large
-
m4.xlarge
-
m4.2xlarge
-
m4.4xlarge
-
m4.8xlarge
-
m4.10xlarge
-
m4.16xlarge
-
c4.large
-
c4.xlarge
-
c4.2xlarge
-
c4.4xlarge
-
c4.8xlarge
-
r4.large
-
r4.xlarge
-
r4.2xlarge
-
r4.4xlarge
-
r4.8xlarge
r4.16xlarge
重要如果您的区域中没有
m4
实例类型,例如eu-west-3
,请改为使用m5
类型。
-
- 复制 worker 机器的 CloudFormation 模板一节中的模板,并将它以 YAML 文件形式保存到计算机上。此模板描述了集群所需的网络对象和负载均衡器。
-
如果您将
m5
实例类型指定为WorkerInstanceType
的值,请将该实例类型添加到 CloudFormation 模板中的WorkerInstanceType.AllowedValues
参数。 创建 worker 堆栈。
启动模板:
重要您必须在一行内输入命令。
$ aws cloudformation create-stack --stack-name <name> 1 --template-body file://<template>.yaml \ 2 --parameters file://<parameters>.json 3
确认模板组件已存在:
$ aws cloudformation describe-stacks --stack-name <name>
继续创建 worker 堆栈,直到为集群创建了充足的 worker 机器。
重要您必须至少创建两台 worker 机器,因此您必须创建至少两个使用此 CloudFormation 模板的堆栈。
1.7.14.1.1. worker 机器的 CloudFormation 模板
您可以使用以下 CloudFormation 模板来部署 OpenShift Container Platform 集群所需的 worker 机器。
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: m4.large Type: String AllowedValues: - "m4.large" - "m4.xlarge" - "m4.2xlarge" - "m4.4xlarge" - "m4.8xlarge" - "m4.10xlarge" - "m4.16xlarge" - "c4.large" - "c4.xlarge" - "c4.2xlarge" - "c4.4xlarge" - "c4.8xlarge" - "r4.large" - "r4.xlarge" - "r4.2xlarge" - "r4.4xlarge" - "r4.8xlarge" - "r4.16xlarge" 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":{"append":[{"source":"${SOURCE}","verification":{}}]},"security":{"tls":{"certificateAuthorities":[{"source":"${CA_BUNDLE}","verification":{}}]}},"timeouts":{},"version":"2.2.0"},"networkd":{},"passwd":{},"storage":{},"systemd":{}}' - { 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
1.7.15. 通过下载二进制文件安装 CLI
您需要安装 CLI(oc
) 来使用命令行界面与 OpenShift Container Platform 进行交互。您可在 Linux 、Windows 或 macOS 上安装 oc
。
如果安装了旧版本的 oc
,则无法使用 OpenShift Container Platform 4.3 中的所有命令。下载并安装新版本的 oc
。
1.7.15.1. 在 Linux 上安装 CLI
您可以按照以下流程在 Linux 上安装 OpenShift CLI(oc
)二进制文件。
流程
- 访问 Red Hat OpenShift Cluster Manager 网站的 Infrastructure Provider 页面。
- 选择您的基础架构供应商及安装类型。
- 在 Command-line interface 部分,从下拉菜单中选择 Linux,并点 Download command-line tools。
解包存档:
$ tar xvzf <file>
把
oc
二进制代码放到PATH
中的目录中。执行以下命令可以查看当前的
PATH
设置:$ echo $PATH
安装 CLI 后,就可以使用oc
命令:
$ oc <command>
1.7.15.2. 在 Windows 上安装 CLI
您可以按照以下流程在 Windows 上安装 OpenShift CLI(oc
)二进制代码。
流程
- 访问 Red Hat OpenShift Cluster Manager 网站的 Infrastructure Provider 页面。
- 选择您的基础架构供应商及安装类型。
- 在 Command-line interface 部分,从下拉菜单中选择 Windows,点 Download command-line tools。
- 使用 ZIP 程序解压存档。
把
oc
二进制代码放到PATH
中的目录中。要查看您的
PATH
,请打开命令提示窗口并执行以下命令:C:\> path
安装 CLI 后,就可以使用oc
命令:
C:\> oc <command>
1.7.15.3. 在 macOS 上安装 CLI
您可以按照以下流程在 macOS 上安装 OpenShift CLI(oc
)二进制代码。
流程
- 访问 Red Hat OpenShift Cluster Manager 网站的 Infrastructure Provider 页面。
- 选择您的基础架构供应商及安装类型。
- 在 Command-line interface 部分,从下拉菜单中选择 MacOS,并点 Download command-line tools。
- 解包和解压存档。
将
oc
二进制文件移到 PATH 的目录中。要查看您的
PATH
,打开一个终端窗口并执行以下命令:$ echo $PATH
安装 CLI 后,就可以使用oc
命令:
$ oc <command>
1.7.16. 登录集群
您可以通过导出集群 kubeconfig
文件,以默认系统用户身份登录集群。kubeconfig
文件包含关于集群的信息,供 CLI 用于将客户端连接到正确集群和 API 服务器。该文件特只适用于一个特定的集群,在 OpenShift Container Platform 安装过程中创建。
先决条件
- 部署 OpenShift Container Platform 集群。
-
安装
oc
CLI。
流程
导出
kubeadmin
凭证:$ export KUBECONFIG=<installation_directory>/auth/kubeconfig 1
- 1
- 对于
<installation_directory>
,请指定安装文件保存到的目录的路径。
使用导出的配置,验证能否成功运行
oc
命令:$ oc whoami system:admin
1.7.17. 批准机器的 CSR
将机器添加到集群时,会为您添加的每台机器生成两个待处理证书签名请求(CSR)。您必须确认这些 CSR 已获得批准,或根据需要自行批准。
先决条件
- 您已将机器添加到集群中。
流程
确认集群可以识别这些机器:
$ oc get nodes NAME STATUS ROLES AGE VERSION master-0 Ready master 63m v1.16.2 master-1 Ready master 63m v1.16.2 master-2 Ready master 64m v1.16.2 worker-0 NotReady worker 76s v1.16.2 worker-1 NotReady worker 70s v1.16.2
输出将列出您创建的所有机器。
检查待处理的 CSR,并确保添加到集群中的每台机器都有
Pending
或Approved
状态的客户端和服务器请求:$ oc get csr NAME AGE REQUESTOR CONDITION csr-8b2br 15m system:serviceaccount:openshift-machine-config-operator:node-bootstrapper Pending 1 csr-8vnps 15m system:serviceaccount:openshift-machine-config-operator:node-bootstrapper Pending csr-bfd72 5m26s system:node:ip-10-0-50-126.us-east-2.compute.internal Pending 2 csr-c57lv 5m26s system:node:ip-10-0-95-157.us-east-2.compute.internal Pending ...
在本例中,两台机器加入了集群。您可能会在列表中看到更多已批准的 CSR。
如果 CSR 没有获得批准,请在所添加机器的所有待处理 CSR 都处于
Pending
状态后,为您的集群机器批准这些 CSR:注意由于 CSR 会自动轮转,因此请在将机器添加到集群后一小时内批准您的 CSR。如果没有在一小时内批准,证书将会轮转,每个节点将会存在多个证书。您必须批准所有这些证书。批准初始 CSR 后,集群的
kube-controller-manager
会自动批准后续的节点客户端 CSR。您必须实施一个方法来自动批准 kubelet 提供的证书请求。若要单独批准,请对每个有效的 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
其他信息
- 如需有关 CSR 的更多信息,请参阅证书签名请求。
1.7.18. 初始 Operator 配置
在 control plane 初始化后,您必须立即配置一些 Operator 以便它们都可用。
先决条件
- 您的 control plane 已初始化。
流程
观察集群组件上线:
$ watch -n5 oc get clusteroperators NAME VERSION AVAILABLE PROGRESSING DEGRADED SINCE authentication 4.3.0 True False False 69s cloud-credential 4.3.0 True False False 12m cluster-autoscaler 4.3.0 True False False 11m console 4.3.0 True False False 46s dns 4.3.0 True False False 11m image-registry 4.3.0 True False False 5m26s ingress 4.3.0 True False False 5m36s kube-apiserver 4.3.0 True False False 8m53s kube-controller-manager 4.3.0 True False False 7m24s kube-scheduler 4.3.0 True False False 12m machine-api 4.3.0 True False False 12m machine-config 4.3.0 True False False 7m36s marketplace 4.3.0 True False False 7m54m monitoring 4.3.0 True False False 7h54s network 4.3.0 True False False 5m9s node-tuning 4.3.0 True False False 11m openshift-apiserver 4.3.0 True False False 11m openshift-controller-manager 4.3.0 True False False 5m943s openshift-samples 4.3.0 True False False 3m55s operator-lifecycle-manager 4.3.0 True False False 11m operator-lifecycle-manager-catalog 4.3.0 True False False 11m service-ca 4.3.0 True False False 11m service-catalog-apiserver 4.3.0 True False False 5m26s service-catalog-controller-manager 4.3.0 True False False 5m25s storage 4.3.0 True False False 5m30s
- 配置不可用的 Operator。
1.7.18.1. 镜像 registry 存储配置
Amazon Web Services 提供默认存储,这意味着 image-registry
Operator 在安装后即可用。但是,如果 Registry Operator 无法创建 S3 存储桶并自动配置存储,您需要手工配置 registry 存储。
提供了配置 PersistentVolume 的说明,这是生产集群所需要的;也提供了将空目录配置为存储位置的说明,这仅适用于非生产集群。
1.7.18.1.1. 为使用用户置备的基础架构的 AWS 配置 registry 存储
在安装过程中,使用您的云凭据就可以创建一个S3 存储桶,Registry Operator 将会自动配置存储。
如果 Registry Operator 无法创建 S3 存储桶或自动配置存储,您可以按照以下流程创建 S3 存储桶并配置存储。
先决条件
- 使用用户置备的 AWS 中有一个集群。
对于 AWS 上的 S3 存储,secret 应该包含以下两个键:
-
REGISTRY_STORAGE_S3_ACCESSKEY
-
REGISTRY_STORAGE_S3_SECRETKEY
-
流程
如果 Registry Operator 无法创建 S3 存储桶并自动配置存储,请进行以下操作。
- 设置一个 Bucket Lifecycle Policy用来终止已有一天之久的未完成的分段上传操作。
在
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 存储桶的公共访问。
1.7.18.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
等待几分钟,然后再次运行该命令。
1.7.19. 删除 bootstrap 资源:
完成集群的初始 Operator 配置后,从 Amazon Web Services (AWS) 中删除 bootstrap 资源。
先决条件
- 已为集群完成初始的 Operator 配置。
1.7.20. 创建 Ingress DNS 记录
如果您删除了 DNS 区配置,请手动创建指向 Ingress 负载均衡器的 DNS 记录。您可以创建一个 wildcard 记录或具体的记录。以下流程使用了 A 记录,但您可以使用其他所需记录类型,如 CNAME 或别名。
先决条件
- 已在 Amazon Web Services (AWS) 上安装了使用您置备的基础架构的 OpenShift Container Platform 集群。
-
安装 OpenShift CLI(
oc
)。 -
安装
jq
软件包。 - 下载 AWS CLI 并安装到您的计算机上。请参阅使用捆绑安装程序(Linux、macOS 或 Unix)安装 AWS CLI的文档。
流程
决定要创建的路由。
-
要创建一个 wildcard 记录,请使用
*.apps.<cluster_name>.<domain_name>
,其中<cluster_name>
是集群名称,<domain_name>
是 OpenShift Container Platform 集群的 Route53 基域。 要创建特定的记录,您必须为集群使用的每个路由创建一个记录,如下所示:
$ 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> grafana-openshift-monitoring.apps.<cluster_name>.<domain_name> prometheus-k8s-openshift-monitoring.apps.<cluster_name>.<domain_name>
-
要创建一个 wildcard 记录,请使用
获取 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
为负载均衡器定位托管区 ID:
$ aws elb describe-load-balancers | jq -r '.LoadBalancerDescriptions[] | select(.DNSName == "<external_ip>").CanonicalHostedZoneNameID' 1 Z3AADJGX6KTTL2
- 1
- 对于
<external_ip>
,请指定您获取的 Ingress Operator 负载均衡器的外部 IP 地址值。
这个命令的输出是负载均衡器托管区 ID。
获取集群域的公共托管区 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 /hostedzone/Z3URY6TWQ91KVV
命令输出中会显示您的域的公共托管区 ID。在本例中是
Z3URY6TWQ91KVV
。在您的私有区中添加别名记录:
$ 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 > } > } > } > ] > }'
在您的公共区中添加记录:
$ 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.7.21. 在用户置备的基础架构上完成 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 INFO Waiting up to 30m0s for the cluster to initialize...
- 1
- 对于
<installation_directory>
,请指定安装文件保存到的目录的路径。
重要安装程序生成的 Ignition 配置文件中所含的证书会在 24 小时后过期。您必须以非降级状态持续运行集群 24 小时,以确保完成第一次证书轮转。
1.7.22. 后续步骤
- 自定义集群。
- 若有需要,您可以选择不使用远程健康报告。
1.8. 使用镜像安装内容在 AWS 上安装集群
在 OpenShift Container Platform 版本 4.3 中,您可以使用您提供的基础架构和安装发行内容的内部镜像在 Amazon Web Services (AWS) 上安装集群。
虽然您可以使用镜像安装发行内容安装 OpenShift Container Platform 集群,但您的集群仍需要访问互联网才能使用 AWS API。
创建此基础架构的一种方法是使用提供的 CloudFormation 模板。您可以修改模板来自定义基础架构,或使用其包含的信息来按照公司策略创建 AWS 对象。
1.8.1. 先决条件
在堡垒主机上创建镜像 registry,并获取您的 OpenShift Container Platform 版本的
imageContentSources
数据。重要由于安装介质位于堡垒主机上,因此请使用该计算机完成所有安装步骤。
- 查看有关 OpenShift Container Platform 安装和更新流程的详细信息。
配置 AWS 帐户以托管集群。
重要如果您的计算机上存储有 AWS 配置集,则不要在使用多因素验证设备的同时使用您生成的临时会话令牌。在集群的整个生命周期中,集群会持续使用您的当前 AWS 凭证来创建 AWS 资源,因此您必须使用基于密钥的长期凭证。要生成适当的密钥,请参阅 AWS 文档中的管理 IAM 用户的访问密钥。您可在运行安装程序时提供密钥。
- 下载 AWS CLI 并安装到您的计算机上。请参阅 AWS 文档中的使用捆绑安装程序(Linux、macOS 或 Unix)安装 AWS CLI。
如果使用防火墙并计划使用遥测(telemetry),您必须将其配置为允许集群需要访问的站点。
注意如果您要配置代理,请务必也要查看此站点列表。
- 如果不允许系统管理身份和访问管理(IAM),集群管理员可以手动创建和维护 IAM 凭证。手动模式也可以用于云 IAM API 无法访问的环境中。
1.8.2. 关于在受限网络中安装
在 OpenShift Container Platform 4.3 中,可以执行不需要有效的互联网连接来获取软件组件的安装。受限网络安装只能在您置备的基础架构上完成,不能在安装程序置备的基础架构上完成,因此您的平台选择会受到限制。
如果选择在云平台中执行受限网络安装,仍然需要访问其云 API。有些云功能,比如 Amazon Web Service 的 IAM 服务,需要访问互联网,因此您可能仍需要连入互联网。根据您的网络,在裸机硬件或 VMware vSphere 上安装时可能需要较少的互联网访问。
要完成受限网络安装,您必须创建一个 registry,镜像 OpenShift Container Platform registry 的内容并包含其安装介质。您可以在堡垒主机上创建此镜像,该主机可同时访问互联网和您的封闭网络,也可以使用满足您的限制条件的其他方法。
受限网络安装始终使用用户置备的基础架构。由于用户置备安装配置的复杂性,在尝试受限网络安装前,请考虑完成标准用户置备基础架构安装。通过完成此测试安装,您可以更轻松地隔离和排查您在受限网络中安装时可能出现的问题。
1.8.2.1. 其他限制
受限网络中的集群还有以下额外限制:
-
ClusterVersion 状态包含
Unable to retrieve available updates
错误。 - 默认情况下,您无法使用 Developer Catalog 的内容,因为您无法访问所需的 ImageStreamTag。
1.8.3. OpenShift Container Platform 对互联网和 Telemetry 的访问
在 OpenShift Container Platform 4.3 中,您需要访问互联网来安装集群。默认运行的 Telemetry 服务提供有关集群健康状况和成功更新的指标,这也需要访问互联网。如果您的集群连接到互联网,Telemetry 会自动运行,而且集群会注册到 Red Hat OpenShift Cluster Manager(OCM)。
确认 Red Hat OpenShift Cluster Manager 清单正确后,可以由 Telemetry 自动维护,也可以使用 OCM 手动维护,使用订阅监控 来跟踪帐户或多集群级别的 OpenShift Container Platform 订阅。
您必须具有以下互联网访问权限:
- 访问 Red Hat OpenShift Cluster Manager 页面,以下载安装程序并执行订阅管理。如果集群可以访问互联网,并且没有禁用 Telemetry,该服务会自动授权您的集群。
- 访问 Quay.io,以获取安装集群所需的软件包。
- 获取执行集群更新所需的软件包。
如果您的集群无法直接访问互联网,则可以在置备的某些类基础架构上执行受限网络安装。在此过程中,您要下载所需的内容,并使用它在镜像 registry(mirror registry) 中填充安装集群并生成安装程序所需的软件包。对于某些安装类型,集群要安装到的环境不需要访问互联网。在更新集群之前,要更新 registry 镜像系统中的内容。
1.8.4. 所需的 AWS 基础架构组件
要在 Amazon Web Services (AWS) 中用户置备的基础架构上安装 OpenShift Container Platform,您必须手动创建机器及其支持的基础架构。
如需有关不同平台集成测试的更多信息,请参阅 OpenShift Container Platform 4.x Tested Integrations页面。
您可以使用提供的 CloudFormation 模板创建此基础架构,也可以手动创建组件,或者重复使用满足集群要求的现有基础架构。查看 CloudFormation 模板,了解组件如何相互连接的更多详情。
1.8.4.1. 集群机器
以下机器需要 AWS::EC2::Instance
对象:
- bootstrap 机器。安装过程中需要此机器,但可在集群部署后删除。
- 至少三台 control plane 机器。control plane 机器不受 MachineSet 的管控。
- 计算机器。在安装过程中创建至少两台计算(compute)机器(也称为 worker 机器)。这些机器不受 MachineSet 的管控。
您可以通过提供的 CloudFormation 模板,为集群机器使用以下实例类型。
如果您的区域中没有 m4
实例类型,例如 eu-west-3
,请改为使用 m5
类型。
实例类型 | bootstrap | Control plane | Compute |
---|---|---|---|
| x | ||
| x | ||
| x | x | |
| x | x | |
| x | x | |
| x | x | |
| x | x | |
| x | x | |
| x | ||
| x | ||
| x | x | |
| x | x | |
| x | x | |
| x | ||
| x | x | |
| x | x | |
| x | x | |
| x | x | |
| x | x |
您可能能够使用符合这些实例类型规格的其他实例类型。
1.8.4.2. 证书签名请求管理
在使用您置备的基础架构时,集群只能有限地访问自动机器管理,因此您必须提供一种在安装后批准集群证书签名请求 (CSR) 的机制。kube-controller-manager
只能批准 kubelet 客户端 CSR。machine-approver
无法保证使用 kubelet 凭证请求的提供证书的有效性,因为它不能确认是正确的机器发出了该请求。您必须决定并实施一种方法,以验证 kubelet 提供证书请求的有效性并进行批准。
1.8.4.3. 其他基础架构组件
- VPC
- DNS 条目
- 负载均衡器(典型或网络)和监听器
- 公共和专用 Route53 区
- 安全组
- IAM 角色
- S3 存储桶
如果您在断开连接的环境中工作,您将无法访问 EC2 和 ELB 端点的公共 IP 地址。要解决这个问题,您必须创建一个 VPC 端点,并将其附加到集群使用的子网。端点应命名如下:
-
ec2.<region>.amazonaws.com
-
elasticloadbalancing.<region>.amazonaws.com
-
s3.<region>.amazonaws.com
所需的 VPC 组件
您必须提供合适的 VPC 和子网,以便与您的机器通信。
组件 | AWS 类型 | 描述 | |
---|---|---|---|
VPC |
| 您必须提供一个公共 VPC 供集群使用。VPC 使用引用每个子网的路由表的端点,以改进与托管在 S3 中的 registry 的通信。 | |
公共子网 |
| 您的 VPC 必须有 1 到 3 个可用区的公共子网,并将其与适当的入口规则关联。 | |
互联网网关 |
| 您必须有一个公共互联网网关,以及附加到 VPC 的公共路由。在提供的模板中,每个公共子网都有一个具有 EIP 地址的 NAT 网关。这些 NAT 网关允许集群资源(如专用子网实例)访问互联网,而有些受限网络或代理场景则不需要它们。 | |
网络访问控制 |
| 您必须允许 VPC 访问下列端口: | |
端口 | 原因 | ||
| 入站 HTTP 流量 | ||
| 入站 HTTPS 流量 | ||
| 入站 SSH 流量 | ||
| 入站临时流量 | ||
| 出站临时流量 | ||
专用子网 |
| 您的 VPC 可以具有私有子网。提供的 CloudFormation 模板可为 1 到 3 个可用区创建专用子网。如果您使用专用子网,必须为其提供适当的路由和表。 |
所需的 DNS 和负载均衡组件
您的 DNS 和负载均衡器配置需要使用公共托管区,并可使用类似安装程序使用的专用托管区(如果安装程序置备了集群的基础架构)。您必须创建一个解析到负载均衡器的 DNS 条目。api.<cluster_name>.<domain>
的条目必须指向外部负载均衡器,api-int.<cluster_name>.<domain>
的条目则必须指向内部负载均衡器。
集群还需要负载均衡器,以及监听端口 6443(用于 Kubernetes API 及其扩展)和端口 22623(用于新机器的 Ignition 配置文件)的监听程序。目标是 master 节点。集群外的客户端和集群内的节点都必须能够访问端口 6443。集群内的节点必须能够访问端口 22623。
组件 | AWS 类型 | 描述 |
---|---|---|
DNS |
| 内部 DNS 的托管区。 |
etcd 记录集 |
| control plane 机器的 etcd 注册记录。 |
公共负载均衡器 |
| 公共子网的负载均衡器。 |
外部 API 服务器记录 |
| 外部 API 服务器的别名记录。 |
外部监听程序 |
| 为外部负载均衡器监听端口 6443 的监听程序。 |
外部目标组 |
| 外部负载均衡器的目标组。 |
专用负载均衡器 |
| 专用子网的负载均衡器。 |
内部 API 服务器记录 |
| 内部 API 服务器的别名记录。 |
内部监听程序 |
| 为内部负载均衡器监听端口 22623 的监听程序。 |
内部目标组 |
| 内部负载均衡器的目标组。 |
内部监听程序 |
| 为内部负载均衡器监听端口 6443 的监听程序。 |
内部目标组 |
| 内部负载均衡器的目标组。 |
安全组
control plane 和 worker 机器需要访问下列端口:
组 | 类型 | IP 协议 | 端口范围 |
---|---|---|---|
MasterSecurityGroup |
|
|
|
|
| ||
|
| ||
|
| ||
WorkerSecurityGroup |
|
|
|
|
| ||
BootstrapSecurityGroup |
|
|
|
|
|
control plane 入口
control plane 机器需要以下入口组。每个入口组都是 AWS::EC2::SecurityGroupIngress
资源。
入口组 | 描述 | IP 协议 | 端口范围 |
---|---|---|---|
| etcd |
|
|
| Vxlan 数据包 |
|
|
| Vxlan 数据包 |
|
|
| 内部集群通信和 Kubernetes 代理指标 |
|
|
| 内部集群通信 |
|
|
| kubernetes kubelet、调度程序和控制器管理器 |
|
|
| kubernetes kubelet、调度程序和控制器管理器 |
|
|
| Kubernetes 入口服务 |
|
|
| Kubernetes 入口服务 |
|
|
worker 入口
worker 机器需要以下入口组。每个入口组都是 AWS::EC2::SecurityGroupIngress
资源。
入口组 | 描述 | IP 协议 | 端口范围 |
---|---|---|---|
| Vxlan 数据包 |
|
|
| Vxlan 数据包 |
|
|
| 内部集群通信 |
|
|
| 内部集群通信 |
|
|
| kubernetes kubelet、调度程序和控制器管理器 |
|
|
| kubernetes kubelet、调度程序和控制器管理器 |
|
|
| Kubernetes 入口服务 |
|
|
| Kubernetes 入口服务 |
|
|
角色和实例配置集
您必须在 AWS 中为机器授予权限。提供的 CloudFormation 模板通过以下 AWS::IAM::Role
对象为机器授予权限,并为每一组角色提供 AWS::IAM::InstanceProfile
。如果不使用模板,您可以为机器授予以下宽泛权限或单独权限。
角色 | 影响 | 操作 | 资源 |
---|---|---|---|
Master |
|
|
|
|
|
| |
|
|
| |
|
|
| |
Worker |
|
|
|
bootstrap |
|
|
|
|
|
| |
|
|
|
1.8.4.4. 所需的 AWS 权限
将 AdministratorAccess
策略附加到您在 Amazon Web Services (AWS) 中创建的 IAM 用户时,授予该用户所有需要的权限。要部署 OpenShift Container Platform 集群的所有组件,IAM 用户需要以下权限:
安装所需的 EC2 权限
-
ec2:AllocateAddress
-
ec2:AssociateAddress
-
ec2:AuthorizeSecurityGroupEgress
-
ec2:AuthorizeSecurityGroupIngress
-
ec2:CopyImage
-
ec2:CreateNetworkInterface
-
ec2:CreateSecurityGroup
-
ec2:CreateTags
-
ec2:CreateVolume
-
ec2:DeleteSecurityGroup
-
ec2:DeleteSnapshot
-
ec2:DeregisterImage
-
ec2:DescribeAccountAttributes
-
ec2:DescribeAddresses
-
ec2:DescribeAvailabilityZones
-
ec2:DescribeDhcpOptions
-
ec2:DescribeImages
-
ec2:DescribeInstanceAttribute
-
ec2:DescribeInstanceCreditSpecifications
-
ec2:DescribeInstances
-
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:ModifyInstanceAttribute
-
ec2:ModifyNetworkInterfaceAttribute
-
ec2:ReleaseAddress
-
ec2:RevokeSecurityGroupEgress
-
ec2:RevokeSecurityGroupIngress
-
ec2:RunInstances
-
ec2:TerminateInstances
安装过程中创建网络资源所需的权限
-
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,您的帐户不需要这些权限来创建网络资源。
安装所需的 Elasticloadbalancing 权限
-
elasticloadbalancing:AddTags
-
elasticloadbalancing:ApplySecurityGroupsToLoadBalancer
-
elasticloadbalancing:AttachLoadBalancerToSubnets
-
elasticloadbalancing:ConfigureHealthCheck
-
elasticloadbalancing:CreateListener
-
elasticloadbalancing:CreateLoadBalancer
-
elasticloadbalancing:CreateLoadBalancerListeners
-
elasticloadbalancing:CreateTargetGroup
-
elasticloadbalancing:DeleteLoadBalancer
-
elasticloadbalancing:DeregisterInstancesFromLoadBalancer
-
elasticloadbalancing:DeregisterTargets
-
elasticloadbalancing:DescribeInstanceHealth
-
elasticloadbalancing:DescribeListeners
-
elasticloadbalancing:DescribeLoadBalancerAttributes
-
elasticloadbalancing:DescribeLoadBalancers
-
elasticloadbalancing:DescribeTags
-
elasticloadbalancing:DescribeTargetGroupAttributes
-
elasticloadbalancing:DescribeTargetHealth
-
elasticloadbalancing:ModifyLoadBalancerAttributes
-
elasticloadbalancing:ModifyTargetGroup
-
elasticloadbalancing:ModifyTargetGroupAttributes
-
elasticloadbalancing:RegisterInstancesWithLoadBalancer
-
elasticloadbalancing:RegisterTargets
-
elasticloadbalancing:SetLoadBalancerPoliciesOfListener
安装所需的 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
安装所需的 Route53 权限
-
route53:ChangeResourceRecordSets
-
route53:ChangeTagsForResource
-
route53:CreateHostedZone
-
route53:DeleteHostedZone
-
route53:GetChange
-
route53:GetHostedZone
-
route53:ListHostedZones
-
route53:ListHostedZonesByName
-
route53:ListResourceRecordSets
-
route53:ListTagsForResource
-
route53:UpdateHostedZoneComment
安装所需的 S3 权限
-
s3:CreateBucket
-
s3:DeleteBucket
-
s3:GetAccelerateConfiguration
-
s3:GetBucketCors
-
s3:GetBucketLocation
-
s3:GetBucketLogging
-
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
集群 Operators 所需的 S3 权限
-
s3:DeleteObject
-
s3:GetObject
-
s3:GetObjectAcl
-
s3:GetObjectTagging
-
s3:GetObjectVersion
-
s3:PutObject
-
s3:PutObjectAcl
-
s3:PutObjectTagging
删除基本集群资源所需的权限
-
autoscaling:DescribeAutoScalingGroups
-
ec2:DeleteNetworkInterface
-
ec2:DeleteVolume
-
elasticloadbalancing:DeleteTargetGroup
-
elasticloadbalancing:DescribeTargetGroups
-
iam:ListInstanceProfiles
-
iam:ListRolePolicies
-
iam:ListUserPolicies
-
s3:DeleteObject
-
tag:GetResources
删除网络资源所需的权限
-
ec2:DeleteDhcpOptions
-
ec2:DeleteInternetGateway
-
ec2:DeleteNatGateway
-
ec2:DeleteRoute
-
ec2:DeleteRouteTable
-
ec2:DeleteSubnet
-
ec2:DeleteVpc
-
ec2:DeleteVpcEndpoints
-
ec2:DetachInternetGateway
-
ec2:DisassociateRouteTable
-
ec2:ReplaceRouteTableAssociation
如果您使用现有的 VPC,您的帐户不需要这些权限来删除网络资源。
创建清单所需的额外 IAM 和 S3 权限
-
iam:CreateAccessKey
-
iam:CreateUser
-
iam:DeleteAccessKey
-
iam:DeleteUser
-
iam:DeleteUserPolicy
-
iam:GetUserPolicy
-
iam:ListAccessKeys
-
iam:PutUserPolicy
-
iam:TagUser
-
iam:GetUserPolicy
-
iam:ListAccessKeys
-
s3:PutBucketPublicAccessBlock
-
s3:GetBucketPublicAccessBlock
-
s3:PutLifecycleConfiguration
-
s3:HeadBucket
-
s3:ListBucketMultipartUploads
-
s3:AbortMultipartUpload
1.8.5. 生成 SSH 私钥并将其添加到代理中
如果要在集群上执行安装调试或灾难恢复,则必须为 ssh-agent
和安装程序提供 SSH 密钥。
在生产环境中,您需要进行灾难恢复和调试。
您可以使用此密钥以 core
用户身份通过 SSH 连接到 master 节点。在部署集群时,此密钥会添加到 core
用户的 ~/.ssh/authorized_keys
列表中。
您必须使用一个本地密钥,而不要使用在特定平台上配置的密钥,如 AWS 密钥对。
流程
如果还没有为计算机上免密码身份验证而配置的 SSH 密钥,请创建一个。例如,在使用 Linux 操作系统的计算机上运行以下命令:
$ ssh-keygen -t rsa -b 4096 -N '' \ -f <path>/<file_name> 1
- 1
- 指定 SSH 密钥的路径和文件名,如
~/.ssh/id_rsa
。不要指定已存在的 SSH 密钥,因为它会被覆盖。
运行此命令会在指定的位置生成不需要密码的 SSH 密钥。
作为后台任务启动
ssh-agent
进程:$ eval "$(ssh-agent -s)" Agent pid 31874
将 SSH 私钥添加到
ssh-agent
:$ ssh-add <path>/<file_name> 1 Identity added: /home/<you>/<path>/<file_name> (<computer_name>)
- 1
- 指定 SSH 私钥的路径和文件名,如
~/.ssh/id_rsa
后续步骤
- 在安装 OpenShift Container Platform 时,为安装程序提供 SSH 公钥。如果在您置备的基础架构上安装集群,您必须将此密钥提供给集群的机器。
1.8.6. 创建用于 AWS 的安装文件
要使用用户置备的基础架构在 Amazon Web Services (AWS) 上安装 OpenShift Container Platform,您必须生成并修改安装程序部署集群所需的文件,以便集群只创建要使用的机器。您要生成并自定义 install-config.yaml
文件、Kubernetes 清单和 Ignition 配置文件。
1.8.6.1. 创建安装配置文件
生成并自定义安装程序部署集群所需的安装配置文件。
先决条件
- 获取 OpenShift Container Platform 安装程序以及集群的 pull secret。对于受限网络安装,这些文件位于您的堡垒主机上。
流程
获取
install-config.yaml
文件。运行以下命令:
$ ./openshift-install create install-config --dir=<installation_directory> 1
- 1
- 对于
<installation_directory>
,请指定用于保存安装程序所创建的文件的目录名称。
重要指定一个空目录。一些安装信息,如 bootstrap X.509 证书,有较短的过期间隔,因此不要重复使用安装目录。如果要重复使用另一个集群安装中的个别文件,可以将其复制到您的目录中。但是,一些安装数据的文件名可能会在发行版本之间有所改变。从 OpenShift Container Platform 老版本中复制安装文件时要格外小心。
在提示符处,提供您的云的配置详情:
可选:选择用来访问集群机器的 SSH 密钥。
注意对于您要在其上执行安装调试或灾难恢复的生产环境 OpenShift Container Platform 集群,请指定
ssh-agent
进程使用的 SSH 密钥。- 选择 aws 作为目标平台。
- 如果计算机上没有保存 AWS 配置集,请为您配置用于运行安装程序的用户输入 AWS 访问密钥 ID 和 secret 访问密钥。
- 选择要将集群部署到的 AWS 区域。
- 选择您为集群配置的 Route53 服务的基域。
- 为集群输入一个描述性名称。
- 粘贴从 Red Hat OpenShift Cluster Manager 站点的 Pull Secret 页面中获取的 pull secret。
编辑
install-config.yaml
文件,将计算副本(也称为 worker 副本)数设为0
,如以下compute
小节中所示:compute: - hyperthreading: Enabled name: worker platform: {} replicas: 0
编辑
install-config.yaml
文件,以提供在受限网络中安装所需的其他信息。更新
pullSecret
值,使其包含 registry 的身份验证信息:pullSecret: '{"auths":{"<local_registry>": {"auth": "<credentials>","email": "you@example.com"}}}'
对于
<local_registry>
,请指定 registry 域名,以及您的镜像 registry 用来提供内容的可选端口。例如:registry.example.com
或者registry.example.com:5000
。使用<credentials>
为您生成的镜像 registry 指定 base64 编码的用户名和密码。添加
additionalTrustBundle
参数和值。该值必须是您用于镜像 registry 的证书文件内容,可以是现有的可信证书颁发机构或您为镜像 registry 生成的自签名证书。additionalTrustBundle: | -----BEGIN CERTIFICATE----- ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ -----END CERTIFICATE-----
添加镜像内容资源:
imageContentSources: - mirrors: - <local_registry>/<local_repository_name>/release source: quay.io/openshift-release-dev/ocp-release - mirrors: - <local_registry>/<local_repository_name>/release source: registry.svc.ci.openshift.org/ocp/release
使用命令输出中的
imageContentSources
部分来镜像(mirror)仓库,或您从您进入受限网络的介质中的内容时使用的值。可选:将发布策略设置为
Internal
publish: Internal
通过设置这个选项,您可以创建一个内部 Ingress Controller 和一个私有负载均衡器。
可选:备份
install-config.yaml
文件。重要install-config.yaml
文件会在安装过程中消耗掉。如果要重复使用此文件,必须现在备份。
1.8.6.2. 在安装过程中配置集群范围代理
生产环境可能会拒绝直接访问互联网,而是提供 HTTP 或 HTTPS 代理。您可以通过在 install-config.yaml
文件中配置代理设置,将新的 OpenShift Container Platform 集群配置为使用代理。
先决条件
-
现有的
install-config.yaml
文件。 查看集群需要访问的站点,并决定是否需要绕过代理。默认情况下代理所有集群出口流量,包括对托管云供应商 API 的调用。若有需要,将站点添加到 Proxy 对象的
spec.noProxy
字段来绕过代理服务器。注意Proxy 对象的
status.noProxy
字段默认填充实例元数据端点 (169.254.169.254
),以及您的安装配置中networking.machineCIDR
、networking.clusterNetwork.cidr
和networking.serviceNetwork[]
字段的值。
流程
编辑
install-config.yaml
文件并添加代理设置。例如:apiVersion: v1 baseDomain: my.domain.com proxy: httpProxy: http://<username>:<pswd>@<ip>:<port> 1 httpsProxy: http://<username>:<pswd>@<ip>:<port> 2 noProxy: example.com 3 additionalTrustBundle: | 4 -----BEGIN CERTIFICATE----- <MY_TRUSTED_CA_CERT> -----END CERTIFICATE----- ...
- 1
- 用于创建集群外 HTTP 连接的代理 URL。URL 必须是
http
。如果您使用不要求额外代理配置但需要额外 CA 的 MITM 透明代理网络,则不得指定httpProxy
值。 - 2
- 用于创建集群外 HTTPS 连接的代理 URL。如果未指定此字段,
httpProxy
会同时用于 HTTP 和 HTTPS 连接。如果您使用不要求额外代理配置但需要额外 CA 的 MITM 透明代理网络,则不得指定httpsProxy
值。 - 3
- 要排除代理的目标域名、域、IP 地址或其他网络 CIDR 的逗号分隔列表。域之前加上前缀
.
可包含该域的所有子域。使用*
可对所有目的地绕过所有代理。 - 4
- 如果提供,安装程序会在
openshift-config
命名空间中生成名为user-ca-bundle
的 ConfigMap,其包含代理 HTTPS 连接所需的一个或多个额外 CA 证书。然后,Cluster Network Operator 会创建trusted-ca-bundle
ConfigMap,将这些内容与 Red Hat Enterprise Linux CoreOS (RHCOS) 信任捆绑包合并,Proxy 对象的trustedCA
字段中也会引用此 ConfigMap。additionalTrustBundle
字段是必需的,除非代理的身份证书由来自 RHCOS 信任捆绑包的颁发机构签名。如果您使用不要求额外代理配置但需要额外 CA 的 MITM 透明代理网络,您必须提供 MITM CA 证书。
注意安装程序不支持代理的
readinessEndpoints
字段。- 保存该文件,并在安装 OpenShift Container Platform 时引用。
安装程序会创建一个名为 cluster
的集群范围代理,该代理使用提供的 install-config.yaml
文件中的代理设置。如果没有提供代理设置,仍然会创建 cluster
Proxy 对象,但它会有一个零 spec
。
只支持名为 cluster
的 Proxy 对象,且无法创建额外的代理。
1.8.6.3. 创建 Kubernetes 清单和 Ignition 配置文件
由于您必须修改一些集群定义文件并要手动启动集群机器,因此您必须生成 Kubernetes 清单和 Ignition 配置文件,集群需要这两项来创建其机器。
安装程序生成的 Ignition 配置文件中所含的证书会在 24 小时后过期。您必须完成集群安装,并使集群以非降级状态运行 24 小时,以确保完成第一次证书轮转。
先决条件
- 获取 OpenShift Container Platform 安装程序。对于受限网络安装,这些文件位于您的堡垒主机上。
-
创建
install-config.yaml
安装配置文件。
流程
为集群生成 Kubernetes 清单:
$ ./openshift-install create manifests --dir=<installation_directory> 1 INFO Consuming Install Config from target directory WARNING Making control-plane schedulable by setting MastersSchedulable to true for Scheduler cluster settings
- 1
- 对于
<installation_directory>
,请指定含有您创建的install-config.yaml
文件的安装目录。
由于您稍后会在安装过程中自行创建计算机器,因此可以忽略这个警告。
删除定义 control plane 机器的 Kubernetes 清单文件:
$ rm -f <installation_directory>/openshift/99_openshift-cluster-api_master-machines-*.yaml
通过删除这些文件,您可以防止集群自动生成 control plane 机器。
删除定义 worker 机器的 Kubernetes 清单文件:
$ rm -f <installation_directory>/openshift/99_openshift-cluster-api_worker-machineset-*.yaml
由于您要自行创建并管理 worker 机器,因此不需要初始化这些机器。
修改
<installation_directory>/manifests/cluster-scheduler-02-config.yml
Kubernetes 清单文件,以防止在 control plane 机器上调度 Pod:-
打开
<installation_directory>/manifests/cluster-scheduler-02-config.yml
文件。 -
找到
mastersSchedulable
参数,并将其值设为False
。 - 保存并退出文件。
注意目前,由于 Kubernetes 限制,入口负载均衡器将无法访问在 control plane 机器上运行的路由器 Pod。以后的 OpenShift Container Platform 次要版本中可能不需要这一步骤。
-
打开
可选:如果您不希望 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: {}
如果您这样做,后续步骤中必须手动添加入口 DNS 记录。
获取 Ignition 配置文件:
$ ./openshift-install create ignition-configs --dir=<installation_directory> 1
- 1
- 对于
<installation_directory>
,请指定相同的安装目录。
该目录中将生成以下文件:
. ├── auth │ ├── kubeadmin-password │ └── kubeconfig ├── bootstrap.ign ├── master.ign ├── metadata.json └── worker.ign
1.8.7. 提取基础架构名称
Ignition 配置包含一个唯一集群标识符,您可以使用它在 Amazon Web Services (AWS) 中唯一地标识您的集群。提供的 CloudFormation 模板包含对此基础架构名称的引用,因此您必须提取它。
先决条件
- 获取 OpenShift Container Platform 安装程序以及集群的 pull secret。
- 为集群生成 Ignition 配置文件。
-
安装
jq
软件包。
1.8.8. 在 AWS 中创建 VPC
您必须在 Amazon Web Services (AWS) 中创建一个 VPC,供您的 OpenShift Container Platform 集群使用。您可以自定义 VPC 来满足您的要求,包括 VPN 和路由表。创建 VPC 的最简单方法是修改提供的 CloudFormation 模板。
如果不使用提供的 CloudFormation 模板来创建 AWS 基础架构,您必须检查提供的信息并手动创建基础架构。如果集群没有正确初始化,您可能需要联系红帽支持并提供您的安装日志。
先决条件
- 配置 AWS 帐户。
- 为集群生成 Ignition 配置文件。
流程
创建一个 JSON 文件,其包含模板所需的参数值:
[ { "ParameterKey": "VpcCidr", 1 "ParameterValue": "10.0.0.0/16" 2 }, { "ParameterKey": "AvailabilityZoneCount", 3 "ParameterValue": "1" 4 }, { "ParameterKey": "SubnetBits", 5 "ParameterValue": "12" 6 } ]
- 复制本主题的 VPC 的 CloudFormation 模板部分中的模板,并将它以 YAML 文件形式保存到计算机上。此模板描述了集群所需的 VPC。
启动模板:
重要您必须在一行内输入命令。
$ aws cloudformation create-stack --stack-name <name> 1 --template-body file://<template>.yaml 2 --parameters file://<parameters>.json 3
确认模板组件已存在:
$ aws cloudformation describe-stacks --stack-name <name>
在
StackStatus
显示CREATE_COMPLETE
后,输出会显示以下参数的值。您必须将这些参数值提供给您在创建集群时要运行的其他 CloudFormation 模板:VpcId
您的 VPC ID。
PublicSubnetIds
新公共子网的 ID。
PrivateSubnetIds
新专用子网的 ID。
1.8.8.1. VPC 的 CloudFormation 模板
您可以使用以下 CloudFormation 模板来部署 OpenShift Container Platform 集群所需的 VPC。
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"]] ]
1.8.9. 在 AWS 中创建网络和负载均衡组件
您必须在 Amazon Web Services (AWS) 中配置网络和负载均衡 (classic 或 network),以供您的 OpenShift Container Platform 集群使用。创建这些组件的最简单方法是修改提供的 CloudFormation 模板,该模板还可创建托管区和子网标签。
您可以在单个 VPC 内多次运行该模板。
如果不使用提供的 CloudFormation 模板来创建 AWS 基础架构,您必须检查提供的信息并手动创建基础架构。如果集群没有正确初始化,您可能需要联系红帽支持并提供您的安装日志。
先决条件
- 配置 AWS 帐户。
- 为集群生成 Ignition 配置文件。
- 在 AWS 中创建和配置 VPC 及相关子网。
流程
获取您在
install-config.yaml
文件中为集群指定的 Route53 区的托管区 ID。您可以从 AWS 控制台或运行以下命令来获取此 ID:重要您必须在一行内输入命令。
$ aws route53 list-hosted-zones-by-name | jq --arg name "<route53_domain>." \ 1 -r '.HostedZones | .[] | select(.Name=="\($name)") | .Id'
- 1
- 对于
<route53_domain>
,请指定您为集群生成install-config.yaml
文件时所用的 Route53 基域。
创建一个 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
- 用来注册目标的 Route53 公共区 ID。
- 6
- 指定 Route53 公共区 ID,其格式与
Z21IXYZABCZ2A4
类似。您可以从 AWS 控制台获取这个值。 - 7
- 用来注册目标的 Route53 区。
- 8
- 指定您为集群生成
install-config.yaml
文件时所用的 Route53 基域。请勿包含 AWS 控制台中显示的结尾句点 (.)。 - 9
- 为 VPC 创建的公共子网。
- 10
- 指定 VPC 的 CloudFormation 模板输出的
PublicSubnetIds
值。 - 11
- 为 VPC 创建的专用子网。
- 12
- 指定 VPC 的 CloudFormation 模板输出的
PrivateSubnetIds
值。 - 13
- 为集群创建的 VPC。
- 14
- 指定 VPC 的 CloudFormation 模板输出的
VpcId
值。
- 复制本主题的网络和负载均衡器的 CloudFormation 模板部分中的模板,并将它以 YAML 文件形式保存到计算机上。此模板描述了集群所需的网络和负载均衡对象。
启动模板:
重要您必须在一行内输入命令。
$ aws cloudformation create-stack --stack-name <name> 1 --template-body file://<template>.yaml 2 --parameters file://<parameters>.json 3 --capabilities CAPABILITY_NAMED_IAM
确认模板组件已存在:
$ 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。
1.8.9.1. 网络和负载均衡器的 CloudFormation 模板
您可以使用以下 CloudFormation 模板来部署 OpenShift Container Platform 集群所需的网络对象和负载均衡器。
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: 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: 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: 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.7" 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.7" 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
1.8.10. 在 AWS 中创建安全组和角色
您必须在 Amazon Web Services (AWS) 中创建安全组和角色,供您的 OpenShift Container Platform 集群使用。创建这些组件的最简单方法是修改提供的 CloudFormation 模板。
如果不使用提供的 CloudFormation 模板来创建 AWS 基础架构,您必须检查提供的信息并手动创建基础架构。如果集群没有正确初始化,您可能需要联系红帽支持并提供您的安装日志。
先决条件
- 配置 AWS 帐户。
- 为集群生成 Ignition 配置文件。
- 在 AWS 中创建和配置 VPC 及相关子网。
流程
创建一个 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 } ]
- 复制本主题的安全对象的 CloudFormation 模板部分中的模板,并将它以 YAML 文件形式保存到计算机上。此模板描述了集群所需的安全组和角色。
启动模板:
重要您必须在一行内输入命令。
$ aws cloudformation create-stack --stack-name <name> 1 --template-body file://<template>.yaml 2 --parameters file://<parameters>.json 3 --capabilities CAPABILITY_NAMED_IAM
确认模板组件已存在:
$ aws cloudformation describe-stacks --stack-name <name>
在
StackStatus
显示CREATE_COMPLETE
后,输出会显示以下参数的值。您必须将这些参数值提供给您在创建集群时要运行的其他 CloudFormation 模板:MasterSecurityGroupId
Master 安全组 ID
WorkerSecurityGroupId
worker 安全组 ID
MasterInstanceProfile
Master IAM 实例配置集
WorkerInstanceProfile
worker IAM 实例配置集
1.8.10.1. 安全对象的 CloudFormation 模板
您可以使用以下 CloudFormation 模板来部署 OpenShift Container Platform 集群所需的安全对象。
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 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 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:*" Resource: "*" - Effect: "Allow" Action: "elasticloadbalancing:*" Resource: "*" - Effect: "Allow" Action: "iam:PassRole" Resource: "*" - Effect: "Allow" Action: "s3:GetObject" 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:Describe*" 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
1.8.11. AWS 基础架构的 RHCOS AMI
您必须对 OpenShift Container Platform 节点的 Amazon Web Services (AWS) 区使用有效的 Red Hat Enterprise Linux CoreOS (RHCOS) AMI。
AWS 区 | AWS AMI |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1.8.12. 在 AWS 中创建 bootstrap 节点
您必须在 Amazon Web Services (AWS) 中创建 bootstrap 节点,以便在 OpenShift Container Platform 集群初始化过程中使用。创建此节点的最简单方法是修改提供的 CloudFormation 模板。
如果不使用提供的 CloudFormation 模板来创建 bootstrap 节点,您必须检查提供的信息并手动创建基础架构。如果集群没有正确初始化,您可能需要联系红帽支持并提供您的安装日志。
先决条件
- 配置 AWS 帐户。
- 为集群生成 Ignition 配置文件。
- 在 AWS 中创建和配置 VPC 及相关子网。
- 在 AWS 中创建并配置 DNS、负载均衡器和监听程序。
- 创建 control plane 和计算角色。
流程
提供一个位置,以便向集群提供
bootstrap.ign
Ignition 配置文件。此文件位于您的安装目录中。达成此目标的一种方式是在集群区域中创建一个 S3 存储桶,并将 Ignition 配置文件上传到其中。重要提供的 CloudFormation 模板假定集群的 Ignition 配置文件由 S3 存储桶提供。如果选择从其他位置提供文件,您必须修改模板。
注意bootstrap Ignition 配置文件包含 secret,如 X.509 密钥。以下步骤为 S3 存储桶提供基本安全性。若要提供额外的安全性,您可以启用 S3 存储桶策略,仅允许某些用户(如 OpenShift IAM 用户)访问存储桶中包含的对象。您可以完全避开 S3,并从 bootstrap 可访问的任意地址提供 bootstrap Ignition 配置文件。
创建存储桶:
$ aws s3 mb s3://<cluster-name>-infra 1
- 1
<cluster-name>-infra
是存储桶名称。
将
bootstrap.ign
Ignition 配置文件上传到存储桶:$ aws s3 cp bootstrap.ign s3://<cluster-name>-infra/bootstrap.ign
验证文件已经上传:
$ aws s3 ls s3://<cluster-name>-infra/ 2019-04-03 16:15:16 314878 bootstrap.ign
创建一个 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:<region>:<account_number>:function:<dns_stack_name>-RegisterNlbIpTargets-<random_string>" 18 }, { "ParameterKey": "ExternalApiTargetGroupArn", 19 "ParameterValue": "arn:aws:elasticloadbalancing:<region>:<account_number>:targetgroup/<dns_stack_name>-Exter-<random_string>" 20 }, { "ParameterKey": "InternalApiTargetGroupArn", 21 "ParameterValue": "arn:aws:elasticloadbalancing:<region>:<account_number>:targetgroup/<dns_stack_name>-Inter-<random_string>" 22 }, { "ParameterKey": "InternalServiceTargetGroupArn", 23 "ParameterValue": "arn:aws:elasticloadbalancing:<region>:<account_number>:targetgroup/<dns_stack_name>-Inter-<random_string>" 24 } ]
- 1
- 您的 Ignition 配置文件中为集群编码的集群基础架构名称。
- 2
- 指定从 Ignition 配置文件元数据中提取的基础架构名称,其格式为
<cluster-name>-<random-string>
。 - 3
- 用于 bootstrap 节点的当前 Red Hat Enterprise Linux CoreOS (RHCOS) AMI。
- 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
- 指定
yes
或no
。如果指定yes
,您必须提供一个 Lambda Amazon Resource Name (ARN) 值。 - 17
- NLB IP 目标注册 lambda 组的 ARN。
- 18
- 指定 DNS 和负载均衡的 CloudFormation 模板输出的
RegisterNlbIpTargetsLambda
值。 - 19
- 外部 API 负载均衡器目标组的 ARN。
- 20
- 指定 DNS 和负载均衡的 CloudFormation 模板输出的
ExternalApiTargetGroupArn
值。 - 21
- 内部 API 负载均衡器目标组群的 ARN。
- 22
- 指定 DNS 和负载均衡的 CloudFormation 模板输出的
InternalApiTargetGroupArn
值。 - 23
- 内部服务负载均衡器目标组群的 ARN。
- 24
- 指定 DNS 和负载均衡的 CloudFormation 模板输出的
InternalServiceTargetGroupArn
值。
- 复制本主题的 Bootstrap 机器的 CloudFormation 模板部分中的模板,并将它以 YAML 文件形式保存到计算机上。此模板描述了集群所需的 bootstrap 机器。
启动模板:
重要您必须在一行内输入命令。
$ aws cloudformation create-stack --stack-name <name> 1 --template-body file://<template>.yaml 2 --parameters file://<parameters>.json 3 --capabilities CAPABILITY_NAMED_IAM
确认模板组件已存在:
$ aws cloudformation describe-stacks --stack-name <name>
在
StackStatus
显示CREATE_COMPLETE
后,输出会显示以下参数的值。您必须将这些参数值提供给您在创建集群时要运行的其他 CloudFormation 模板:BootstrapInstanceId
bootstrap 实例 ID。
BootstrapPublicIp
bootstrap 节点公共 IP 地址。
BootstrapPrivateIp
bootstrap 节点专用 IP 地址。
1.8.12.1. bootstrap 机器的 CloudFormation 模板
您可以使用以下 CloudFormation 模板来部署 OpenShift Container Platform 集群所需的 bootstrap 机器。
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 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: "i3.large" NetworkInterfaces: - AssociatePublicIpAddress: "true" DeviceIndex: "0" GroupSet: - !Ref "BootstrapSecurityGroup" - !Ref "MasterSecurityGroupId" SubnetId: !Ref "PublicSubnet" UserData: Fn::Base64: !Sub - '{"ignition":{"config":{"replace":{"source":"${S3Loc}","verification":{}}},"timeouts":{},"version":"2.1.0"},"networkd":{},"passwd":{},"storage":{},"systemd":{}}' - { 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
1.8.13. 在 AWS 中创建 control plane 机器
您必须在 Amazon Web Services (AWS) 中创建 control plane 机器,供您的集群使用。创建这些节点的最简单方法是修改提供的 CloudFormation 模板。
如果不使用提供的 CloudFormation 模板来创建 control plane 节点,您必须检查提供的信息并手动创建基础架构。如果集群没有正确初始化,您可能需要联系红帽支持并提供您的安装日志。
先决条件
- 配置 AWS 帐户。
- 为集群生成 Ignition 配置文件。
- 在 AWS 中创建和配置 VPC 及相关子网。
- 在 AWS 中创建并配置 DNS、负载均衡器和监听程序。
- 创建 control plane 和计算角色。
- 创建 bootstrap 机器。
流程
创建一个 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": "m4.xlarge" 26 }, { "ParameterKey": "AutoRegisterELB", 27 "ParameterValue": "yes" 28 }, { "ParameterKey": "RegisterNlbIpTargetsLambdaArn", 29 "ParameterValue": "arn:aws:lambda:<region>:<account_number>:function:<dns_stack_name>-RegisterNlbIpTargets-<random_string>" 30 }, { "ParameterKey": "ExternalApiTargetGroupArn", 31 "ParameterValue": "arn:aws:elasticloadbalancing:<region>:<account_number>:targetgroup/<dns_stack_name>-Exter-<random_string>" 32 }, { "ParameterKey": "InternalApiTargetGroupArn", 33 "ParameterValue": "arn:aws:elasticloadbalancing:<region>:<account_number>:targetgroup/<dns_stack_name>-Inter-<random_string>" 34 }, { "ParameterKey": "InternalServiceTargetGroupArn", 35 "ParameterValue": "arn:aws:elasticloadbalancing:<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
- 指定
yes
或no
。如果指定yes
,您必须提供托管区信息。 - 7
- 用来注册 etcd 目标的 Route53 专用区 ID。
- 8
- 指定 DNS 和负载均衡的 CloudFormation 模板输出的
PrivateHostedZoneId
值。 - 9
- 用来注册目标的 Route53 区。
- 10
- 指定
<cluster_name>.<domain_name>
,其中<domain_name>
是您为集群生成install-config.yaml
文件时所用的 Route53 基域。请勿包含 AWS 控制台中显示的结尾句点 (.)。 - 11 13 15
- 在其中启动 control plane 机器的子网,最好是专用子网。
- 12 14 16
- 从 DNS 和负载均衡的 CloudFormation 模板输出的
PrivateSubnets
值指定子网。 - 17
- 与 master 节点关联的 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
- 与 master 节点关联的 IAM 配置集。
- 24
- 指定安全组和角色的 CloudFormation 模板输出的
MasterInstanceProfile
参数值。 - 25
- 用于 control plane 机器的 AWS 实例类型。
- 26
- 允许的值:
-
m4.xlarge
-
m4.2xlarge
-
m4.4xlarge
-
m4.8xlarge
-
m4.10xlarge
-
m4.16xlarge
-
c4.2xlarge
-
c4.4xlarge
-
c4.8xlarge
-
r4.xlarge
-
r4.2xlarge
-
r4.4xlarge
-
r4.8xlarge
r4.16xlarge
重要如果您的区域中没有
m4
实例类型,例如eu-west-3
,请改为指定m5
类型,如m5.xlarge
。
-
- 27
- 是否要注册网络负载均衡器 (NLB) 。
- 28
- 指定
yes
或no
。如果指定yes
,您必须提供一个 Lambda Amazon Resource Name (ARN) 值。 - 29
- NLB IP 目标注册 lambda 组的 ARN。
- 30
- 指定 DNS 和负载均衡的 CloudFormation 模板输出的
RegisterNlbIpTargetsLambda
值。 - 31
- 外部 API 负载均衡器目标组的 ARN。
- 32
- 指定 DNS 和负载均衡的 CloudFormation 模板输出的
ExternalApiTargetGroupArn
值。 - 33
- 内部 API 负载均衡器目标组群的 ARN。
- 34
- 指定 DNS 和负载均衡的 CloudFormation 模板输出的
InternalApiTargetGroupArn
值。 - 35
- 内部服务负载均衡器目标组群的 ARN。
- 36
- 指定 DNS 和负载均衡的 CloudFormation 模板输出的
InternalServiceTargetGroupArn
值。
- 复制control plane 机器的 CloudFormation 模板一节中的模板,并将它以 YAML 文件形式保存到计算机上。此模板描述了集群所需的 control plane 机器。
-
如果您将
m5
实例类型指定为MasterInstanceType
的值,请将该实例类型添加到 CloudFormation 模板中的MasterInstanceType.AllowedValues
参数。 启动模板:
重要您必须在一行内输入命令。
$ aws cloudformation create-stack --stack-name <name> 1 --template-body file://<template>.yaml 2 --parameters file://<parameters>.json 3
确认模板组件已存在:
$ aws cloudformation describe-stacks --stack-name <name>
1.8.13.1. control plane 机器的 CloudFormation 模板
您可以使用以下 CloudFormation 模板来部署 OpenShift Container Platform 集群所需的 control plane 机器。
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: "yes" AllowedValues: - "yes" - "no" Description: Do you want to invoke DNS etcd registration, which requires Hosted Zone information? Type: String PrivateHostedZoneId: Description: The Route53 private zone ID to register the etcd targets with, such as Z21IXYZABCZ2A4. Type: String PrivateHostedZoneName: Description: The Route53 zone to register the targets with, such as cluster.example.com. Omit the trailing period. 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: m4.xlarge Type: String AllowedValues: - "m4.xlarge" - "m4.2xlarge" - "m4.4xlarge" - "m4.8xlarge" - "m4.10xlarge" - "m4.16xlarge" - "c4.2xlarge" - "c4.4xlarge" - "c4.8xlarge" - "r4.xlarge" - "r4.2xlarge" - "r4.4xlarge" - "r4.8xlarge" - "r4.16xlarge" 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: "DNS" Parameters: - AutoRegisterDNS - PrivateHostedZoneName - PrivateHostedZoneId - 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" AutoRegisterDNS: default: "Use Provided DNS Automation" AutoRegisterELB: default: "Use Provided ELB Automation" PrivateHostedZoneName: default: "Private Hosted Zone Name" PrivateHostedZoneId: default: "Private Hosted Zone ID" Conditions: DoRegistration: !Equals ["yes", !Ref AutoRegisterELB] DoDns: !Equals ["yes", !Ref AutoRegisterDNS] 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":{"append":[{"source":"${SOURCE}","verification":{}}]},"security":{"tls":{"certificateAuthorities":[{"source":"${CA_BUNDLE}","verification":{}}]}},"timeouts":{},"version":"2.2.0"},"networkd":{},"passwd":{},"storage":{},"systemd":{}}' - { 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":{"append":[{"source":"${SOURCE}","verification":{}}]},"security":{"tls":{"certificateAuthorities":[{"source":"${CA_BUNDLE}","verification":{}}]}},"timeouts":{},"version":"2.2.0"},"networkd":{},"passwd":{},"storage":{},"systemd":{}}' - { 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":{"append":[{"source":"${SOURCE}","verification":{}}]},"security":{"tls":{"certificateAuthorities":[{"source":"${CA_BUNDLE}","verification":{}}]}},"timeouts":{},"version":"2.2.0"},"networkd":{},"passwd":{},"storage":{},"systemd":{}}' - { 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 EtcdSrvRecords: Condition: DoDns Type: AWS::Route53::RecordSet Properties: HostedZoneId: !Ref PrivateHostedZoneId Name: !Join [".", ["_etcd-server-ssl._tcp", !Ref PrivateHostedZoneName]] ResourceRecords: - !Join [ " ", ["0 10 2380", !Join [".", ["etcd-0", !Ref PrivateHostedZoneName]]], ] - !Join [ " ", ["0 10 2380", !Join [".", ["etcd-1", !Ref PrivateHostedZoneName]]], ] - !Join [ " ", ["0 10 2380", !Join [".", ["etcd-2", !Ref PrivateHostedZoneName]]], ] TTL: 60 Type: SRV Etcd0Record: Condition: DoDns Type: AWS::Route53::RecordSet Properties: HostedZoneId: !Ref PrivateHostedZoneId Name: !Join [".", ["etcd-0", !Ref PrivateHostedZoneName]] ResourceRecords: - !GetAtt Master0.PrivateIp TTL: 60 Type: A Etcd1Record: Condition: DoDns Type: AWS::Route53::RecordSet Properties: HostedZoneId: !Ref PrivateHostedZoneId Name: !Join [".", ["etcd-1", !Ref PrivateHostedZoneName]] ResourceRecords: - !GetAtt Master1.PrivateIp TTL: 60 Type: A Etcd2Record: Condition: DoDns Type: AWS::Route53::RecordSet Properties: HostedZoneId: !Ref PrivateHostedZoneId Name: !Join [".", ["etcd-2", !Ref PrivateHostedZoneName]] ResourceRecords: - !GetAtt Master2.PrivateIp TTL: 60 Type: A Outputs: PrivateIPs: Description: The control-plane node private IP addresses. Value: !Join [ ",", [!GetAtt Master0.PrivateIp, !GetAtt Master1.PrivateIp, !GetAtt Master2.PrivateIp] ]
1.8.14. 使用用户置备的基础架构在 AWS 上初始化 bootstrap 节点
在 Amazon Web Services (AWS) 中创建所有所需的基础架构后,就可以安装集群。
先决条件
- 配置 AWS 帐户。
- 为集群生成 Ignition 配置文件。
- 在 AWS 中创建和配置 VPC 及相关子网。
- 在 AWS 中创建并配置 DNS、负载均衡器和监听程序。
- 创建 control plane 和计算角色。
- 创建 bootstrap 机器。
- 创建 control plane 机器。
- 如果您计划手动管理 worker 机器,请创建 worker 机器。
流程
更改到包含安装程序的目录,再运行以下命令:
$ ./openshift-install wait-for bootstrap-complete --dir=<installation_directory> \ 1 --log-level=info 2
如果命令退出且不显示
FATAL
警告,则代表您的 control plane 已被初始化。
1.8.14.1. 在 AWS 中创建 worker 节点
您可以在 Amazon Web Services (AWS) 中创建 worker 节点,供集群使用。手动创建这些节点的最简单方法是修改提供的 CloudFormation 模板。
CloudFormation 模板会创建一个堆栈,其代表一台 worker 机器。您必须为每台 worker 机器创建一个堆栈。
如果不使用提供的 CloudFormation 模板来创建 worker 节点,您必须检查提供的信息并手动创建基础架构。如果集群没有正确初始化,您可能需要联系红帽支持并提供您的安装日志。
先决条件
- 配置 AWS 帐户。
- 为集群生成 Ignition 配置文件。
- 在 AWS 中创建和配置 VPC 及相关子网。
- 在 AWS 中创建并配置 DNS、负载均衡器和监听程序。
- 创建 control plane 和计算角色。
- 创建 bootstrap 机器。
- 创建 control plane 机器。
流程
创建一个 JSON 文件,其包含 CloudFormation 模板需要的参数值:
[ { "ParameterKey": "InfrastructureName", 1 "ParameterValue": "mycluster-<random_string>" 2 }, { "ParameterKey": "RhcosAmi", 3 "ParameterValue": "ami-<random_string>" 4 }, { "ParameterKey": "Subnet", 5 "ParameterValue": "subnet-<random_string>" 6 }, { "ParameterKey": "WorkerSecurityGroupId", 7 "ParameterValue": "sg-<random_string>" 8 }, { "ParameterKey": "IgnitionLocation", 9 "ParameterValue": "https://api-int.<cluster_name>.<domain_name>:22623/config/worker" 10 }, { "ParameterKey": "CertificateAuthorities", 11 "ParameterValue": "" 12 }, { "ParameterKey": "WorkerInstanceProfileName", 13 "ParameterValue": "" 14 }, { "ParameterKey": "WorkerInstanceType", 15 "ParameterValue": "m4.large" 16 } ]
- 1
- 您的 Ignition 配置文件中为集群编码的集群基础架构名称。
- 2
- 指定从 Ignition 配置文件元数据中提取的基础架构名称,其格式为
<cluster-name>-<random-string>
。 - 3
- 用于 worker 节点的当前 Red Hat Enterprise Linux CoreOS (RHCOS) AMI。
- 4
- 指定
AWS::EC2::Image::Id
值。 - 5
- 在其中启动 worker 节点的子网,最好是专用子网。
- 6
- 从 DNS 和负载均衡的 CloudFormation 模板输出的
PrivateSubnets
值指定子网。 - 7
- 与 worker 节点关联的 worker 安全组 ID。
- 8
- 指定安全组和角色的 CloudFormation 模板输出的
WorkerSecurityGroupId
值。 - 9
- 从中获取 bootstrap Ignition 配置文件的位置。
- 10
- 指定生成的 Ignition 配置的位置,
https://api-int.<cluster_name>.<domain_name>:22623/config/worker
。 - 11
- 要使用的 Base64 编码证书颁发机构字符串。
- 12
- 指定安装目录下
worker.ign
文件中的值。这个值是一个长字符串,格式为data:text/plain;charset=utf-8;base64,ABC…xYz==
。 - 13
- 与 worker 节点关联的 IAM 配置集。
- 14
- 指定安全组和角色的 CloudFormation 模板输出的
WorkerInstanceProfile
参数值。 - 15
- 用于 control plane 机器的 AWS 实例类型。
- 16
- 允许的值:
-
m4.large
-
m4.xlarge
-
m4.2xlarge
-
m4.4xlarge
-
m4.8xlarge
-
m4.10xlarge
-
m4.16xlarge
-
c4.large
-
c4.xlarge
-
c4.2xlarge
-
c4.4xlarge
-
c4.8xlarge
-
r4.large
-
r4.xlarge
-
r4.2xlarge
-
r4.4xlarge
-
r4.8xlarge
r4.16xlarge
重要如果您的区域中没有
m4
实例类型,例如eu-west-3
,请改为使用m5
类型。
-
- 复制 worker 机器的 CloudFormation 模板一节中的模板,并将它以 YAML 文件形式保存到计算机上。此模板描述了集群所需的网络对象和负载均衡器。
-
如果您将
m5
实例类型指定为WorkerInstanceType
的值,请将该实例类型添加到 CloudFormation 模板中的WorkerInstanceType.AllowedValues
参数。 创建 worker 堆栈。
启动模板:
重要您必须在一行内输入命令。
$ aws cloudformation create-stack --stack-name <name> 1 --template-body file://<template>.yaml \ 2 --parameters file://<parameters>.json 3
确认模板组件已存在:
$ aws cloudformation describe-stacks --stack-name <name>
继续创建 worker 堆栈,直到为集群创建了充足的 worker 机器。
重要您必须至少创建两台 worker 机器,因此您必须创建至少两个使用此 CloudFormation 模板的堆栈。
1.8.14.1.1. worker 机器的 CloudFormation 模板
您可以使用以下 CloudFormation 模板来部署 OpenShift Container Platform 集群所需的 worker 机器。
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: m4.large Type: String AllowedValues: - "m4.large" - "m4.xlarge" - "m4.2xlarge" - "m4.4xlarge" - "m4.8xlarge" - "m4.10xlarge" - "m4.16xlarge" - "c4.large" - "c4.xlarge" - "c4.2xlarge" - "c4.4xlarge" - "c4.8xlarge" - "r4.large" - "r4.xlarge" - "r4.2xlarge" - "r4.4xlarge" - "r4.8xlarge" - "r4.16xlarge" 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":{"append":[{"source":"${SOURCE}","verification":{}}]},"security":{"tls":{"certificateAuthorities":[{"source":"${CA_BUNDLE}","verification":{}}]}},"timeouts":{},"version":"2.2.0"},"networkd":{},"passwd":{},"storage":{},"systemd":{}}' - { 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
1.8.15. 登录集群
您可以通过导出集群 kubeconfig
文件,以默认系统用户身份登录集群。kubeconfig
文件包含关于集群的信息,供 CLI 用于将客户端连接到正确集群和 API 服务器。该文件特只适用于一个特定的集群,在 OpenShift Container Platform 安装过程中创建。
先决条件
- 部署 OpenShift Container Platform 集群。
-
安装
oc
CLI。
流程
导出
kubeadmin
凭证:$ export KUBECONFIG=<installation_directory>/auth/kubeconfig 1
- 1
- 对于
<installation_directory>
,请指定安装文件保存到的目录的路径。
使用导出的配置,验证能否成功运行
oc
命令:$ oc whoami system:admin
1.8.16. 批准机器的 CSR
将机器添加到集群时,会为您添加的每台机器生成两个待处理证书签名请求(CSR)。您必须确认这些 CSR 已获得批准,或根据需要自行批准。
先决条件
- 您已将机器添加到集群中。
流程
确认集群可以识别这些机器:
$ oc get nodes NAME STATUS ROLES AGE VERSION master-0 Ready master 63m v1.16.2 master-1 Ready master 63m v1.16.2 master-2 Ready master 64m v1.16.2 worker-0 NotReady worker 76s v1.16.2 worker-1 NotReady worker 70s v1.16.2
输出将列出您创建的所有机器。
检查待处理的 CSR,并确保添加到集群中的每台机器都有
Pending
或Approved
状态的客户端和服务器请求:$ oc get csr NAME AGE REQUESTOR CONDITION csr-8b2br 15m system:serviceaccount:openshift-machine-config-operator:node-bootstrapper Pending 1 csr-8vnps 15m system:serviceaccount:openshift-machine-config-operator:node-bootstrapper Pending csr-bfd72 5m26s system:node:ip-10-0-50-126.us-east-2.compute.internal Pending 2 csr-c57lv 5m26s system:node:ip-10-0-95-157.us-east-2.compute.internal Pending ...
在本例中,两台机器加入了集群。您可能会在列表中看到更多已批准的 CSR。
如果 CSR 没有获得批准,请在所添加机器的所有待处理 CSR 都处于
Pending
状态后,为您的集群机器批准这些 CSR:注意由于 CSR 会自动轮转,因此请在将机器添加到集群后一小时内批准您的 CSR。如果没有在一小时内批准,证书将会轮转,每个节点将会存在多个证书。您必须批准所有这些证书。批准初始 CSR 后,集群的
kube-controller-manager
会自动批准后续的节点客户端 CSR。您必须实施一个方法来自动批准 kubelet 提供的证书请求。若要单独批准,请对每个有效的 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
其他信息
- 如需有关 CSR 的更多信息,请参阅证书签名请求。
1.8.17. 初始 Operator 配置
在 control plane 初始化后,您必须立即配置一些 Operator 以便它们都可用。
先决条件
- 您的 control plane 已初始化。
流程
观察集群组件上线:
$ watch -n5 oc get clusteroperators NAME VERSION AVAILABLE PROGRESSING DEGRADED SINCE authentication 4.3.0 True False False 69s cloud-credential 4.3.0 True False False 12m cluster-autoscaler 4.3.0 True False False 11m console 4.3.0 True False False 46s dns 4.3.0 True False False 11m image-registry 4.3.0 True False False 5m26s ingress 4.3.0 True False False 5m36s kube-apiserver 4.3.0 True False False 8m53s kube-controller-manager 4.3.0 True False False 7m24s kube-scheduler 4.3.0 True False False 12m machine-api 4.3.0 True False False 12m machine-config 4.3.0 True False False 7m36s marketplace 4.3.0 True False False 7m54m monitoring 4.3.0 True False False 7h54s network 4.3.0 True False False 5m9s node-tuning 4.3.0 True False False 11m openshift-apiserver 4.3.0 True False False 11m openshift-controller-manager 4.3.0 True False False 5m943s openshift-samples 4.3.0 True False False 3m55s operator-lifecycle-manager 4.3.0 True False False 11m operator-lifecycle-manager-catalog 4.3.0 True False False 11m service-ca 4.3.0 True False False 11m service-catalog-apiserver 4.3.0 True False False 5m26s service-catalog-controller-manager 4.3.0 True False False 5m25s storage 4.3.0 True False False 5m30s
- 配置不可用的 Operator。
1.8.17.1. 镜像 registry 存储配置
Amazon Web Services 提供默认存储,这意味着 image-registry
Operator 在安装后即可用。但是,如果 Registry Operator 无法创建 S3 存储桶并自动配置存储,您需要手工配置 registry 存储。
提供了配置 PersistentVolume 的说明,这是生产集群所需要的;也提供了将空目录配置为存储位置的说明,这仅适用于非生产集群。
1.8.17.1.1. 为使用用户置备的基础架构的 AWS 配置 registry 存储
在安装过程中,使用您的云凭据就可以创建一个S3 存储桶,Registry Operator 将会自动配置存储。
如果 Registry Operator 无法创建 S3 存储桶或自动配置存储,您可以按照以下流程创建 S3 存储桶并配置存储。
先决条件
- 使用用户置备的 AWS 中有一个集群。
对于 AWS 上的 S3 存储,secret 应该包含以下两个键:
-
REGISTRY_STORAGE_S3_ACCESSKEY
-
REGISTRY_STORAGE_S3_SECRETKEY
-
流程
如果 Registry Operator 无法创建 S3 存储桶并自动配置存储,请进行以下操作。
- 设置一个 Bucket Lifecycle Policy用来终止已有一天之久的未完成的分段上传操作。
在
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 存储桶的公共访问。
1.8.17.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
等待几分钟,然后再次运行该命令。
1.8.18. 删除 bootstrap 资源:
完成集群的初始 Operator 配置后,从 Amazon Web Services (AWS) 中删除 bootstrap 资源。
先决条件
- 已为集群完成初始的 Operator 配置。
1.8.19. 创建 Ingress DNS 记录
如果您删除了 DNS 区配置,请手动创建指向 Ingress 负载均衡器的 DNS 记录。您可以创建一个 wildcard 记录或具体的记录。以下流程使用了 A 记录,但您可以使用其他所需记录类型,如 CNAME 或别名。
先决条件
- 已在 Amazon Web Services (AWS) 上安装了使用您置备的基础架构的 OpenShift Container Platform 集群。
-
安装 OpenShift CLI(
oc
)。 -
安装
jq
软件包。 - 下载 AWS CLI 并安装到您的计算机上。请参阅使用捆绑安装程序(Linux、macOS 或 Unix)安装 AWS CLI的文档。
流程
决定要创建的路由。
-
要创建一个 wildcard 记录,请使用
*.apps.<cluster_name>.<domain_name>
,其中<cluster_name>
是集群名称,<domain_name>
是 OpenShift Container Platform 集群的 Route53 基域。 要创建特定的记录,您必须为集群使用的每个路由创建一个记录,如下所示:
$ 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> grafana-openshift-monitoring.apps.<cluster_name>.<domain_name> prometheus-k8s-openshift-monitoring.apps.<cluster_name>.<domain_name>
-
要创建一个 wildcard 记录,请使用
获取 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
为负载均衡器定位托管区 ID:
$ aws elb describe-load-balancers | jq -r '.LoadBalancerDescriptions[] | select(.DNSName == "<external_ip>").CanonicalHostedZoneNameID' 1 Z3AADJGX6KTTL2
- 1
- 对于
<external_ip>
,请指定您获取的 Ingress Operator 负载均衡器的外部 IP 地址值。
这个命令的输出是负载均衡器托管区 ID。
获取集群域的公共托管区 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 /hostedzone/Z3URY6TWQ91KVV
命令输出中会显示您的域的公共托管区 ID。在本例中是
Z3URY6TWQ91KVV
。在您的私有区中添加别名记录:
$ 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 > } > } > } > ] > }'
在您的公共区中添加记录:
$ 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.8.20. 在用户置备的基础架构上完成 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 INFO Waiting up to 30m0s for the cluster to initialize...
- 1
- 对于
<installation_directory>
,请指定安装文件保存到的目录的路径。
重要安装程序生成的 Ignition 配置文件中所含的证书会在 24 小时后过期。您必须以非降级状态持续运行集群 24 小时,以确保完成第一次证书轮转。
- 在 Cluster registration 页面注册您的集群。
1.8.21. 后续步骤
- 自定义集群。
- 若有需要,您可以选择不使用远程健康报告。
1.9. 在 AWS 上卸载集群
您可以删除部署到 Amazon Web Services (AWS) 的集群。
1.9.1. 删除使用安装程序置备的基础架构的集群
您可以从云中删除使用安装程序置备的基础架构的集群。
先决条件
- 有部署集群时所用的安装程序副本。
- 有创建集群时安装程序所生成的文件。
流程
在用来安装集群的计算机中运行以下命令:
$ ./openshift-install destroy cluster \ --dir=<installation_directory> --log-level=info 1 2
注意您必须为集群指定包含集群定义文件的目录。安装程序需要此目录中的
metadata.json
文件来删除集群。-
可选:删除
<installation_directory>
目录和 OpenShift Container Platform 安装程序。
Legal Notice
Copyright © 2024 Red Hat, Inc.
OpenShift documentation is licensed under the Apache License 2.0 (https://www.apache.org/licenses/LICENSE-2.0).
Modified versions must remove all Red Hat trademarks.
Portions adapted from https://github.com/kubernetes-incubator/service-catalog/ with modifications by Red Hat.
Red Hat, Red Hat Enterprise Linux, the Red Hat logo, the Shadowman logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat Software Collections is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation’s permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.