Private DNS configuration Kubernetes upstream and domain name server (coredns forward)

1. To modify and add CoreDNS ConfigMap conditional forwarding server configuration

Forces all non-clustered DNS lookup through a specific domain name server (located 172.16.0.1), the proxy and forward pointing the domain name servers, instead of /etc/resolv.conf.

Consul domain server if the cluster is located 10.150.0.1, Consul and all names with the suffix .consul.local

$ kubectl -n kube-system edit configmap coredns

Output as follows:

apiVersion: v1
kind: ConfigMap
metadata:
  annotations:
  labels:
    eks.amazonaws.com/component: coredns
    k8s-app: kube-dns
  name: coredns
  namespace: kube-system
data:
  Corefile: |
    .:53 {
        errors
        health
        kubernetes cluster.local in-addr.arpa ip6.arpa {
          pods insecure
          upstream 172.16.0.1
          fallthrough in-addr.arpa ip6.arpa
        }
        prometheus :9153
        proxy . 172.16.0.1
        cache 30
        loop
        reload
        loadbalance
    }
    domain-name:53 {
        errors 
        cache 30
        forward . custom-dns-server
        reload
    }
     consul.local:53 {
        errors
        cache 30
        proxy . 10.150.0.1
    }

Note: Replace the domain name as your domain name. The custom-dns-server is replaced with your custom DNS server IP address.

2. Verify that the DNS method

$ kubectl run busybox --restart=Never --image=busybox -- sleep 3600
$ kubectl exec busybox -- nslookup domain-name

Guess you like

Origin blog.51cto.com/foxhound/2483880