Red Hat Training

A Red Hat training course is available for OpenShift Container Platform

4.17. 配置自定义证书

OpenShift Container Platform API 和 Web 控制台的公共主机名的自定义服务证书 可以在集群安装过程中部署,并可在清单文件中配置。

注意

为与 publicMasterURL 关联的主机名配置自定义证书,该证书设置为 openshift_master_cluster_public_hostname 参数值。为与 masterURL ( openshift_master_cluster_hostname)关联的主机名使用自定义服务证书会导致 TLS 错误,因为基础架构组件尝试使用内部 masterURL 主机联系主 API。

可使用 openshift_master_named_certificates 集群变量配置证书和密钥文件路径:

openshift_master_named_certificates=[{"certfile": "/path/to/custom1.crt", "keyfile": "/path/to/custom1.key", "cafile": "/path/to/custom-ca1.crt"}]

文件路径对于运行 Ansible 的系统来说必须是本地的。证书会复制到 master 主机,并部署到 /etc/origin/master/named_certificates/ 目录中。

Ansible 检测到证书的 Common NameSubject Alternative Names。在设置 openshift_master_named_certificates 时,可以通过提供 "names" 键来覆盖检测到的名称:

openshift_master_named_certificates=[{"certfile": "/path/to/custom1.crt", "keyfile": "/path/to/custom1.key", "names": ["public-master-host.com"], "cafile": "/path/to/custom-ca1.crt"}]

使用 openshift_master_named_certificates 配置的证书会在 master 上缓存。这意味着每个额外的 Ansible 运行使用不同的证书集合,会导致以前部署的所有证书都保留在 master 主机和 master 配置文件中。

如果要使用提供的值(或无值)覆盖 openshift_master_named_certificates,请指定 openshift_master_overwrite_named_certificates 集群变量:

openshift_master_overwrite_named_certificates=true

如需更完整的示例,请考虑清单文件中的以下集群变量:

openshift_master_cluster_method=native
openshift_master_cluster_hostname=lb-internal.openshift.com
openshift_master_cluster_public_hostname=custom.openshift.com

要覆盖后续 Ansible 运行上的证书,请设置以下参数值:

openshift_master_named_certificates=[{"certfile": "/root/STAR.openshift.com.crt", "keyfile": "/root/STAR.openshift.com.key", "names": ["custom.openshift.com"], "cafile": "/root/ca-file.crt"}]
openshift_master_overwrite_named_certificates=true
重要

cafile 证书在安装过程中或重新部署证书期间导入到 master 上的 ca-bundle.crt 文件中。ca-bundle.crt 文件挂载到在 OpenShift Container Platform 中运行的每个 pod 中。几个 OpenShift Container Platform 组件会在访问 masterPublicURL 端点时自动信任命名的证书。如果在证书参数中省略 cafile 选项,Web 控制台的功能和几个其他组件会减少。