上次更新日期:2021 年 4 月 23 日
我想在我的 Amazon Elastic Kubernetes Service (Amazon EKS) 集群中使用 CoreDNS 配置转发服务器。
简短描述您可以使用 CoreDNS 配置条件转发,以将 DNS 查询发送至通过自定义 DNS 服务器解析的域。有关更多信息,请参阅 Kubernetes 网站上的自定义 DNS 服务。
解决方法1. 修改 CoreDNS ConfigMap 并添加条件转发服务器配置:
$ 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
fallthrough in-addr.arpa ip6.arpa
}
prometheus :9153
forward . /etc/resolv.conf
cache 30
loop
reload
loadbalance
}
domain-name:53 {
errors
cache 30
forward . custom-dns-server
reload
}
注意:将域名替换为您的域名。将 custom-dns-server 替换为您的自定义 DNS 服务器 IP 地址。
2. 验证域名解析是否有效:
$ kubectl run busybox --restart=Never --image=busybox:1.28 -- sleep 3600
$ kubectl exec busybox -- nslookup domain-name
注意:将域名替换为您的域名。