×

在 OpenShift Container Platform 4.17 版本中,您可以使用安装程序预配的基础架构在 Microsoft Azure Stack Hub 上安装集群。但是,您必须手动配置install-config.yaml文件以指定 Azure Stack Hub 特定的值。

使用安装程序部署使用安装程序预配的基础架构的集群时,您可以选择azure,但此选项仅支持 Azure 公有云。

先决条件

上传 RHCOS 集群镜像

您必须下载 RHCOS 虚拟硬盘 (VHD) 集群镜像并将其上传到您的 Azure Stack Hub 环境,以便在部署期间可以访问它。

先决条件
  • 为您的集群生成 Ignition 配置文件。

步骤
  1. 获取 RHCOS VHD 集群镜像

    1. 将 RHCOS VHD 的 URL 导出到环境变量。

      $ export COMPRESSED_VHD_URL=$(openshift-install coreos print-stream-json | jq -r '.architectures.x86_64.artifacts.azurestack.formats."vhd.gz".disk.location')
    2. 在本地下载压缩的 RHCOS VHD 文件。

      $ curl -O -L ${COMPRESSED_VHD_URL}
  2. 解压缩 VHD 文件。

    解压缩后的 VHD 文件大小约为 16 GB,请确保您的主机系统至少有 16 GB 的可用空间。上传文件后,可以删除 VHD 文件。

  3. 将本地 VHD 文件上传到 Azure Stack Hub 环境,确保 blob 公开可用。例如,您可以使用 az 命令行界面或 Web 门户将 VHD 文件上传到 blob。

手动创建安装配置文件

安装集群需要您手动创建安装配置文件。

先决条件
  • 您需要在本地机器上有一个 SSH 公钥,提供给安装程序。此密钥将用于 SSH 身份验证,用于调试和灾难恢复集群节点。

  • 您已获得 OpenShift Container Platform 安装程序和集群的拉取密钥。

步骤
  1. 创建一个安装目录来存储所需的安装资源。

    $ mkdir <installation_directory>

    您必须创建一个目录。某些安装资源(如 bootstrap X.509 证书)的有效期较短,因此您不能重复使用安装目录。如果您想重复使用另一个集群安装中的单个文件,可以将它们复制到您的目录中。但是,安装资源的文件名可能会在不同版本之间发生变化。从早期 OpenShift Container Platform 版本复制安装文件时,请谨慎操作。

  2. 自定义提供的示例 install-config.yaml 文件模板,并将其保存到 <installation_directory>

    此配置文件必须命名为 install-config.yaml

    进行以下修改:

    1. 指定所需的安装参数。

    2. 更新 platform.azure 部分以指定 Azure Stack Hub 特定的参数。

    3. 可选:更新一个或多个默认配置参数以自定义安装。

      有关参数的更多信息,请参阅“安装配置参数”。

  3. 备份 install-config.yaml 文件,以便您可以使用它来安装多个集群。

    install-config.yaml 文件在安装过程的下一步中使用。您现在必须备份它。

Azure Stack Hub 的示例自定义 install-config.yaml 文件

您可以自定义 install-config.yaml 文件以指定有关 OpenShift Container Platform 集群平台的更多详细信息,或修改所需参数的值。

此示例 YAML 文件仅供参考。将其用作资源,将参数值输入到您手动创建的安装配置文件中。

apiVersion: v1
baseDomain: example.com (1)
credentialsMode: Manual
controlPlane:  (2) (3)
  name: master
  platform:
    azure:
      osDisk:
        diskSizeGB: 1024 (4)
        diskType: premium_LRS
  replicas: 3
compute: (2)
- name: worker
  platform:
    azure:
      osDisk:
        diskSizeGB: 512 (4)
        diskType: premium_LRS
  replicas: 3
metadata:
  name: test-cluster  (1) (5)
networking:
  clusterNetwork:
  - cidr: 10.128.0.0/14
    hostPrefix: 23
  machineNetwork:
  - cidr: 10.0.0.0/16
  networkType: OVNKubernetes (6)
  serviceNetwork:
  - 172.30.0.0/16
platform:
  azure:
    armEndpoint: azurestack_arm_endpoint  (1) (7)
    baseDomainResourceGroupName: resource_group  (1) (8)
    region: azure_stack_local_region  (1) (9)
    resourceGroupName: existing_resource_group (10)
    outboundType: Loadbalancer
    cloudName: AzureStackCloud (1)
    clusterOSimage: https://vhdsa.blob.example.example.com/vhd/rhcos-410.84.202112040202-0-azurestack.x86_64.vhd  (1) (11)
