> For the complete documentation index, see [llms.txt](https://platform9.com/kb/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://platform9.com/kb/pmk/how-to/custom-coredns-configuration-for-adding-additional-external-dns.md).

# How To Customize CoreDNS Configuration for Adding Additional External DNS

## Problem

How To Customize CoreDNS Configuration for Adding Additional External DNS.

## Environment

* Platform9 Managed Kubernetes - v5.2 and K8s v1.20 and Higher
* AddOn Management

## Procedure

1. Generate the TOKEN by following steps mentioned in [Keystone Identity](https://platform9.com/learn/keystone-identity).
2. API to retrieve existing CoreDNS ClusterAddon object detail.

{% tabs %}
{% tab title="API GET Call" %}

```python
curl -X GET -H "X-Auth-Token: $TOKEN" https://<DU_FQDN>/qbert/v4/<PROJECT_ID>/sunpike/apis/sunpike.platform9.com/v1alpha2/namespaces/default/clusteraddons/<CLUSTER_UUID>-coredns
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Example Showing Default Set Parameters" %}

```typescript
$ curl -X GET -H "X-Auth-Token: $TOKEN" https://cs-sanchit.platform9.horse/qbert/v4/1c1003c1b84e47e7bd2a4cdf3b725976/sunpike/apis/sunpike.platform9.com/v1alpha2/namespaces/default/clusteraddons/8c8f1d62-159a-4829-b68f-3432d4a9afc6-coredns | jq
...
...
  "spec": {
    "clusterID": "8c8f1d62-159a-4829-b68f-3432d4a9afc6",
    "version": "1.7.0",
    "type": "coredns",
    "override": {
      "params": [
        {
          "name": "dnsMemoryLimit",
          "value": "170Mi"
        },
        {
          "name": "dnsDomain",
          "value": "cluster.local"
        }
      ]
    },
    "watch": true
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Example Existing Associated ConfigMap" %}

```go
# kubectl describe configmap coredns -n kube-system
Name:         corednsNamespace:    kube-system
Labels:       addonmanager.kubernetes.io/mode=EnsureExists
Annotations:  <none>


Data
====
Corefile:
----
.:53 {
    errors
    health {
        lameduck 5s
    }
    ready
    kubernetes cluster.local in-addr.arpa ip6.arpa {
        pods insecure
        fallthrough in-addr.arpa ip6.arpa
        ttl 30
    }
    prometheus :9153
    forward . /etc/resolv.conf {
        max_concurrent 1000
    }
    cache 30
    loop
    reload
    loadbalance
}

Events:  <none>
```

{% endtab %}
{% endtabs %}

3. Create a new JSON spec file with the required additional DNS configuration parameter.

{% hint style="info" %}
**Note**

The extra DNS configuration parameter one wants to add should have no indentations. The addon operator adds the correct indentation before adding it under the DNS block in the configmap.
{% endhint %}

{% tabs %}
{% tab title="Sample DNS configuration without indentation" %}

```go
kfplc.com:53 {
   errors
   cache 30
   forward . 10.246.6.1
}
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="base64 Encoding of the sample configuration" %}

```go
a2ZwbGMuY29tOjUzIHsKICBlcnJvcnMKICBjYWNoZSAzMAogIGZvcndhcmQgLiAxMC4yNDYuNi4xCn0K
```

{% endtab %}
{% endtabs %}

This needs to be inputted as a value for the parameter *`base64EncAdditionalDnsConfig`* in the JSON spec file.

{% tabs %}
{% tab title="Sample JSON File" %}

```go
# cat coredns.json
{
    "apiVersion": "sunpike.platform9.com/v1alpha2",
    "kind": "ClusterAddon",
    "metadata": {
        "labels": {
            "sunpike.pf9.io/cluster": "CLUSTER_UUID",
            "type": "coredns"
        },
        "name": "CLUSTER_UUID-coredns",
        "namespace": "default"
    },
    "spec": {
        "clusterID": "CLUSTER_UUID",
        "override": {
            "params": [
                {
                    "name": "dnsMemoryLimit",
                    "value": "170Mi"
                },
                {
                    "name": "dnsDomain",
                    "value": "cluster.local"
                },
                {
                    "name": "base64EncAdditionalDnsConfig",
                    "value": "<base 64 encoded additional dns config>"
                }
            ]
        },
        "type": "coredns",
        "version": "1.7.0",
        "watch": true
    }
}
```

{% endtab %}
{% endtabs %}

You can read more about it here [CoreDNS Addon](https://platform9.com/docs/kubernetes/coredns-addon).

4. Patch the existing CoreDNS ClusterAddon object with the newly created Spec file *coredns.json*.

{% tabs %}
{% tab title="Command" %}

```go
curl -X PATCH -H "X-Auth-Token: $TOKEN" -H "Content-Type: application/merge-patch+json" -H "Accept: application/json" -d "@coredns.json" https://<DU_FQDN>/qbert/v4/<PROJECT_ID>/sunpike/apis/sunpike.platform9.com/v1alpha2/namespaces/default/clusteraddons/<CLUSTER_UUID>-coredns
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Info**

Replace the placeholders `<DU_FQDN>`, `<PROJECT_ID>` and the `<CLUSTER_UUID>` with their appropriate values required. The `name` attribute in the spec must be in the format `CLUSTER_UUID-coredns`

The CoreDNS version in the above JSON file is currently on *1.7.0*. It will be updated along with the `pf9-kube` version and can be referred from the [Support Matrix.](https://docs.platform9.com/kubernetes/support-matrix)
{% endhint %}

{% tabs %}
{% tab title="Updated ConfigMap after the PATCH API Call" %}

```go
# kubectl describe configmap coredns -n kube-system
Name:         coredns
Namespace:    kube-system
Labels:       addonmanager.kubernetes.io/mode=EnsureExists
Annotations:  <none>

Data
====
Corefile:
----
.:53 {
    errors
    health {
        lameduck 5s
    }
    ready
    kubernetes cluster.local in-addr.arpa ip6.arpa {
        pods insecure
        fallthrough in-addr.arpa ip6.arpa
        ttl 30
    }

    prometheus :9153
    forward . /etc/resolv.conf {
        max_concurrent 1000
    }
    cache 30
    loop
    reload
    loadbalance

}

kfplc.com:53 {
  errors
  cache 30
  forward . 10.246.6.1
}​


Events:  <none>
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Note**

The changes made to the AddOn object will persist across management plane & cluster upgrades.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://platform9.com/kb/pmk/how-to/custom-coredns-configuration-for-adding-additional-external-dns.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
