Skip to main content

Adjust CoreDNS configuration in Kubernetes

Managed - FPT Kubernetes Engine (M-FKE) uses CoreDNS to resolve domains for the cluster. Since FPT manages CoreDNS, you can't edit its Corefile directly — use a coredns-custom ConfigMap instead.

note

After applying any coredns-custom change below, delete the 2 CoreDNS Pods in kube-system to reload the configuration.

Rewrite DNS​

Configure DNS rewriting by adding this ConfigMap in the kube-system namespace:

apiVersion: v1
kind: ConfigMap
metadata:
name: coredns-custom
namespace: kube-system
data:
test.server: |
.com:8053 {
log
errors
rewrite stop {
name regex (.*)\..com {1}.default.svc.cluster.local
answer name (.*)\.default\.svc\.cluster\.local {1}..com
}
forward . /etc/resolv.conf # you can redirect this to a specific DNS server such as 10.0.0.10, but that server must be able to resolve the rewritten domain name
}

Custom forward server​

To send resolution requests to a specific DNS server:

apiVersion: v1
kind: ConfigMap
metadata:
name: coredns-custom
namespace: kube-system
data:
test.server: | # you may select any name here, but it must end with the .server file extension
.com:8053 {
forward foo.com 1.1.1.1
forward . 2.2.2.2
}

1.1.1.1 and 2.2.2.2 are the DNS servers you define. forward . 2.2.2.2 sends resolution requests for *.com domains to 2.2.2.2.

Custom domains​

Without a coredns-custom ConfigMap, M-FKE can't resolve a domain that's only valid inside the cluster (for example, puglife.local, which isn't a public domain). Configure it as follows:

apiVersion: v1
kind: ConfigMap
metadata:
name: coredns-custom
namespace: kube-system
data:
puglife.server: | # you may select any name here, but it must end with the .server file extension
puglife.local:8053 {
errors
cache 30
forward . 192.11.0.1 # this is my test/dev DNS server
}

Stub domain​

Configure a stub domain as follows — update the custom domain and IP address to match your infrastructure:

apiVersion: v1
kind: ConfigMap
metadata:
name: coredns-custom
namespace: kube-system
data:
test.server: | # you may select any name here, but it must end with the .server file extension
abc.com:8053 {
errors
cache 30
forward . 1.2.3.4
}
my.cluster.local:8053 {
errors
cache 30
forward . 2.3.4.5
}

Hosts plugin​

Add custom DNS records with the hosts plugin:

apiVersion: v1
kind: ConfigMap
metadata:
name: coredns-custom # this is the name of the configmap you can overwrite with your changes
namespace: kube-system
data:
test.override: | # you may select any name here, but it must end with the .override file extension
hosts {
10.0.0.1 example1.org
10.0.0.2 example2.org
10.0.0.3 example3.org
fallthrough
}