我有在(裸机)群集中运行的kube-dns。我知道它可以正常工作,因为我可以将服务插入到我创建的名称中并获得主机条目:
$ host elk-service-headless.default.svc.cluster.local
elk-service-headless.default.svc.cluster.local has address 10.42.0.151
elk-service-headless.default.svc.cluster.local has address 10.42.0.152
elk-service-headless.default.svc.cluster.local has address 10.42.0.153
(...)
Run Code Online (Sandbox Code Playgroud)
我不知道该怎么做是列出kube-dns持有的所有记录。我已经尝试过像dig这样的标准DNS技巧host -l,但无法获得它们。但是无论如何,必须有一种方法可以通过Kubernetes本身来实现。我尝试检查ConfigMap,但未找到所需的内容。
AAb*_*er 25
这篇文章将帮助您在运行 kube-dns 的集群上找到 K8s 服务的内部 DNS 记录:
kubectl -n kube-system get svc kube-dns
现在我们知道内部 K8s DNS 解析器 IP 是 172.20.0.10
kubectl -n fe get ep
kubectl -n fe exec -it fe-app-575fdf6cb6-lt7t6 -- sh
#!/bin/bash
echo =========== Create an ubuntu pod ==================
kubectl run ubuntu --image=ubuntu -- bash -c "while true; do echo hello; sleep 10;done"
# Wait for the pod "ubuntu" to contain the status condition of type "Ready"
kubectl wait --for=condition=Ready pod/ubuntu
# Save a sorted list of IPs of all of the k8s SVCs:
kubectl get svc -A|egrep -v 'CLUSTER-IP|None'|awk '{print $4}'|sort -V > ips
# Copy the ip list to owr Ubuntu pod:
kubectl cp ips ubuntu:/
echo =========== Installing dig tool into the pod ===============
kubectl exec -it ubuntu -- apt-get update
kubectl exec -it ubuntu -- apt install -y dnsutils
# Print 7 blank lines
yes '' | sed 7q
echo =========== Print all k8s SVC DNS records ====================
for ip in $(cat ips); do echo -n "$ip "; kubectl exec -it ubuntu -- dig -x $ip +short; done
echo ====== End of list =====================
echo ========= Cleanup ===============
kubectl delete po ubuntu
rm ips
exit 0
Run Code Online (Sandbox Code Playgroud)
如果您使用kube-dns,它使用 dnsmaq 来缓存 DNS 记录,您可以通过此答案转储记录。
如果你使用的是coredns,它嵌入了一个缓存插件来缓存 DNS 记录,我发现没有办法获取这个缓存插件中的数据。但我发现 coredns 可以使用 etcd 作为后端,因此 DNS 记录可以缓存在 etcd 中,但这需要使用以下 Corefile 重新配置您的 coredns:
.:53 {
etcd {
path /skydns
endpoint <etcd_endpoint>
upstream /etc/resolv.conf
}
...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1345 次 |
| 最近记录: |