默認的coredns配置沒有開啟日志插件,這導致kubernetes集群中一些dns解析超時問題難以定位。通過kubernetes log命令查看到的結(jié)果往往是
root@iZj6chmpsf3hnh4tj2y2mgZ:~# kubectl logs coredns-64897985d-59hbn -n kube-system
.:53
[INFO] plugin/reload: Running configuration MD5 = db32ca3650231d74073ff4cf814959a7
CoreDNS-1.8.6
linux/amd64, go1.17.1, 13a9191
我們可以通過修改kubernetes的?configmap中的coredns配置來開啟日志功能,默認的coredns配置如下
kubectl describe configmap coredns -n kube-system
Name: coredns
Namespace: kube-system
Labels: <none>
Annotations: <none>
Data
====
Corefile:
----
.:53 {
errors
health {
lameduck 5s
}
ready
kubernetes cluster.local in-addr.arpa ip6.arpa {
pods insecure
fallthrough in-addr.arpa ip6.arpa
ttl 30
}
prometheus :9153
forward . /etc/resolv.conf {
max_concurrent 1000
}
cache 30
loop
reload
loadbalance
}
BinaryData
====
添加log模塊

image-20211230205435435
接下來我們再使用命令查看日志,就可以看到dns解析的記錄,無需重啟coredns

image-20211230205544473
還可以在log模塊里添加一些配置來自定義log輸出,例如
只打印錯誤的解析請求
. {
log . {combined} {
class denial error
}
}
只打印拒絕了的,并且是example.org下的請求
. {
log example.org {
class denial
}
}