教程


OpenShift Dedicated 4

OpenShift Dedicated 教程

Red Hat OpenShift Documentation Team

摘要

管理 OpenShift Dedicated 集群的教程。

第 1 章 教程概述

使用红帽专家的逐步教程,充分利用您的受管 OpenShift 集群。

重要

此内容由红帽专家编写,但尚未测试每个支持的配置。

本指南演示了如何修改 Google Cloud Platform (GCP)版本 4.14 及更高版本上的 OpenShift Dedicated 中的 Web 控制台、OAuth 服务器和下载组件路由的主机名和 TLS 证书。[1]

对组件路由所做的更改[2] 在本指南中,请参阅 自定义内部 OAuth 服务器 URL自定义控制台路由以及自定义 下载路由 OpenShift Dedicated 文档。

2.1. 先决条件

  • OCM CLI (ocm)版本 1.0.5 或更高版本
  • gcloud CLI (gcloud)
  • Google Cloud Platform (GCP)集群版本 4.14 或更高版本上的 OpenShift Dedicated
  • OpenShift CLI (oc)
  • jq CLI
  • 使用具有 cluster-admin 角色的用户访问集群。
  • openssl (用于生成演示 SSL/TLS 证书)

2.2. 设置您的环境

  1. 使用具有 cluster-admin 权限的账户登录集群。
  2. 为集群名称配置环境变量:

    $ export CLUSTER_NAME=$(oc get infrastructure cluster -o=jsonpath="{.status.infrastructureName}"  | sed 's/-[a-z0-9]\{5\}$//')
    Copy to Clipboard Toggle word wrap
  3. 在移至下一部分前,确保所有字段都正确输出:

    $ echo "Cluster: ${CLUSTER_NAME}"
    Copy to Clipboard Toggle word wrap

    输出示例

    Cluster: my-osd-cluster
    Copy to Clipboard Toggle word wrap

2.3. 查找当前路由

  1. 验证您是否可以访问其默认主机名上的组件路由。

    您可以通过查询 openshift-consoleopenshift-authentication 项目中的路由列表来查找主机名。

    $ oc get routes -n openshift-console
    $ oc get routes -n openshift-authentication
    Copy to Clipboard Toggle word wrap

    输出示例

    NAME        HOST/PORT                                                                          PATH       SERVICES    PORT    TERMINATION          WILDCARD
    console     console-openshift-console.apps.my-example-cluster-gcp.z9a9.p2.openshiftapps.com    ... 1 more  console    https   reencrypt/Redirect   None
    downloads   downloads-openshift-console.apps.my-example-cluster-gcp.z9a9.p2.openshiftapps.com  ... 1 more  downloads  http    edge/Redirect        None
    NAME              HOST/PORT                                                             PATH        SERVICES          PORT   TERMINATION            WILDCARD
    oauth-openshift   oauth-openshift.apps.my-example-cluster-gcp.z9a9.p2.openshiftapps.com ... 1 more  oauth-openshift   6443   passthrough/Redirect   None
    Copy to Clipboard Toggle word wrap

    在这个输出中,您可以看到我们的基本主机名为 z9a9.p2.openshiftapps.com

  2. 运行以下命令,获取默认入口的 ID:

    $ export INGRESS_ID=$(ocm list ingress -c ${CLUSTER_NAME} -o json | jq -r '.[] | select(.default == true) | .id')
    Copy to Clipboard Toggle word wrap
  3. 在移至下一部分前,确保所有字段都正确输出:

    $ echo "Ingress ID: ${INGRESS_ID}"
    Copy to Clipboard Toggle word wrap

    输出示例

    Ingress ID: r3l6
    Copy to Clipboard Toggle word wrap

    通过运行这些命令,您可以看到集群的默认组件路由是:

    • console-openshift-console.apps.my-example-cluster-gcp.z9a9.p2.openshiftapps.com for Console
    • downloads-openshift-console.apps.my-example-cluster-gcp.z9a9.p2.openshiftapps.com for Downloads
    • oauth-openshift.apps.my-example-cluster-gcp.z9a9.p2.openshiftapps.com for OAuth

我们可以使用 ocm edit ingress 命令更改每个服务的主机名,并为我们的所有组件路由添加一个 TLS 证书。ocm edit ingress 命令的命令行帮助摘录中显示了相关的参数:

$ ocm edit ingress -h
Edit a cluster ingress for a cluster. Usage:
  ocm edit ingress ID [flags]
  [...]
  --component-routes string                Component routes settings. Available keys [oauth, console, downloads]. For each key a pair of hostname and tlsSecretRef is expected to be supplied. Format should be a comma separate list 'oauth: hostname=example-hostname;tlsSecretRef=example-secret-ref,downloads:...'
Copy to Clipboard Toggle word wrap

在本例中,我们将使用以下自定义组件路由:

  • Console 的 console.my-new-domain.dev
  • download.my-new-domain.dev for Downloads
  • oauth.my-new-domain.dev for OAuth

2.4. 为每个组件路由创建有效的 TLS 证书

在本节中,我们创建三个单独的自签名证书密钥对,然后信任它们,以使用真实的 Web 浏览器访问我们的新组件路由。

警告

这仅用于演示目的,不建议将其作为生产工作负载的解决方案。请参考您的证书颁发机构了解如何为生产工作负载创建具有类似属性的证书。

重要

