Custom private domain name in kubernetes cluster
We use default service domain name ${servicename}.${namespace}.svc.cluster.local
in kubernetes cluster, however the custom private domain name in private k8s networks frequently used. we can use coredns component reparse the private domain name to default CNAME.
change coredns configmap add custom domain name config to yaml
kubectl edit cm coredns -n kube-system
1data:
2 Corefile: |
3 .:53 {
4 errors
5 health {
6 lameduck 5s
7 }
8 ready
9 kubernetes cluster.local in-addr.arpa ip6.arpa {
10 pods insecure
11 fallthrough in-addr.arpa ip6.arpa
12 ttl 30
13 }
14 file /etc/coredns/uat-env.db uat-env.com
15 prometheus :9153
16 forward . /etc/resolv.conf
17 cache 30
18 loop
19 reload
20 loadbalance
21 }
22 uat-env.db: >-
23 uat-env.com. IN SOA ns.dns.cluster.local.
24 hostmaster.cluster.local. 1592362202 7200 1800 86400 30
25
26 uat-env.com. IN NS
27 kube-dns.kube-system.svc.cluster.local.
28
29 db.uat-env.com. IN CNAME
30 mysql.db.svc.cluster.local.
31
32 private-services.uat-env.com. IN CNAME
33 internal-gateway.default.svc.cluster.local.
add file /etc/coredns/uat-env.db uat-env.com
line to Corefile section
add new section uat-env.db
and add relative recordset
Change coredns
deployment configure in kube-system
namespace
kubectl edit deployment coredns -n kube-system
under config-volume
section in volumes
section add an item, looks like this
1items:
2 - key: Corefile
3 path: Corefile
4 - key: uat-env.db
5 path: uat-env.db
that’s all, enjoy it.
1# test it
2dig db.uat-env.com
3curl http://private-services.uat-env.com