红枫-vip 发表于 2022-7-9 11:45:31

抛问题-如何在 CoreDNS 配置文件添加访问日志?

啥也不说了 直接抛出问题:如何在 CoreDNS 配置文件添加访问日志?面试题一枚

闪电迈坤 发表于 2022-7-9 11:54:06

CoreDNS 配置文件是 Corefile,通过添加 log 插件可以打印访问日志,而 Corefile 是保存在 ConfigMap 中。

$kubectl edit configmap -nkube-system coredns修改如下 ConfigMap,添加 log:
apiVersion: v1
kind: ConfigMap
metadata:
name: coredns
namespace: kube-system
data:
Corefile: |
    .:53 {
      log
      errors
      health
      kubernetes cluster.local in-addr.arpa ip6.arpa {
          pods insecure
          upstream
          fallthrough in-addr.arpa ip6.arpa
      }
      prometheus :9153
      forward . /etc/resolv.conf
      cache 30
      loop
      reload
      loadbalance
    }    ConfigMap 保存后需要等待 1 到 2 分钟生效到 CoreDNS 的 Pod 中。如果配置生效,则 CoreDNS 将在日志看到:
.:53
plugin/reload: Running configuration MD5 = db32ca3650231d74073ff4cf814959a7
Reloading complete

在应用 Pod 中测试目标地址的连通性:
#查询目标地址
$kubectl get svc |grep datachannel
datatest                               ClusterIP   10.96.0.37    <none>      8080/TCP                                       29d

#测试连通性
$kubectl exec -it deployment-flink-jobmanager-c695cf9d-rgtbh -- curl -vi datatest:8080
*   Trying 10.96.0.37:8080...
* Connected to datachannel (10.96.0.37) port 8092 (#0)
> GET / HTTP/1.1
> Host: datachannel:8080
> User-Agent: curl/7.69.1
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 400
HTTP/1.1 400
< Content-Type: text/plain;charset=UTF-8
Content-Type: text/plain;charset=UTF-8
< Connection: close
Connection: close

<
Bad Request
This combination of host and port requires TLS.
* Closing connection 0

#DNS的关键日志
kubectl logs -nkube-system coredns-659f5bbffd-rfr79 |grep datatest
10.244.2.252:36293 - 17111 "AAAA IN datatest.default.svc.cluster.local. udp 51 false 512" NOERROR qr,aa,rd 144 0.000184943s
10.244.2.252:36293 - 32461 "A IN datatest.default.svc.cluster.local. udp 51 false 512" NOERROR qr,aa,rd 100 0.000144745s

答案一枚

页: [1]
查看完整版本: 抛问题-如何在 CoreDNS 配置文件添加访问日志?