This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.17.2. 创建路由
您可以使用 Web 控制台或 CLI 创建不受保护和安全的路由。
使用 Web 控制台,您可以进入 Routes 页面,在导航的 Applications 部分找到。
点击 Create Route 在项目中创建路由:
图 17.1. 使用 Web 控制台创建路由
使用 CLI 时,以下示例会创建一个不受保护的路由:
oc expose svc/frontend --hostname=www.example.com
$ oc expose svc/frontend --hostname=www.example.com
新路由从服务继承名称,除非您使用 --name
选项指定名称。
上面创建的非安全路由的 YAML 定义
有关使用 CLI 配置路由的详情,请参考 Route Types。
非安全的路由是默认配置,因此最容易设置。但是,安全路由 为连接保持私有提供安全性。要创建使用密钥和证书加密的安全 HTTPS 路由(PEM-format 文件必须单独生成和签名),您可以使用 create route
命令并选择性地提供证书和密钥。
TLS 是 HTTPS 和其他加密协议的 SSL 替代。
oc create route edge --service=frontend \ --cert=${MASTER_CONFIG_DIR}/ca.crt \ --key=${MASTER_CONFIG_DIR}/ca.key \ --ca-cert=${MASTER_CONFIG_DIR}/ca.crt \ --hostname=www.example.com
$ oc create route edge --service=frontend \
--cert=${MASTER_CONFIG_DIR}/ca.crt \
--key=${MASTER_CONFIG_DIR}/ca.key \
--ca-cert=${MASTER_CONFIG_DIR}/ca.crt \
--hostname=www.example.com
上面创建的安全路由的 YAML 定义
目前,不支持密码保护的密钥文件。启动后,HAProxy 会提示输入密码,且无法自动执行此过程。要从密钥文件中删除密码短语,您可以运行以下命令:
openssl rsa -in <passwordProtectedKey.key> -out <new.key>
# openssl rsa -in <passwordProtectedKey.key> -out <new.key>
您可以在不指定密钥和证书的前提下创建安全路由,在这种情况下,路由器的默认证书 将用于 TLS 终止。
OpenShift Container Platform 中的 TLS 终止依赖于 SNI 来提供自定义证书。任何在端口 443 上收到的非SNI 流量都使用 TLS 终止处理,默认证书可能与请求的主机名不匹配,从而导致验证错误。