在k8s中配置coredns日志输出

avatar 2024年5月30日18:24:09 评论 209 次浏览

前几天刚升级了kubernetes,今天突然发现,在k8s中有个别的服务不可用,通过日志排除发现,原来请求的负载均衡的地址变化了,这个在coredns中没有自动的更新。但是在coredns中也没有日志输出给排查工作带来了不便,今天就记录一下如何给coredns增加日志输出。

 [root@master01 ~]# kubectl describe configmaps -n kube-system coredns
 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
 ====
 
 Events:  <none>

因为集群内对TCP的支持有限,所以coredns优先采用UDP协议,即使请求通过TCP协议也要先尝试使用UDP协议,所以我们需要在coredns中先配置prefer_udp然后在开启log。

 [root@master01 ~]# kubectl edit configmaps -n kube-system coredns
 ....................................
 apiVersion: v1
 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
            prefer_udp #增加
         } 
         cache 30
         loop
         log  #增加
         reload
         loadbalance
     }
 kind: ConfigMap
 metadata:
   creationTimestamp: "2023-10-24T07:01:04Z"
   name: coredns
   namespace: kube-system
   resourceVersion: "123364853"
   uid: bf5414c9-9712-48cd-946d-a2b50ce07322

然后保存即可,下面看看日志是否有输出。

  kubectl logs -n kube-system coredns-8468f7cd6-hdlpl -f
 .:53
 [INFO] plugin/reload: Running configuration SHA512 = 591cf328cccc12bc490481273e738df59329c62c0b729d94e8b61db9961c2fa5f046dd37f1cf888b953814040d180f52594972691cd6ff41be96639138a43908
 CoreDNS-1.9.3
 linux/amd64, go1.18.2, 45b0a11
 [INFO] Reloading
 [INFO] plugin/health: Going into lameduck mode for 5s
 [INFO] plugin/reload: Running configuration SHA512 = 52a214bc4e0cb7dfb5a5420a2bc477af664daa42b634258f31f304cf553d3e2f763a612e12aee7d677a0b8c3180d08b7878d1c0a3a90120969794df143548e34
 [INFO] Reloading complete
 [INFO] 127.0.0.1:40330 - 2784 "HINFO IN 4091778280082153869.6559142958910158676. udp 57 false 512" NXDOMAIN qr,aa,rd,ra 132 0.013122052s

日志正常有输出了,这样就添加好了,后期可以看一下coredns的日志是否解析失败,就可以判断服务是否为何相互之间调用异常的问题了。不需要在过度的排查了。没有了,看看其他的吧。

avatar

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: