###coredns泛域名解析 单域名解析

#测试命令如下

#修改configmap
kubectl edit cm -n kube-system coredns -oyaml
#默认有2分钟延迟,可以先把pod数量为零之后在增加上来  以下两条命令生产环境慎用 慎用 慎用 重要的事情要说三遍
kubectl scale deployment coredns -n kube-system --replicas=0
kubectl scale deployment coredns -n kube-system --replicas=2
#启动一个pod测试
kubectl run --rm -i --tty dev --image=alpine /bin/sh
ping myki.com

coredns泛解析第一种

  Corefile: |
    .:53 {
        errors
        health {
          lameduck 5s
        }
        ready
        template IN A myki.cn {
          match .*\.myki\.cn
          answer "{{ .Name }} 60 IN A 192.168.1.1"
          fallthrough
        }
        kubernetes cluster.local. in-addr.arpa ip6.arpa {
          pods insecure
          fallthrough in-addr.arpa ip6.arpa
        }
        prometheus :9153
        forward . /etc/resolv.conf
        cache 30
        reload
        loadbalance
    }

coredns泛解析第二种 上游DNS用的是dnamasq 添加如下配置 address=/myki.com/127.0.0.1

apiVersion: v1
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
        cache 30
        loop
        reload
        loadbalance
    }
	#转发泛域名到上游dns
    mvmyun.com:53 {
        errors
        cache 30
        forward . 192.168.1.1
    }

coredns单解析

apiVersion: v1
data:
  Corefile: |
    .:53 {
        errors
        health {
           lameduck 5s
        }
        ready
		#单解析
        hosts {
          192.168.1.192 harbor.mvmyun.com
          fallthrough
        }
        kubernetes cluster.local in-addr.arpa ip6.arpa {
           pods insecure
           fallthrough in-addr.arpa ip6.arpa
           ttl 30
        }
        prometheus :9153
        forward . /etc/resolv.conf
        cache 30
        loop
        reload
        loadbalance
    }
    mvmyun.com:53 {
        errors
        cache 30
        forward . 192.168.1.1
    }