5.5. 使用 DNS 转发

您可以针对一个区(zone),使用 DNS 转发来覆盖 /etc/resolv.conf 中指定的转发配置,方法是指定这个区使用哪个名称解析服务器。如果转发区是 OpenShift Container Platform 管理的 Ingress 域,那么上游名称服务器必须为域授权。

流程

  1. 修改名为 default 的 DNS Operator 对象:

    $ oc edit dns.operator/default

    这允许 Operator 使用基于 Server 的额外服务器配置块来创建和更新名为 dns-default 的 ConfigMap。如果没有服务器带有与查询匹配的区,则命名解析功能会返回到由 /etc/resolv.conf中指定的名称服务器。

    DNS 示例

    apiVersion: operator.openshift.io/v1
    kind: DNS
    metadata:
      name: default
    spec:
      servers:
      - name: foo-server 1
        zones: 2
          - example.com
        forwardPlugin:
          upstreams: 3
            - 1.1.1.1
            - 2.2.2.2:5353
      - name: bar-server
        zones:
          - bar.com
          - example.com
        forwardPlugin:
          upstreams:
            - 3.3.3.3
            - 4.4.4.4:5454

    1
    name 必须符合 rfc6335 服务名称的语法。
    2
    zones 必须符合 rfc1123 中的一个 subdomain 的定义。集群域 cluster.local 不是 zones 中的一个有效的 subdomain
    3
    每个 forwardPlugin 最多允许 15 个 upstreams
    注意

    如果 servers 未定义或无效,则 ConfigMap 只包括默认服务器。

  2. 查看 ConfigMap:

    $ oc get configmap/dns-default -n openshift-dns -o yaml

    基于以上 DNS 示例的 DNS ConfigMap 示例

    apiVersion: v1
    data:
      Corefile: |
        example.com:5353 {
            forward . 1.1.1.1 2.2.2.2:5353
        }
        bar.com:5353 example.com:5353 {
            forward . 3.3.3.3 4.4.4.4:5454 1
        }
        .:5353 {
            errors
            health
            kubernetes cluster.local in-addr.arpa ip6.arpa {
                pods insecure
                upstream
                fallthrough in-addr.arpa ip6.arpa
            }
            prometheus :9153
            forward . /etc/resolv.conf {
                policy sequential
            }
            cache 30
            reload
        }
    kind: ConfigMap
    metadata:
      labels:
        dns.operator.openshift.io/owning-dns: default
      name: dns-default
      namespace: openshift-dns

    1
    forwardPlugin 的更改会触发 CoreDNS 守护进程集的滚动更新。

其他资源