我想在CoreDNS中配置自定义DNS(以绕过NAT环回问题,这意味着在网络内部,IP的解析方式与网络外部的解析方式不同)。
我试图用一个“假”域修改ConfigMap for CoreDNS只是为了测试,但是它不起作用。
我正在使用minik8s
这是配置映射coredns的配置文件:
apiVersion: v1
data:
Corefile: |
.:53 {
errors
health
ready
kubernetes cluster.local in-addr.arpa ip6.arpa {
pods insecure
fallthrough in-addr.arpa ip6.arpa
}
prometheus :9153
forward . 8.8.8.8 8.8.4.4
cache 30
loop
reload
loadbalance
}
consul.local:53 {
errors
cache 30
forward . 10.150.0.1
}
kind: ConfigMap
然后,我尝试使用占线框来解析此地址,但是它不起作用。
$kubectl exec -ti busybox -- nslookup test.consul.local
> nslookup: can't resolve 'test.consul.local'
command terminated with exit code 1
甚至kubernetes DNS都失败了
$ kubectl exec -ti busybox -- nslookup kubernetes.default
nslookup: can't resolve 'kubernetes.default'
command terminated with exit code 1
最佳答案
我转载了您的情况,它可以按预期工作。
在这里,我将描述在Kubernetes上使用自定义DNS的两种不同方法。首先是Pod级别。您可以自定义您的广告连播将使用的DNS服务器。在您不想为所有 pods 更改此配置的特定情况下,这很有用。
为此,您需要添加一些可选字段。要了解更多信息,请阅读this。
例:
kind: Pod
metadata:
name: busybox-custom
namespace: default
spec:
containers:
- name: busybox
image: busybox:1.28
command:
- sleep
- "3600"
imagePullPolicy: IfNotPresent
dnsPolicy: "None"
dnsConfig:
nameservers:
- 8.8.8.8
searches:
- ns1.svc.cluster-domain.example
- my.dns.search.suffix
options:
- name: ndots
value: "2"
- name: edns0
restartPolicy: Always
$ kubectl exec -ti busybox-custom -- nslookup cnn.com
Server: 8.8.8.8
Address 1: 8.8.8.8 dns.google
Name: cnn.com
Address 1: 2a04:4e42::323
Address 2: 2a04:4e42:400::323
Address 3: 2a04:4e42:200::323
Address 4: 2a04:4e42:600::323
Address 5: 151.101.65.67
Address 6: 151.101.129.67
Address 7: 151.101.193.67
Address 8: 151.101.1.67
$ kubectl exec -ti busybox-custom -- nslookup kubernetes.default
Server: 8.8.8.8
Address 1: 8.8.8.8 dns.google
nslookup: can't resolve 'kubernetes.default'
command terminated with exit code 1
如您所见,此方法将产生解析内部DNS名称的问题。
实现此目的的第二种方法是在群集级别上更改DNS。正如您所见,这就是您选择的方式。
$ kubectl get cm coredns -n kube-system -o yaml
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
forward . 8.8.8.8 8.8.4.4
cache 30
loop
reload
loadbalance
}
kind: ConfigMap
如您所见,我没有
consul.local:53
条目。这种设置并不常见,我认为您无需在设置中包括此条目。 这可能是您的问题,当我添加此条目时,也会遇到与您报告的问题相同的问题。
$ kubectl exec -ti busybox -- nslookup cnn.com
Server: 10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local
Name: cnn.com
Address 1: 2a04:4e42:200::323
Address 2: 2a04:4e42:400::323
Address 3: 2a04:4e42::323
Address 4: 2a04:4e42:600::323
Address 5: 151.101.65.67
Address 6: 151.101.193.67
Address 7: 151.101.1.67
Address 8: 151.101.129.67
$ kubectl exec -ti busybox -- nslookup kubernetes.default
Server: 10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local
Name: kubernetes.default
Address 1: 10.96.0.1 kubernetes.default.svc.cluster.local
另一个主要问题是您正在使用最新的busybox镜像调试DNS。我强烈建议您避免使用任何低于1.28的版本,因为它知道problems有关名称解析的问题。
可以用来对DNS进行故障排除的最佳busybox镜像是1.28,因为注释中建议使用Oleg Butuzov。
关于kubernetes - 在kubernetes中配置自定义DNS,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59399457/