要防止 HTTP/2 连接合并出现问题,您必须为每个端点使用单独的证书。不支持使用通配符或 SAN 证书。

  • 为每个组件路由生成一个证书,注意将证书的主题(-subj)设置为您要使用的组件路由的自定义域:

    Example

    $ openssl req -newkey rsa:2048 -new -nodes -x509 -days 365 -keyout key-console.pem -out cert-console.pem -subj "/CN=console.my-new-domain.dev"
    $ openssl req -newkey rsa:2048 -new -nodes -x509 -days 365 -keyout key-downloads.pem -out cert-downloads.pem -subj "/CN=downloads.my-new-domain.dev"
    $ openssl req -newkey rsa:2048 -new -nodes -x509 -days 365 -keyout key-oauth.pem -out cert-oauth.pem -subj "/CN=oauth.my-new-domain.dev"
    Copy to Clipboard Toggle word wrap

    这会生成三对 .pem 文件、key-<component>.pemcert-<component>.pem

2.5. 将证书作为 secret 添加到集群中

  • openshift-config 命名空间中创建三个 TLS secret。

    在本指南的稍后更新组件路由时,这些 secret 将成为您的 secret 引用。

    $ oc create secret tls console-tls --cert=cert-console.pem --key=key-console.pem -n openshift-config
    $ oc create secret tls downloads-tls --cert=cert-downloads.pem --key=key-downloads.pem -n openshift-config
    $ oc create secret tls oauth-tls --cert=cert-oauth.pem --key=key-oauth.pem -n openshift-config
    Copy to Clipboard Toggle word wrap

2.6. 在集群中查找负载均衡器的负载均衡器 IP

当您创建集群时,该服务会创建一个负载均衡器,并为该负载均衡器生成负载均衡器 IP。为了为集群创建 DNS 记录,我们需要知道负载均衡器 IP。

您可以通过针对 openshift-ingress 命名空间运行 oc get svc 命令来查找负载均衡器 IP。负载均衡器的负载均衡器 IP 是与 openshift-ingress 命名空间中的 router-default 服务关联的 EXTERNAL-IP

$ oc get svc -n openshift-ingress
NAME            TYPE          CLUSTER-IP     EXTERNAL-IP        PORT(S)                     AGE
router-default  LoadBalancer  172.30.237.88  34.85.169.230      80:31175/TCP,443:31554/TCP  76d
Copy to Clipboard Toggle word wrap

在我们的情形中,负载均衡器 IP 为 34.85.169.230

稍后保存这个值,因为我们需要为新组件路由主机名配置 DNS 记录。

2.7. 在托管供应商中添加组件路由 DNS 记录

在 DNS 设置中创建 A 记录,将域指向 router-default 的负载均衡器的 IP 地址。

2.8. 使用 OCM CLI 更新组件路由和 TLS secret

更新 DNS 记录后,您可以使用 OCM CLI 更改组件路由。

  1. 使用 ocm edit ingress 命令,使用新的基域和与其关联的 secret 引用更新您的默认入口路由,需要小心更新每个组件路由的主机名。

    $ ocm edit ingress -c ${CLUSTER_NAME} ${INGRESS_ID} --component-routes 'console: hostname=console.my-new-domain.dev;tlsSecretRef=console-tls,downloads: hostname=downloads.my-new-domain.dev;tlsSecretRef=downloads-tls,oauth: hostname=oauth.my-new-domain.dev;tlsSecretRef=oauth-tls'
    Copy to Clipboard Toggle word wrap
    注意

    您还可以通过保留您不想更改设置为空字符串的组件路由来只编辑组件路由的子集。例如,如果您只想更改 Console 和 OAuth 服务器主机名和 TLS 证书,您将运行以下命令:

    $ ocm edit ingress -c ${CLUSTER_NAME} ${INGRESS_ID} --component-routes 'console: hostname=console.my-new-domain.dev;tlsSecretRef=console-tls,downloads: hostname="";tlsSecretRef="", oauth: hostname=oauth.my-new-domain.dev;tlsSecretRef=oauth-tls'
    Copy to Clipboard Toggle word wrap
  2. 运行 ocm list ingress 命令来验证您的更改是否成功:

    $ ocm list ingress -c ${CLUSTER_NAME} -ojson | jq ".[] | select(.id == \"${INGRESS_ID}\") | .component_routes"
    Copy to Clipboard Toggle word wrap

    输出示例

    {
      "console": {
        "kind": "ComponentRoute",
        "hostname": "console.my-new-domain.dev",
        "tls_secret_ref": "console-tls"
      },
      "downloads": {
        "kind": "ComponentRoute",
        "hostname": "downloads.my-new-domain.dev",
        "tls_secret_ref": "downloads-tls"
      },
      "oauth": {
        "kind": "ComponentRoute",
        "hostname": "oauth.my-new-domain.dev",
        "tls_secret_ref": "oauth-tls"
      }
    }
    Copy to Clipboard Toggle word wrap

  3. 将您的证书添加到本地系统上的信任存储中,然后确认您可以使用本地 Web 浏览器通过新路由访问组件。

2.9. 使用 OCM CLI 将组件路由重置为默认值

如果要将组件路由重置为默认配置,请运行以下 ocm edit ingress 命令:

$ ocm edit ingress -c ${CLUSTER_NAME} ${INGRESS_ID} --component-routes 'console: hostname="";tlsSecretRef="",downloads: hostname="";tlsSecretRef="", oauth: hostname="";tlsSecretRef=""'
Copy to Clipboard Toggle word wrap


[1] 通常不支持在 4.14 之前的 OpenShift Dedicated OCM 版本上修改这些路由。但是,如果您有一个使用版本 4.13 的集群,可以通过 提交支持问题单,在版本 4.13 集群上启用对此功能的支持
[2] 我们使用术语"组件路由"来指代首次安装 OCM 时提供的 OAuth、控制台和下载路由。

Legal Notice

Copyright © 2025 Red Hat

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.

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat