Pods 无法解析 Kubernetes DNS。

huangapple go评论68阅读模式
英文:

Pods cannot resolve kubernetes DNS

问题

From a pod, I am able to resolve DNS addresses only when I am using the CoreDNS endpoint IP. How to make pods use the CoreDNS IP address?

CoreDNS configuration:

  • IP address: 10.96.0.10
  • endpoint: 10.244.0.222

Kubelet configuration:
clusterDNS:

  • 10.96.0.10

Flannel: Default configuration from https://github.com/flannel-io/flannel

Cluster: The cluster is up and running and has these pods:

  • coredns
  • etcd
  • apiserver
  • controller-manager
  • flannel
  • scheduler

Also, the cluster consists of only a single master node (that is schedulable).

Pod setup:

# run pod
kubectl run -it --rm --restart=Never --image=infoblox/dnstools:latest dnstools

Test cases:
1.
nslookup kubernetes.default

output: ;; connection timed out; no servers could be reached

nslookup kubernetes.default 10.96.0.10

output: ;; connection timed out; no servers could be reached

nslookup kubernetes.default 10.244.0.222

output: resolved address, Address: 10.96.0.1

ping 10.96.0.1

output: all packages lost

ping 10.96.0.10

output: all packages lost

ping 10.244.0.222

output: all packages received

How did this happen?
This issue appeared when I was updating a cluster. I have reinstalled kube-flannel and CoreDNS services with their default equivalents:

Throughout this process, I also uninstalled kube-proxy.

I don't know if kube-proxy is a necessary component of a Kubernetes cluster, or if Flannel can be an alternative, but I tried to reinstall it with this command: https://stackoverflow.com/a/71519601/19570235. However, without any luck.

Error message:
could not fetch a Kubernetes version from the internet: unable to get URL "https://dl.k8s.io/release/stable-1.txt":

英文:

TL;DR

From a pod I am able to resolve DNS addresses only when I am using CoreDNS endpoint IP. How to make pods use coreDNS IP address?

CoreDNS configuration

  • IP address: 10.96.0.10
  • endpoint: 10.244.0.222

Kubelet configuration

...
clusterDNS:
  - 10.96.0.10
...

Flannel

Default configuration from: https://github.com/flannel-io/flannel

Cluster

Is up and running and have these pods:

  • coredns
  • etcd
  • apiserver
  • controller-manager
  • flannel
  • scheduler

Also, the cluster consists of only a single master node (that is schedulable).

Pod setup

# run pod
kubectl run -it --rm --restart=Never --image=infoblox/dnstools:latest dnstools

Test cases

# 1
nslookup kubernetes.default
# output: ;; connection timed out; no servers could be reached
# 2
nslookup kubernetes.default 10.96.0.10
# output: ;; connection timed out; no servers could be reached
# 3
nslookup kubernetes.default 10.244.0.222
# output: resolved address, Address: 10.96.0.1
# 4
ping 10.96.0.1
# output: all packages lost
# 5
ping 10.96.0.10
# output: all packages lost
# 6
ping 10.244.0.222
# output: all packages received

How have that happened?

That issue appeared when I was updating a cluster. I have reinstalled kube-flannel and coreDNS services with their default equivalents:

Throughout this process I have also uninstalled kube-proxy.

I don't know if kube-proxy is a necessary component of a k8s or does a flannel can be an alternative but I tried to reinstall it with this command: https://stackoverflow.com/a/71519601/19570235 However, without any luck.

# Error message:
could not fetch a Kubernetes version from the internet: unable to get URL "https://dl.k8s.io/release/stable-1.txt":

答案1

得分: 0

我已经通过将kubelet中的clusterDNS部分从10.96.0.10更改为10.244.0.222来解决了这个问题。

之后,我重新启动了kubelet服务(k8s在Ubuntu上运行),以及Pods。现在,Pods可以解析主机名和其他服务,比如google.com。

我不太确定这是否是一个解决方法,或者是否需要在kubelet配置中提供coreDNS端点,因此我会在接受此答案之前将此帖子保持开放一段时间。

英文:

I was able to resolve this issue by changing clusterDNS section in kubelet from 10.96.0.10 to 10.244.0.222.

After that I have restarted kubelet service (k8s is working on Ubuntu) and pods. Now pods can resolve hostnames and other services, like google.com.

I am not really sure if that is a workaround or if it is necessary to provide coreDNS endpoint to the kubelet config and because of that I will keep this post open for a while before accepting this answer.

huangapple
  • 本文由 发表于 2023年6月26日 20:03:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76556493.html
匿名

发表评论

匿名网友

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

确定