5.7. 用户置备的 DNS 要求
在 OpenShift Container Platform 部署中,以下组件需要 DNS 名称解析:
- The Kubernetes API
- OpenShift Container Platform 应用程序通配符
- bootstrap、control plane 和计算机器
Kubernetes API、bootstrap 机器、control plane 机器和计算机器也需要反向 DNS 解析。
DNS A/AAAA 或 CNAME 记录用于名称解析,PTR 记录用于反向名称解析。反向记录很重要,因为 Red Hat Enterprise Linux CoreOS(RHCOS)使用反向记录为所有节点设置主机名,除非 DHCP 提供主机名。另外,反向记录用于生成 OpenShift Container Platform 需要操作的证书签名请求(CSR)。
建议使用 DHCP 服务器为每个群集节点提供主机名。如需更多信息,请参阅用户置备的基础架构部分的 DHCP 建议。
用户置备的 OpenShift Container Platform 集群需要以下 DNS 记录,这些记录必须在安装前就位。在每个记录中,<cluster_name>
是集群名称,<base_domain>
是您在 install-config.yaml
文件中指定的基域。完整的 DNS 记录采用以下形式: <component>.<cluster_name>.<base_domain>.
。
组件 | 记录 | 描述 |
---|---|---|
Kubernetes API |
| DNS A/AAAA 或 CNAME 记录,以及用于标识 API 负载均衡器的 DNS PTR 记录。这些记录必须由集群外的客户端和集群中的所有节点解析。 |
| DNS A/AAAA 或 CNAME 记录,以及用于内部标识 API 负载均衡器的 DNS PTR 记录。这些记录必须可以从集群中的所有节点解析。 重要 API 服务器必须能够根据 Kubernetes 中记录的主机名解析 worker 节点。如果 API 服务器无法解析节点名称,则代理的 API 调用会失败,且您无法从 pod 检索日志。 | |
Routes |
| 通配符 DNS A/AAAA 或 CNAME 记录,指向应用程序入口负载均衡器。应用程序入口负载均衡器以运行 Ingress Controller Pod 的机器为目标。默认情况下,Ingress Controller Pod 在计算机器上运行。这些记录必须由集群外的客户端和集群中的所有节点解析。
例如,console |
bootstrap 机器 |
| DNS A/AAAA 或 CNAME 记录,以及用于标识 bootstrap 机器的 DNS PTR 记录。这些记录必须由集群中的节点解析。 |
control plane 机器 |
| DNS A/AAAA 或 CNAME 记录,以识别 control plane 节点的每台机器。这些记录必须由集群中的节点解析。 |
计算机器 |
| DNS A/AAAA 或 CNAME 记录,用于识别 worker 节点的每台机器。这些记录必须由集群中的节点解析。 |
在 OpenShift Container Platform 4.4 及更新的版本中,您不需要在 DNS 配置中指定 etcd 主机和 SRV 记录。
您可以使用 dig
命令验证名称和反向名称解析。如需了解详细的 验证步骤,请参阅为用户置备的基础架构验证 DNS 解析 一节。
5.7.1. 用户置备的集群的 DNS 配置示例
本节提供 A 和 PTR 记录配置示例,它们满足了在用户置备的基础架构上部署 OpenShift Container Platform 的 DNS 要求。样本不是为选择一个 DNS 解决方案提供建议。
在这个示例中,集群名称为 ocp4
,基域是 example.com
。
用户置备的集群的 DNS A 记录配置示例
以下示例是 BIND 区域文件,其中显示了用户置备的集群中名称解析的 A 记录示例。
例 5.1. DNS 区数据库示例
$TTL 1W @ IN SOA ns1.example.com. root ( 2019070700 ; serial 3H ; refresh (3 hours) 30M ; retry (30 minutes) 2W ; expiry (2 weeks) 1W ) ; minimum (1 week) IN NS ns1.example.com. IN MX 10 smtp.example.com. ; ; ns1.example.com. IN A 192.168.1.5 smtp.example.com. IN A 192.168.1.5 ; helper.example.com. IN A 192.168.1.5 helper.ocp4.example.com. IN A 192.168.1.5 ; api.ocp4.example.com. IN A 192.168.1.5 1 api-int.ocp4.example.com. IN A 192.168.1.5 2 ; *.apps.ocp4.example.com. IN A 192.168.1.5 3 ; bootstrap.ocp4.example.com. IN A 192.168.1.96 4 ; control-plane0.ocp4.example.com. IN A 192.168.1.97 5 control-plane1.ocp4.example.com. IN A 192.168.1.98 6 control-plane2.ocp4.example.com. IN A 192.168.1.99 7 ; compute0.ocp4.example.com. IN A 192.168.1.11 8 compute1.ocp4.example.com. IN A 192.168.1.7 9 ; ;EOF
- 1
- 为 Kubernetes API 提供名称解析。记录引用 API 负载均衡器的 IP 地址。
- 2
- 为 Kubernetes API 提供名称解析。记录引用 API 负载均衡器的 IP 地址,用于内部集群通信。
- 3
- 为通配符路由提供名称解析。记录引用应用程序入口负载均衡器的 IP 地址。应用程序入口负载均衡器以运行 Ingress Controller Pod 的机器为目标。默认情况下,Ingress Controller Pod 在计算机器上运行。注意
在这个示例中,将相同的负载均衡器用于 Kubernetes API 和应用入口流量。在生产环境中,您可以单独部署 API 和应用程序入口负载均衡器,以便可以隔离扩展每个负载均衡器基础架构。
- 4
- 为 bootstrap 机器提供名称解析。
- 5 6 7
- 为 control plane 机器提供名称解析。
- 8 9
- 为计算机器提供名称解析。
用户置备的集群的 DNS PTR 记录配置示例
以下示例 BIND 区域文件显示了用户置备的集群中反向名称解析的 PTR 记录示例。
例 5.2. 反向记录的 DNS 区数据库示例
$TTL 1W @ IN SOA ns1.example.com. root ( 2019070700 ; serial 3H ; refresh (3 hours) 30M ; retry (30 minutes) 2W ; expiry (2 weeks) 1W ) ; minimum (1 week) IN NS ns1.example.com. ; 5.1.168.192.in-addr.arpa. IN PTR api.ocp4.example.com. 1 5.1.168.192.in-addr.arpa. IN PTR api-int.ocp4.example.com. 2 ; 96.1.168.192.in-addr.arpa. IN PTR bootstrap.ocp4.example.com. 3 ; 97.1.168.192.in-addr.arpa. IN PTR control-plane0.ocp4.example.com. 4 98.1.168.192.in-addr.arpa. IN PTR control-plane1.ocp4.example.com. 5 99.1.168.192.in-addr.arpa. IN PTR control-plane2.ocp4.example.com. 6 ; 11.1.168.192.in-addr.arpa. IN PTR compute0.ocp4.example.com. 7 7.1.168.192.in-addr.arpa. IN PTR compute1.ocp4.example.com. 8 ; ;EOF
OpenShift Container Platform 应用程序通配符不需要 PTR 记录。
5.7.2. 用户置备的基础架构的负载均衡要求
在安装 OpenShift Container Platform 前,您必须置备 API 和应用程序入口负载均衡基础架构。在生产环境中,您可以单独部署 API 和应用程序入口负载均衡器,以便可以隔离扩展每个负载均衡器基础架构。
如果要使用 Red Hat Enterprise Linux (RHEL) 实例部署 API 和应用程序入口负载均衡器,您必须单独购买 RHEL 订阅。
负载平衡基础架构必须满足以下要求:
API 负载均衡器 :提供一个通用端点,供用户(包括人工和机器)与平台交互和配置。配置以下条件:
- 仅第 4 层负载均衡.这可被称为 Raw TCP 或 SSL Passthrough 模式。
- 无状态负载平衡算法。这些选项根据负载均衡器的实施而有所不同。
重要不要为 API 负载均衡器配置会话持久性。为 Kubernetes API 服务器配置会话持久性可能会导致出现过量 OpenShift Container Platform 集群应用程序流量,以及过量的在集群中运行的 Kubernetes API。
在负载均衡器的前端和后端配置以下端口:
表 5.5. API 负载均衡器 port 后端机器(池成员) internal 外部 描述 6443
Bootstrap 和 control plane.bootstrap 机器初始化集群 control plane 后,您要从负载均衡器中删除 bootstrap 机器。您必须为 API 服务器健康检查探测配置
/readyz
端点。X
X
Kubernetes API 服务器
22623
Bootstrap 和 control plane.bootstrap 机器初始化集群 control plane 后,您要从负载均衡器中删除 bootstrap 机器。
X
机器配置服务器
注意负载均衡器必须配置为,从 API 服务器关闭
/readyz
端点到从池中移除 API 服务器实例时最多需要 30 秒。在/readyz
返回错误或健康后的时间范围内,端点必须被删除或添加。每 5 秒或 10 秒探测一次,有两个成功请求处于健康状态,三个成为不健康的请求是经过良好测试的值。应用程序入口负载均衡器 :为应用程序流量从集群外部流提供入口点。OpenShift Container Platform 集群需要正确配置入口路由器。
配置以下条件:
- 仅第 4 层负载均衡.这可被称为 Raw TCP 或 SSL Passthrough 模式。
- 建议根据可用选项以及平台上托管的应用程序类型,使用基于连接的或基于会话的持久性。
提示如果应用程序入口负载均衡器可以看到客户端的真实 IP 地址,启用基于 IP 的会话持久性可以提高使用端到端 TLS 加密的应用程序的性能。
在负载均衡器的前端和后端配置以下端口:
表 5.6. 应用程序入口负载均衡器 port 后端机器(池成员) internal 外部 描述 443
默认情况下,运行 Ingress Controller Pod、计算或 worker 的机器。
X
X
HTTPS 流量
80
默认情况下,运行 Ingress Controller Pod、计算或 worker 的机器。
X
X
HTTP 流量
注意如果要部署一个带有零计算节点的三节点集群,Ingress Controller Pod 在 control plane 节点上运行。在三节点集群部署中,您必须配置应用程序入口负载均衡器,将 HTTP 和 HTTPS 流量路由到 control plane 节点。
5.7.2.1. 用户置备的集群的负载均衡器配置示例
本节提供了一个满足用户置备集群的负载均衡要求的 API 和应用程序入口负载均衡器配置示例。示例是 HAProxy 负载均衡器的 /etc/haproxy/haproxy.cfg
配置。这个示例不是为选择一个负载平衡解决方案提供建议。
在这个示例中,将相同的负载均衡器用于 Kubernetes API 和应用入口流量。在生产环境中,您可以单独部署 API 和应用程序入口负载均衡器,以便可以隔离扩展每个负载均衡器基础架构。
如果您使用 HAProxy 作为负载均衡器,并且 SELinux 设置为 enforcing
,您必须通过运行 setsebool -P haproxy_connect_any=1
来确保 HAProxy 服务可以绑定到配置的 TCP 端口。
例 5.3. API 和应用程序入口负载均衡器配置示例
global log 127.0.0.1 local2 pidfile /var/run/haproxy.pid maxconn 4000 daemon defaults mode http log global option dontlognull option http-server-close option redispatch retries 3 timeout http-request 10s timeout queue 1m timeout connect 10s timeout client 1m timeout server 1m timeout http-keep-alive 10s timeout check 10s maxconn 3000 listen api-server-6443 1 bind *:6443 mode tcp option httpchk GET /readyz HTTP/1.0 option log-health-checks balance roundrobin server bootstrap bootstrap.ocp4.example.com:6443 verify none check check-ssl inter 10s fall 2 rise 3 backup 2 server master0 master0.ocp4.example.com:6443 weight 1 verify none check check-ssl inter 10s fall 2 rise 3 server master1 master1.ocp4.example.com:6443 weight 1 verify none check check-ssl inter 10s fall 2 rise 3 server master2 master2.ocp4.example.com:6443 weight 1 verify none check check-ssl inter 10s fall 2 rise 3 listen machine-config-server-22623 3 bind *:22623 mode tcp server bootstrap bootstrap.ocp4.example.com:22623 check inter 1s backup 4 server master0 master0.ocp4.example.com:22623 check inter 1s server master1 master1.ocp4.example.com:22623 check inter 1s server master2 master2.ocp4.example.com:22623 check inter 1s listen ingress-router-443 5 bind *:443 mode tcp balance source server worker0 worker0.ocp4.example.com:443 check inter 1s server worker1 worker1.ocp4.example.com:443 check inter 1s listen ingress-router-80 6 bind *:80 mode tcp balance source server worker0 worker0.ocp4.example.com:80 check inter 1s server worker1 worker1.ocp4.example.com:80 check inter 1s
- 1
- 端口
6443
处理 Kubernetes API 流量并指向 control plane 机器。 - 2 4
- bootstrap 条目必须在 OpenShift Container Platform 集群安装前就位,且必须在 bootstrap 过程完成后删除它们。
- 3
- 端口
22623
处理机器配置服务器流量并指向 control plane 机器。 - 5
- 端口
443
处理 HTTPS 流量,并指向运行 Ingress Controller pod 的机器。默认情况下,Ingress Controller Pod 在计算机器上运行。 - 6
- 端口
80
处理 HTTP 流量,并指向运行 Ingress Controller pod 的机器。默认情况下,Ingress Controller Pod 在计算机器上运行。注意如果要部署一个带有零计算节点的三节点集群,Ingress Controller Pod 在 control plane 节点上运行。在三节点集群部署中,您必须配置应用程序入口负载均衡器,将 HTTP 和 HTTPS 流量路由到 control plane 节点。
如果您使用 HAProxy 作为负载均衡器,您可以通过在 HAProxy 节点上运行 netstat -nltupe
来检查 haproxy
进程是否在侦听端口 6443
、22623
、443
和 80
。