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
- Generate the TOKEN by following steps mentioned in Keystone Identity.
- API to retrieve existing CoreDNS ClusterAddon object detail.
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
$ 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
# 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>
- Create a new JSON spec file with the required additional DNS configuration parameter.
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.
kfplc.com:53 {
errors
cache 30
forward . 10.246.6.1
}
a2ZwbGMuY29tOjUzIHsKICBlcnJvcnMKICBjYWNoZSAzMAogIGZvcndhcmQgLiAxMC4yNDYuNi4xCn0K
This needs to be inputted as a value for the parameter base64EncAdditionalDnsConfig
in the JSON spec file.
# 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
}
}
You can read more about it here CoreDNS Addon.
- Patch the existing CoreDNS ClusterAddon object with the newly created Spec file coredns.json.
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
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.
# 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>
The changes made to the AddOn object will persist across management plane & cluster upgrades.