pullSecret: '{"auths": ...}'  (1) (12)
fips: false (13)
sshKey: ssh-ed25519 AAAA... (14)
additionalTrustBundle: | (15)
    -----BEGIN CERTIFICATE-----
    <MY_TRUSTED_CA_CERT>
    -----END CERTIFICATE-----
1 必需。
2 如果您不提供这些参数和值,安装程序将提供默认值。
3 controlPlane 部分是一个单映射,但 compute 部分是映射序列。为了满足不同数据结构的要求,compute 部分的第一行必须以连字符 - 开头,而 controlPlane 部分的第一行则不能。尽管这两个部分目前都定义了一个单机器池,但 OpenShift Container Platform 的未来版本可能会支持在安装期间定义多个计算池。只使用一个控制平面池。
4 您可以指定要使用的磁盘大小(以 GB 为单位)。控制平面节点的最低建议大小为 1024 GB。
5 集群的名称。
6 要安装的集群网络插件。默认值 OVNKubernetes 是唯一支持的值。
7 您的 Azure Stack Hub 运营商提供的 Azure 资源管理器端点。
8 包含您基本域的 DNS 区域的资源组的名称。
9 您的 Azure Stack Hub 本地区域的名称。
10 要安装集群的现有资源组的名称。如果未定义,则会为集群创建一个新的资源组。
11 Azure Stack 环境中包含 RHCOS VHD 的存储 blob 的 URL。
12 验证您的集群所需的拉取密钥。
13 是否启用或禁用 FIPS 模式。默认情况下,FIPS 模式未启用。如果启用了 FIPS 模式,则运行 OpenShift Container Platform 的 Red Hat Enterprise Linux CoreOS (RHCOS) 机器将绕过默认的 Kubernetes 密码套件,并改为使用 RHCOS 提供的密码模块。

在 FIPS 模式下运行 Red Hat Enterprise Linux (RHEL) 或 Red Hat Enterprise Linux CoreOS (RHCOS) 时,OpenShift Container Platform 核心组件仅在 x86_64、ppc64le 和 s390x 架构上使用已提交给 NIST 用于 FIPS 140-2/140-3 验证的 RHEL 密码库。

14 您可以选择提供用于访问集群中机器的 sshKey 值。

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

15 如果 Azure Stack Hub 环境使用内部证书颁发机构 (CA),则需要添加 CA 证书。

手动管理云凭据

云凭据运营商 (CCO) 仅在手动模式下支持您的云提供商。因此,您必须指定云提供商的身份和访问管理 (IAM) 密钥。

步骤
  1. 如果您之前没有创建安装清单文件,请运行以下命令:

    $ openshift-install create manifests --dir <installation_directory>

    其中 <installation_directory> 是安装程序创建文件的目录。

  2. 通过运行以下命令,设置包含安装文件中的发行版镜像的 $RELEASE_IMAGE 变量:

    $ RELEASE_IMAGE=$(./openshift-install version | awk '/release image/ {print $3}')
  3. 通过运行以下命令,从 OpenShift Container Platform 发行版镜像中提取 CredentialsRequest 自定义资源 (CR) 列表:

    $ oc adm release extract \
      --from=$RELEASE_IMAGE \
      --credentials-requests \
      --included \(1)
      --install-config=<path_to_directory_with_installation_configuration>/install-config.yaml \(2)
      --to=<path_to_directory_for_credentials_requests> (3)
    1 --included 参数仅包含特定集群配置所需的清单。
    2 指定 install-config.yaml 文件的位置。
    3 指定要存储 CredentialsRequest 对象的目录的路径。如果指定的目录不存在,此命令将创建它。

    此命令将为每个 CredentialsRequest 对象创建一个 YAML 文件。

    CredentialsRequest 对象示例
    apiVersion: cloudcredential.openshift.io/v1
    kind: CredentialsRequest
    metadata:
      name: <component_credentials_request>
      namespace: openshift-cloud-credential-operator
      ...
    spec:
      providerSpec:
        apiVersion: cloudcredential.openshift.io/v1
        kind: AzureProviderSpec
        roleBindings:
        - role: Contributor
      ...
  4. 为之前生成的 openshift-install 清单目录中的密钥创建 YAML 文件。必须使用每个 CredentialsRequest 对象的 spec.secretRef 中定义的命名空间和密钥名称来存储密钥。

    包含密钥的 CredentialsRequest 对象示例
    apiVersion: cloudcredential.openshift.io/v1
    kind: CredentialsRequest
    metadata:
      name: <component_credentials_request>
      namespace: openshift-cloud-credential-operator
      ...
    spec:
      providerSpec:
        apiVersion: cloudcredential.openshift.io/v1
        kind: AzureProviderSpec
        roleBindings:
        - role: Contributor
          ...
      secretRef:
        name: <component_secret>
        namespace: <component_namespace>
      ...
    Secret 对象示例
    apiVersion: v1
    kind: Secret
    metadata:
      name: <component_secret>
      namespace: <component_namespace>
    data:
      azure_subscription_id: <base64_encoded_azure_subscription_id>
      azure_client_id: <base64_encoded_azure_client_id>
      azure_client_secret: <base64_encoded_azure_client_secret>
      azure_tenant_id: <base64_encoded_azure_tenant_id>
      azure_resource_prefix: <base64_encoded_azure_resource_prefix>
      azure_resourcegroup: <base64_encoded_azure_resourcegroup>
      azure_region: <base64_encoded_azure_region>

在升级使用手动维护的凭据的集群之前,您必须确保 CCO 处于可升级状态。

配置集群以使用内部 CA

如果 Azure Stack Hub 环境使用内部证书颁发机构 (CA),请更新 cluster-proxy-01-config.yaml 文件以配置集群以使用内部 CA。

先决条件
  • 创建 install-config.yaml 文件,并指定 .pem 格式的证书信任捆绑包。

  • 创建集群清单。

步骤
  1. 从安装程序创建文件的目录转到 manifests 目录。

  2. user-ca-bundle 添加到 spec.trustedCA.name 字段。

    cluster-proxy-01-config.yaml 文件示例
    apiVersion: config.openshift.io/v1
    kind: Proxy
    metadata:
      creationTimestamp: null
      name: cluster
    spec:
      trustedCA:
        name: user-ca-bundle
    status: {}
  3. 可选:备份 manifests/cluster-proxy-01-config.yaml 文件。当您部署集群时,安装程序将使用 manifests/ 目录。

部署集群

您可以在兼容的云平台上安装 OpenShift Container Platform。

您只能在初始安装期间运行安装程序的 create cluster 命令一次。

先决条件
  • 您已配置了一个帐户,该帐户具有托管集群的云平台的权限。

  • 您已获得 OpenShift Container Platform 安装程序和集群的拉取密钥。

  • 您已验证主机上的云提供商帐户具有部署集群的正确权限。权限不正确的帐户会导致安装过程失败,并显示一条显示缺少权限的错误消息。

步骤
  • 切换到包含安装程序的目录并初始化集群部署

    $ ./openshift-install create cluster --dir <installation_directory> \ (1)
        --log-level=info (2)
    
    1 对于<installation_directory>,请指定您自定义的./install-config.yaml文件的位置。
    2 要查看不同的安装详细信息,请指定warndebugerror代替info
验证

集群部署成功完成时

  • 终端会显示访问集群的说明,包括指向 Web 控制台的链接以及kubeadmin用户的凭据。

  • 凭据信息也会输出到<installation_directory>/.openshift_install.log

请勿删除安装程序或安装程序创建的文件。两者都是删除集群所必需的。

示例输出
...
INFO Install complete!
INFO To access the cluster as the system:admin user when using 'oc', run 'export KUBECONFIG=/home/myuser/install_dir/auth/kubeconfig'
INFO Access the OpenShift web-console here: https://console-openshift-console.apps.mycluster.example.com
INFO Login to the console with user: "kubeadmin", and password: "password"
INFO Time elapsed: 36m22s
  • 安装程序生成的 Ignition 配置文件包含 24 小时后过期的证书,届时会续订这些证书。如果在续订证书之前集群关闭,并且 24 小时后集群重新启动,则集群会自动恢复过期的证书。例外情况是,您必须手动批准挂起的node-bootstrapper证书签名请求 (CSR) 以恢复 kubelet 证书。有关更多信息,请参阅有关 *从过期的控制平面证书中恢复* 的文档。

  • 建议您在生成 Ignition 配置文件后 12 小时内使用它们,因为在集群安装后 16 到 22 小时之间会进行 24 小时证书轮换。在 12 小时内使用 Ignition 配置文件,可以避免在安装过程中运行证书更新时安装失败。

使用 CLI 登录集群

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

先决条件
  • 您已部署 OpenShift Container Platform 集群。

  • 您已安装oc CLI。

步骤
  1. 导出kubeadmin凭据

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

    $ oc whoami
    示例输出
    system:admin

使用 Web 控制台登录集群

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

先决条件
  • 您可以访问安装主机。

  • 您已完成集群安装,并且所有集群 Operators 都可用。

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

    $ cat <installation_directory>/auth/kubeadmin-password

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

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

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

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

    示例输出
    console     console-openshift-console.apps.<cluster_name>.<base_domain>            console     https   reencrypt/Redirect   None
  3. 在 Web 浏览器中导航到前面命令输出中详细说明的路由,并以kubeadmin用户身份登录。

其他资源