
// Module included in the following assemblies:
//
// * networking/external_dns_operator/nw-creating-dns-records-on-gcp.adoc

:_mod-docs-content-type: PROCEDURE
[id="nw-control-dns-records-public-managed-zone-gcp_{context}"]
= Creating DNS records on a public managed zone for {gcp-short}

[role="_abstract"]
To create DNS records on {gcp-first}, use the External DNS Operator. The DNS Operator manages external name resolution for your cluster services.

.Prerequisites

* You must have administrator privileges.

.Procedure

. Copy the `gcp-credentials` secret in the `encoded-gcloud.json` file by running the following command:
+
[source,terminal]
----
$ oc get secret gcp-credentials -n kube-system --template='{{$v := index .data "service_account.json"}}{{$v}}' | base64 -d - > decoded-gcloud.json
----

. Export your Google credentials by running the following command:
+
[source,terminal]
----
$ export GOOGLE_CREDENTIALS=decoded-gcloud.json
----

. Activate your account by using the following command:
+
[source,terminal]
----
$ gcloud auth activate-service-account  <client_email as per decoded-gcloud.json> --key-file=decoded-gcloud.json
----

. Set your project by running the following command:
+
[source,terminal]
----
$ gcloud config set project <project_id as per decoded-gcloud.json>
----

. Get a list of routes by running the following command:
+
[source,terminal]
----
$ oc get routes --all-namespaces | grep console
----
+
.Example output
[source,terminal]
----
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
----

. Get a list of managed zones, such as `qe-cvs4g-private-zone test.gcp.example.com`, by running the following command:
+
[source,terminal]
----
$ gcloud dns managed-zones list | grep test.gcp.example.com
----

. Create a YAML file, for example, `external-dns-sample-gcp.yaml`, that defines the `ExternalDNS` object:
+
.Example `external-dns-sample-gcp.yaml` file
[source,yaml]
----
apiVersion: externaldns.olm.openshift.io/v1beta1
kind: ExternalDNS
metadata:
  name: sample-gcp
spec:
  domains:
    - filterType: Include
      matchType: Exact
      name: test.gcp.example.com
  provider:
    type: GCP
  source:
    openshiftRouteOptions:
      routerName: default
    type: OpenShiftRoute
# ...
----
+
where:

`metadata.name`:: Specifies the External DNS name.

`spec.domains.filterType`:: By default, all hosted zones are selected as potential targets. You can include your hosted zone.

`spec.domains.matchType`:: Specifies the domain of the target that must match the string defined by the `name` key.

`spec.domains.name`:: Specifies the exact domain of the zone you want to update. The hostname of the routes must be subdomains of the specified domain.

`spec.provider.type`:: Specifies the provider type.

`source.openshiftRouteOptions`:: Specifies options for the source of DNS records.

`openshiftRouteOptions.routerName`:: If the source type is `OpenShiftRoute`, you can pass the OpenShift Ingress Controller name. External DNS selects the canonical hostname of that router as the target while creating a CNAME record.

`type`:: Specifies the `route` resource as the source for {gcp-short} DNS records.

. Check the DNS records created for {product-title} routes by running the following command:
+
[source,terminal]
----
$ gcloud dns record-sets list --zone=qe-cvs4g-private-zone | grep console
----
