美文网首页
kubernetes coredns dns解析添加

kubernetes coredns dns解析添加

作者: 大鹏一怒乘风起 | 来源:发表于2022-06-05 19:55 被阅读0次

    在configmap里面找到corefile文件,增加hosts解析

    .:5353 {
        bind {$POD_IP}
        cache 30
        errors
        health {$POD_IP}:8080
        kubernetes cluster.local in-addr.arpa ip6.arpa {
            pods insecure
            fallthrough in-addr.arpa ip6.arpa
        }
        loadbalance round_robin
        hosts {
            10.66.1.11 nexus.mingyuanyun.com
            fallthrough 
        }
        prometheus {$POD_IP}:9153
        forward . /etc/resolv.conf {
            policy random
        }
        reload
    }
    
    配置完成之后,重启coredns pod  重启即可
    ###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
        }
    

    相关文章

      网友评论

          本文标题:kubernetes coredns dns解析添加

          本文链接:https://www.haomeiwen.com/subject/xihjprtx.html