1.要修改 CoreDNS ConfigMap 並添加條件轉發服務器配置
強制所有非集羣 DNS 查找通過特定的域名服務器(位於172.16.0.1),將 proxy 和 forward 指向域名服務器,而不是 /etc/resolv.conf。
如果集羣的 Consul 域服務器位於 10.150.0.1,並且所有 Consul 名稱都帶有後綴.consul.local
$ kubectl -n kube-system edit configmap coredns
輸出內容如下:
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
}
注意:將域名替換爲您的域名。將 custom-dns-server 替換爲您的自定義 DNS 服務器 IP 地址。
2.驗證域名解析方法
$ kubectl run busybox --restart=Never --image=busybox -- sleep 3600
$ kubectl exec busybox -- nslookup domain-name