$ CLIENT_ID=$(oc get secrets azure-credentials -n kube-system --template={{.data.azure_client_id}} | base64 -d)
To create dns records on Microsoft Azure, use the External dns Operator. By using this Operator, you can manage external name resolution for your cluster services.
|
Using the External dns Operator on a Microsoft Entra Workload ID-enabled cluster or a cluster that runs in Microsoft Azure Government (MAG) regions is not supported. |
To create dns records on a public or private dns zone for Azure, use the External dns Operator. The Operator manages external name resolution for your cluster.
You must have administrator privileges.
The admin user must have access to the kube-system namespace.
Fetch the credentials from the kube-system namespace to use the cloud provider client by running the following command:
$ CLIENT_ID=$(oc get secrets azure-credentials -n kube-system --template={{.data.azure_client_id}} | base64 -d)
$ CLIENT_SECRET=$(oc get secrets azure-credentials -n kube-system --template={{.data.azure_client_secret}} | base64 -d)
$ RESOURCE_GROUP=$(oc get secrets azure-credentials -n kube-system --template={{.data.azure_resourcegroup}} | base64 -d)
$ SUBSCRIPTION_ID=$(oc get secrets azure-credentials -n kube-system --template={{.data.azure_subscription_id}} | base64 -d)
$ TENANT_ID=$(oc get secrets azure-credentials -n kube-system --template={{.data.azure_tenant_id}} | base64 -d)
Log in to Azure by running the following command:
$ az login --service-principal -u "${CLIENT_ID}" -p "${CLIENT_SECRET}" --tenant "${TENANT_ID}"
Get a list of routes by running the following command:
$ oc get routes --all-namespaces | grep console
openshift-console console console-openshift-console.apps.test.azure.example.com console https reencrypt/Redirect None
openshift-console downloads downloads-openshift-console.apps.test.azure.example.com downloads http edge/Redirect None
Get a list of dns zones.
For public dns zones, enter the following command:
$ az network dns zone list --resource-group "${RESOURCE_GROUP}"
For private dns zones, enter the following command:
$ az network private-dns zone list -g "${RESOURCE_GROUP}"
Create a YAML file, for example, external-dns-sample-azure.yaml, that defines the Externaldns object:
external-dns-sample-azure.yaml fileapiVersion: externaldns.olm.openshift.io/v1beta1
kind: Externaldns
metadata:
name: sample-azure
spec:
zones:
- "/subscriptions/1234567890/resourceGroups/test-azure-xxxxx-rg/providers/Microsoft.Network/dnszones/test.azure.example.com"
provider:
type: Azure
source:
openshiftRouteOptions:
routerName: default
type: OpenShiftRoute
# ...
where:
metadata.nameSpecifies the External dns name.
spec.zonesSpecifies the zone ID. For a private dns zone, change dnszones to privatednsZones.
provider.typeSpecifies the provider type.
source.openshiftRouteOptionsSpecifies the options for the source of dns records.
routerNameIf the source type is OpenShiftRoute, you can pass the OpenShift Ingress Controller name. The External dns Operator selects the canonical hostname of that router as the target while creating the CNAME record.
source.typeSpecifies the route resource as the source for the Azure dns records.
Check the records created for the routes.
For public dns zones, enter the following command:
$ az network dns record-set list -g "${RESOURCE_GROUP}" -z "${ZONE_NAME}" | grep console
For private dns zones, enter the following command:
$ az network private-dns record-set list -g "${RESOURCE_GROUP}" -z "${ZONE_NAME}" | grep console