
云原生
Docker Swarm 中 Nginx 反代网关报 "No route to host" 的根因与解法
背景 集群使用 Docker Swarm 部署,Nginx 通过反向代理访问网关服务 wulaoer。按 Swarm 规则,Nginx 配置里写服务名加端口即可通信,例如: 但实际
前几天刚升级了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的日志是否解析失败,就可以判断服务是否为何相互之间调用异常的问题了。不需要在过度的排查了。没有了,看看其他的吧。
评论 0