12.8. 创建用于 AWS 的安装文件
要使用用户置备的基础架构在 Amazon Web Services (AWS) 上安装 OpenShift Container Platform,您必须生成并修改安装程序部署集群所需的文件,以便集群只创建要使用的机器。您要生成并自定义 install-config.yaml
文件、Kubernetes 清单和 Ignition 配置文件。您还可以选择在安装准备阶段首先设置独立 var
分区。
12.8.1. 可选:创建独立 /var 分区 复制链接链接已复制到粘贴板!
建议安装程序将 OpenShift Container Platform 的磁盘分区保留给安装程序。然而,在有些情况下您可能需要在文件系统的一部分中创建独立分区。
OpenShift Container Platform 支持添加单个分区来将存储附加到 /var
分区或 /var
的子目录中。例如:
-
/var/lib/containers
:保存随着系统中添加更多镜像和容器而增长的容器相关内容。 -
/var/lib/etcd
:保存您可能希望独立保留的数据,比如 etcd 存储的性能优化。 -
/var
:保存您可能希望独立保留的数据,以满足审计等目的。
通过单独存储 /var
目录的内容,可以更轻松地根据需要为区域扩展存储,并在以后重新安装 OpenShift Container Platform,并保持该数据的完整性。使用这个方法,您不必再次拉取所有容器,在更新系统时也不必复制大量日志文件。
因为 /var
在进行一个全新的 Red Hat Enterprise Linux CoreOS(RHCOS)安装前必需存在,所以这个流程会在 OpenShift Container Platform 安装过程的 openshift-install
准备阶段插入一个创建的机器配置清单的机器配置来设置独立的 /var
分区。
如果按照以下步骤在此流程中创建独立 /var
分区,则不需要再次创建 Kubernetes 清单和 Ignition 配置文件,如本节所述。
流程
创建存放 OpenShift Container Platform 安装文件的目录:
mkdir $HOME/clusterconfig
$ mkdir $HOME/clusterconfig
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 运行
openshift-install
,以在manifest
和openshift
子目录中创建一组文件。在系统提示时回答系统问题:openshift-install create manifests --dir $HOME/clusterconfig
$ openshift-install create manifests --dir $HOME/clusterconfig
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 输出示例
? SSH Public Key ... INFO Credentials loaded from the "myprofile" profile in file "/home/myuser/.aws/credentials" INFO Consuming Install Config from target directory INFO Manifests created in: $HOME/clusterconfig/manifests and $HOME/clusterconfig/openshift
? SSH Public Key ... INFO Credentials loaded from the "myprofile" profile in file "/home/myuser/.aws/credentials" INFO Consuming Install Config from target directory INFO Manifests created in: $HOME/clusterconfig/manifests and $HOME/clusterconfig/openshift
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 可选:确认安装程序在
clusterconfig/openshift
目录中创建了清单:ls $HOME/clusterconfig/openshift/
$ ls $HOME/clusterconfig/openshift/
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 输出示例
99_kubeadmin-password-secret.yaml 99_openshift-cluster-api_master-machines-0.yaml 99_openshift-cluster-api_master-machines-1.yaml 99_openshift-cluster-api_master-machines-2.yaml ...
99_kubeadmin-password-secret.yaml 99_openshift-cluster-api_master-machines-0.yaml 99_openshift-cluster-api_master-machines-1.yaml 99_openshift-cluster-api_master-machines-2.yaml ...
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 创建用于配置额外分区的 Butane 配置。例如,将文件命名为
$HOME/clusterconfig/98-var-partition.bu
,将磁盘设备名称改为worker
系统上存储设备的名称,并根据情况设置存储大小。这个示例将/var
目录放在一个单独的分区中:Copy to Clipboard Copied! Toggle word wrap Toggle overflow 注意当创建单独的
/var
分区时,如果不同的实例类型没有相同的设备名称,则无法为 worker 节点使用不同的实例类型。从 Butane 配置创建一个清单,并将它保存到
clusterconfig/openshift
目录中。例如,运行以下命令:butane $HOME/clusterconfig/98-var-partition.bu -o $HOME/clusterconfig/openshift/98-var-partition.yaml
$ butane $HOME/clusterconfig/98-var-partition.bu -o $HOME/clusterconfig/openshift/98-var-partition.yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 再次运行
openshift-install
,从manifest
和openshift
子目录中的一组文件创建 Ignition 配置:openshift-install create ignition-configs --dir $HOME/clusterconfig ls $HOME/clusterconfig/
$ openshift-install create ignition-configs --dir $HOME/clusterconfig $ ls $HOME/clusterconfig/ auth bootstrap.ign master.ign metadata.json worker.ign
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
现在,您可以使用 Ignition 配置文件作为安装程序的输入来安装 Red Hat Enterprise Linux CoreOS(RHCOS)系统。
12.8.2. 创建安装配置文件 复制链接链接已复制到粘贴板!
生成并自定义安装程序部署集群所需的安装配置文件。
先决条件
- 已获取 OpenShift Container Platform 安装程序用于用户置备的基础架构和集群的 pull secret。
-
使用红帽发布的附带 Red Hat Enterprise Linux CoreOS(RHCOS)AMI 检查您是否将集群部署到一个区域。如果您要部署到需要自定义 AMI 的区域,如 AWS GovCloud 区域,您必须手动创建
install-config.yaml
文件。
流程
创建
install-config.yaml
文件。进入包含安装程序的目录并运行以下命令:
./openshift-install create install-config --dir <installation_directory>
$ ./openshift-install create install-config --dir <installation_directory>
1 Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- 对于
<installation_directory>
,请指定要存储安装程序创建的文件的目录名称。
重要指定一个空目录。有些安装资产,如 bootstrap X.509 证书的过期间隔较短,因此不得重复使用安装目录。如果要重复使用另一个集群安装中的单个文件,您可以将它们复制到您的目录中。但是,安装资产的文件名可能会在发行版本间有所变化。从以前的 OpenShift Container Platform 版本中复制安装文件时请小心。
在提示符处,提供云的配置详情:
可选: 选择用于访问集群机器的 SSH 密钥。
注意对于您要在其上执行安装调试或灾难恢复的生产环境 OpenShift Container Platform 集群,请指定
ssh-agent
进程使用的 SSH 密钥。- 选择 aws 作为目标平台。
如果计算机上没有保存 AWS 配置集,请为您配置用于运行安装程序的用户输入 AWS 访问密钥 ID 和 secret 访问密钥。
注意AWS 访问密钥 ID 和 secret 访问密钥存储在安装主机上当前用户主目录中的
~/.aws/credentials
中。如果文件中不存在导出的配置集凭证,安装程序会提示您输入凭证。您向安装程序提供的所有凭证都存储在文件中。- 选择要将集群部署到的 AWS 区域。
- 选择您为集群配置的 Route 53 服务的基域。
- 为集群输入描述性名称。
- 粘贴 Red Hat OpenShift Cluster Manager 中的 pull secret。
-
如果要安装三节点集群,请通过将
compute.replicas
参数设置为0
来修改install-config.yaml
文件。这样可确保集群的 control plane 可以调度。如需更多信息,请参阅"在 AWS 上安装三节点集群"。 可选:备份
install-config.yaml
文件。重要install-config.yaml
文件会在安装过程中消耗掉。如果要重复使用此文件,必须现在备份。
12.8.3. 在安装过程中配置集群范围代理 复制链接链接已复制到粘贴板!
生产环境可能会拒绝直接访问互联网,而是提供 HTTP 或 HTTPS 代理。您可以通过在 install-config.yaml
文件中配置代理设置,将新的 OpenShift Container Platform 集群配置为使用代理。
先决条件
-
您有一个现有的
install-config.yaml
文件。 您检查了集群需要访问的站点,并确定它们中的任何站点是否需要绕过代理。默认情况下,所有集群出口流量都经过代理,包括对托管云供应商 API 的调用。如果需要,您将在
Proxy 对象的
spec.noProxy
字段中添加站点来绕过代理。注意Proxy
对象status.noProxy
字段使用安装配置中的networking.machineNetwork[].cidr
、networking.clusterNetwork[].cidr
和networking.serviceNetwork[]
字段的值填充。对于在 Amazon Web Services(AWS)、Google Cloud Platform(GCP)、Microsoft Azure 和 Red Hat OpenStack Platform(RHOSP)上安装,
Proxy
对象status.noProxy
字段也会使用实例元数据端点填充(169.254.169.254
)。
流程
编辑
install-config.yaml
文件并添加代理设置。例如:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- 用于创建集群外 HTTP 连接的代理 URL。URL 方案必须是
http
。 - 2
- 用于创建集群外 HTTPS 连接的代理 URL。
- 3
- 要从代理中排除的目标域名、IP 地址或其他网络 CIDR 的逗号分隔列表。在域前面加上
.
以仅匹配子域。例如,.y.com
匹配x.y.com
,但不匹配y.com
。使用*
绕过所有目的地的代理。如果您已将 AmazonEC2
、Elastic Load Balancing
和S3
VPC 端点添加到 VPC 中,您必须将这些端点添加到noProxy
字段。 - 4
- 如果提供,安装程序会在
openshift-config
命名空间中生成名为user-ca-bundle
的配置映射,其包含代理 HTTPS 连接所需的一个或多个额外 CA 证书。然后,Cluster Network Operator 会创建trusted-ca-bundle
配置映射,将这些内容与 Red Hat Enterprise Linux CoreOS(RHCOS)信任捆绑包合并,Proxy
对象的trustedCA
字段中也会引用此配置映射。additionalTrustBundle
字段是必需的,除非代理的身份证书由来自 RHCOS 信任捆绑包的颁发机构签名。 - 5
- 可选:决定
Proxy
对象的配置以引用trustedCA
字段中user-ca-bundle
配置映射的策略。允许的值是Proxyonly
和Always
。仅在配置了http/https
代理时,使用Proxyonly
引用user-ca-bundle
配置映射。使用Always
始终引用user-ca-bundle
配置映射。默认值为Proxyonly
。
注意安装程序不支持代理的
readinessEndpoints
字段。注意如果安装程序超时,重启并使用安装程序的
wait-for
命令完成部署。例如:./openshift-install wait-for install-complete --log-level debug
$ ./openshift-install wait-for install-complete --log-level debug
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 保存该文件并在安装 OpenShift Container Platform 时引用。
安装程序会创建一个名为 cluster 的集群范围代理,该代理 使用
提供的 install-config.yaml
文件中的代理设置。如果没有提供代理设置,仍然会创建一个 cluster
Proxy
对象,但它会有一个空 spec
。
只支持名为 cluster
的 Proxy
对象,且无法创建额外的代理。
12.8.4. 创建 Kubernetes 清单和 Ignition 配置文件 复制链接链接已复制到粘贴板!
由于您必须修改一些集群定义文件并手动启动集群机器,因此您必须生成 Kubernetes 清单和 Ignition 配置文件来配置机器。
安装配置文件转换为 Kubernetes 清单。清单嵌套到 Ignition 配置文件中,稍后用于配置集群机器。
-
OpenShift Container Platform 安装程序生成的 Ignition 配置文件包含 24 小时后过期的证书,然后在该时进行续订。如果在更新证书前关闭集群,且集群在 24 小时后重启,集群会自动恢复过期的证书。一个例外是,您必须手动批准待处理的
node-bootstrapper
证书签名请求(CSR)来恢复 kubelet 证书。如需更多信息,请参阅从过期的 control plane 证书 中恢复的文档。 - 建议您在 Ignition 配置文件生成后的 12 小时内使用它们,因为 24 小时的证书会在集群安装后的 16 小时到 22 小时间进行轮转。通过在 12 小时内使用 Ignition 配置文件,您可以避免在安装过程中因为执行了证书更新而导致安装失败的问题。
先决条件
- 已获得 OpenShift Container Platform 安装程序。
-
已创建
install-config.yaml
安装配置文件。
流程
进入包含 OpenShift Container Platform 安装程序的目录,并为集群生成 Kubernetes 清单:
./openshift-install create manifests --dir <installation_directory>
$ ./openshift-install create manifests --dir <installation_directory>
1 Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- 对于
<installation_directory>
,请指定包含您创建的install-config.yaml
文件的安装目录。
删除定义 control plane 机器的 Kubernetes 清单文件:
rm -f <installation_directory>/openshift/99_openshift-cluster-api_master-machines-*.yaml
$ rm -f <installation_directory>/openshift/99_openshift-cluster-api_master-machines-*.yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 通过删除这些文件,您可以防止集群自动生成 control plane 机器。
删除定义 control plane 机器集的 Kubernetes 清单文件:
rm -f <installation_directory>/openshift/99_openshift-machine-api_master-control-plane-machine-set.yaml
$ rm -f <installation_directory>/openshift/99_openshift-machine-api_master-control-plane-machine-set.yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 删除定义 worker 机器的 Kubernetes 清单文件:
rm -f <installation_directory>/openshift/99_openshift-cluster-api_worker-machineset-*.yaml
$ rm -f <installation_directory>/openshift/99_openshift-cluster-api_worker-machineset-*.yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 重要如果在用户置备的基础架构上安装集群时禁用了
MachineAPI
功能,则必须删除定义 worker 机器的 Kubernetes 清单文件。否则,集群将无法安装。由于您要自行创建和管理 worker 机器,因此不需要初始化这些机器。
警告如果您要安装一个三节点集群,请跳过以下步骤,以便可以调度 control plane 节点。
重要当您将 control plane 节点从默认的不可调度配置为可以调度时,需要额外的订阅。这是因为 control plane 节点变为计算节点。
检查
<installation_directory>/manifests/cluster-scheduler-02-config.yml Kubernetes 清单文件中的
mastersSchedulable
参数是否已设置为false
。此设置可防止在 control plane 机器上调度 pod:-
打开
<installation_directory>/manifests/cluster-scheduler-02-config.yml
文件。 -
找到
mastersSchedulable
参数,并确保它被设置为false
。 - 保存并退出 文件。
-
打开
可选:如果您不希望 Ingress Operator 代表您创建 DNS 记录,请删除
<installation_directory>/manifests/cluster-dns-02-config.yml
DNS 配置文件中的privateZone
和 publicZone
部分:Copy to Clipboard Copied! Toggle word wrap Toggle overflow 如果这样做,您必须在后续步骤中手动添加入口 DNS 记录。
要创建 Ignition 配置文件,请从包含安装程序的目录运行以下命令:
./openshift-install create ignition-configs --dir <installation_directory>
$ ./openshift-install create ignition-configs --dir <installation_directory>
1 Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- 对于
<installation_directory>
,请指定相同的安装目录。
为安装目录中的 bootstrap、control plane 和计算节点创建 Ignition 配置文件。
kubeadmin-password
和kubeconfig
文件在./<installation_directory>/auth
目录中创建:Copy to Clipboard Copied! Toggle word wrap Toggle overflow