k8s coredns 配置上游dns

k8s coredns 配置上游dns

一 . 配置corends的comfigmap

apiVersion: v1
data:
  Corefile: |
    .:53 {
        errors
        health
        kubernetes cluster.local in-addr.arpa ip6.arpa {
           pods insecure
           upstream
           fallthrough in-addr.arpa ip6.arpa
           #ttl 30
        }
        prometheus :9153
        proxy . 192.168.0.110 #上游dns配置,可以设置多个用空格隔开
        cache 30
        reload
        loadbalance
    }
kind: ConfigMap
metadata:
  name: coredns
  namespace: kube-system

二. 检查本地主机设置

查看/etc/resolv.conf文件

# Generated by NetworkManager
#search www.tendawifi.com 如果有search尽量删除
nameserver 192.168.0.1

否者会出现部分解析失败问题

  • dns配置
log-queries
no-resolv
server=223.5.5.5
address=/kafka1.agnziwjx.com/192.168.0.119
address=/kafka2.agnziwjx.com/192.168.0.119
address=/kafka3.agnziwjx.com/192.168.0.119
address=/kafka4.agnziwjx.com/192.168.0.119
address=/orderer1.org.hghfvclf.com/192.168.0.119
address=/orderer2.org.hghfvclf.com/192.168.0.119
address=/peer1.org.hghfvclf.com/192.168.0.119
address=/h3/192.168.0.119
address=/h3h3/192.168.0.119
address=/h2h3/192.168.0.119
address=/h4h3/192.168.0.119

  • 容器中执行ping
ping: bad address 'kafka1.agnziwjx.com'
/ # ping kafka2.agnziwjx.com
PING kafka2.agnziwjx.com (192.168.0.119): 56 data bytes
64 bytes from 192.168.0.119: seq=0 ttl=64 time=0.063 ms
64 bytes from 192.168.0.119: seq=1 ttl=64 time=0.136 ms
  • 解析log
⁣⁣⁣⁣dnsmasq: query[AAAA] kafka1.agnziwjx.com from 192.168.0.119
⁣⁣dnsmasq: config kafka1.agnziwjx.com is NODATA-IPv6
⁣⁣dnsmasq: query[AAAA] kafka1.agnziwjx.com.www.tendawifi.com from 192.168.0.119
⁣⁣dnsmasq: forwarded kafka1.agnziwjx.com.www.tendawifi.com to 223.5.5.5
⁣⁣dnsmasq: query[A] kafka1.agnziwjx.com.www.tendawifi.com from 192.168.0.119
⁣⁣dnsmasq: forwarded kafka1.agnziwjx.com.www.tendawifi.com to 223.5.5.5
⁣⁣dnsmasq: reply kafka1.agnziwjx.com.www.tendawifi.com is NXDOMAIN
⁣⁣dnsmasq: reply kafka1.agnziwjx.com.www.tendawifi.com is NODATA-IPv4
⁣⁣dnsmasq: query[A] kafka1.agnziwjx.com.www.tendawifi.com from 192.168.0.119
⁣⁣dnsmasq: cached kafka1.agnziwjx.com.www.tendawifi.com is NODATA-IPv4

⁣⁣dnsmasq: query[AAAA] kafka2.agnziwjx.com.www.tendawifi.com from 192.168.0.119
⁣⁣dnsmasq: forwarded kafka2.agnziwjx.com.www.tendawifi.com to 223.5.5.5
⁣⁣dnsmasq: query[A] kafka2.agnziwjx.com.www.tendawifi.com from 192.168.0.119
⁣⁣dnsmasq: forwarded kafka2.agnziwjx.com.www.tendawifi.com to 223.5.5.5
⁣⁣dnsmasq: reply kafka2.agnziwjx.com.www.tendawifi.com is NXDOMAIN
⁣⁣dnsmasq: reply kafka2.agnziwjx.com.www.tendawifi.com is NODATA-IPv6
⁣⁣dnsmasq: query[AAAA] kafka2.agnziwjx.com from 192.168.0.119
⁣⁣dnsmasq: config kafka2.agnziwjx.com is NODATA-IPv6
⁣⁣dnsmasq: query[A] kafka2.agnziwjx.com from 192.168.0.119

⁣⁣dnsmasq: ⁣⁣config kafka2.agnziwjx.com is 192.168.0.119

三.注意细节

  • 当修改corends的comfigmap的上游服务器不会立马生效时候,需要等待5~15秒之后,在pod中执行ping才能成功

你可能感兴趣的:(k8s coredns 配置上游dns)