Kubernetes Pod 默认的DNS策略为:ClusterFirst,即默认使用集群内部DNS,所以如果想要增加内部DNS解析可以通过修改集群内CoreDNS的配置文件完成。

1
➜  ~ kubectl -n kube-system edit cm coredns

添加如下配置

1
2
3
4
        hosts {
           192.168.122.81 xnile.cn
           fallthrough
        }

整个配置文件如下

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
apiVersion: v1
data:
  Corefile: |
    .:53 {
        errors
        health
        hosts {
           192.168.122.81 xnile.cn
           fallthrough
        }
        kubernetes cluster.local in-addr.arpa ip6.arpa {
           pods insecure
           upstream
           fallthrough in-addr.arpa ip6.arpa
           ttl 30
        }
        prometheus :9153
        forward . /etc/resolv.conf
        cache 30
        loop
        reload
        loadbalance
    }    
kind: ConfigMap
metadata:
  name: coredns
  namespace: kube-system