19.6. 在 GCP 上创建 DNS 记录

您可以使用外部 DNS Operator 在 GCP 上创建 DNS 记录。

19.6.1. 在 GCP 公共管理区上创建 DNS 记录

您可以使用 External DNS Operator 在 GCP 公共受管区上创建 DNS 记录。

先决条件

  • 您必须具有管理员特权。

流程

  1. 运行以下命令,将 gcp-credentials secret 复制到 encoded-gcloud.json 文件中:

    $ oc get secret gcp-credentials -n kube-system --template='{{$v := index .data "service_account.json"}}{{$v}}' | base64 -d - > decoded-gcloud.json
  2. 运行以下命令导出 Google 凭证:

    $ export GOOGLE_CREDENTIALS=decoded-gcloud.json
  3. 使用以下命令激活您的帐户:

    $ gcloud auth activate-service-account  <client_email as per decoded-gcloud.json> --key-file=decoded-gcloud.json
  4. 运行以下命令来设置项目:

    $ gcloud config set project <project_id as per decoded-gcloud.json>
  5. 运行以下命令来获取路由列表:

    $ oc get routes --all-namespaces | grep console

    输出示例

    openshift-console          console             console-openshift-console.apps.test.gcp.example.com                       console             https   reencrypt/Redirect     None
    openshift-console          downloads           downloads-openshift-console.apps.test.gcp.example.com                     downloads           http    edge/Redirect          None

  6. 运行以下命令来获取受管区列表:

    $ gcloud dns managed-zones list | grep test.gcp.example.com

    输出示例

    qe-cvs4g-private-zone test.gcp.example.com

  7. 创建一个 YAML 文件,如 external-dns-sample-gcp.yaml,该文件定义 ExternalDNS 对象:

    external-dns-sample-gcp.yaml 文件示例

    apiVersion: externaldns.olm.openshift.io/v1beta1
    kind: ExternalDNS
    metadata:
      name: sample-gcp 1
    spec:
      domains:
        - filterType: Include 2
          matchType: Exact 3
          name: test.gcp.example.com 4
      provider:
        type: GCP 5
      source:
        openshiftRouteOptions: 6
          routerName: default 7
        type: OpenShiftRoute 8

    1
    指定外部 DNS 名称。
    2
    默认情况下,所有托管区都被选为潜在的目标。您可以包含托管区。
    3
    目标的域必须与 name 键定义的字符串匹配。
    4
    指定您要更新的区域的确切域。路由的主机名必须是指定域的子域。
    5
    定义提供程序类型。
    6
    您可以定义 DNS 记录源的选项。
    7
    如果源类型是 OpenShiftRoute,您可以传递 OpenShift Ingress Controller 名称。外部 DNS 在创建 CNAME 记录时,选择该路由器的规范主机名作为目标。
    8
    route 资源定义为 GCP DNS 记录的源。
  8. 运行以下命令,检查为 OpenShift Container Platform 路由创建的 DNS 记录:

    $ gcloud dns record-sets list --zone=qe-cvs4g-private-zone | grep console