1.4. 通过入口对象保护路由


您可以通过直接通过入口对象管理证书来保护应用程序流量。这包括在 ingress 注解或使用默认证书中使用目标 CA 证书创建路由。

警告

Ingress Controller 为通过入口对象管理的证书维护单向同步。不要手动将更改直接应用到生成的路由的 TLS 配置。在下一次更新或协调父入口对象时,任何手动修改都会被静默覆盖。当您运行 GitOps 管理的集群时,这尤其要注意。

要使用自定义目标 CA 证书定义路由,请将 route.openshift.io/destination-ca-certificate-secret 注解应用到 Ingress 对象。此配置可确保 Ingress Controller 使用指定的 secret 来验证目标服务的身份。

先决条件

  • 在 PEM 编码文件中有一个证书/密钥对,其中的证书对路由主机有效。
  • 在 PEM 编码文件中有一个单独的 CA 证书来完成证书链。
  • 在 PEM 编码文件中有一个单独的目标 CA 证书。
  • 您有一个要公开的服务。

流程

  1. 输入以下命令为目标 CA 证书创建 secret:

    $ oc create secret generic dest-ca-cert --from-file=tls.crt=<file_path>

    例如:

    $ oc -n test-ns create secret generic dest-ca-cert --from-file=tls.crt=tls.crt

    输出示例

    secret/dest-ca-cert created

  2. route.openshift.io/destination-ca-certificate-secret 添加到 Ingress 注解中:

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: frontend
      annotations:
        route.openshift.io/termination: "reencrypt"
        route.openshift.io/destination-ca-certificate-secret: secret-ca-cert
    ...

    其中:

    destination-ca-certificate-secret

    指定 route.openshift.io/destination-ca-certificate-secret 注解。该注解引用 Kubernetes secret。

    Ingress Controller 将注解中引用的 secret 插入到生成的路由中。

    输出示例

    apiVersion: route.openshift.io/v1
    kind: Route
    metadata:
      name: frontend
      annotations:
        route.openshift.io/termination: reencrypt
        route.openshift.io/destination-ca-certificate-secret: secret-ca-cert
    spec:
    ...
      tls:
        insecureEdgeTerminationPolicy: Redirect
        termination: reencrypt
        destinationCACertificate: |
          -----BEGIN CERTIFICATE-----
          [...]
          -----END CERTIFICATE-----
    ...

Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

關於紅帽

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

让开源更具包容性

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

关于红帽文档

Legal Notice

Theme

© 2026 Red Hat
返回顶部