Kubernetes中coredns无法正常域名解析问题

35 篇文章 0 订阅
25 篇文章 5 订阅

  下载了比较新的版本,查看下安装后的版本

Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.0", GitCommit:"9e991415386e4cf155a24b1da15becaa390438d8", GitTreeState:"clean", BuildDate:"2020-03-25T14:58:59Z", GoVersion:"go1.13.8", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.0", GitCommit:"9e991415386e4cf155a24b1da15becaa390438d8", GitTreeState:"clean", BuildDate:"2020-03-25T14:50:46Z", GoVersion:"go1.13.8", Compiler:"gc", Platform:"linux/amd64"}

按官方文档安装 kubeadm kubelet, kubectl后,如果不安装相关的网络 addon, 默认安装的coredns会是pending状态,而master会是"not ready"状态。

去官方

https://docs.projectcalico.org/getting-started/kubernetes/flannel/flannel

 

curl https://docs.projectcalico.org/manifests/canal-etcd.yaml -O

apply -f 后直接都正常了。

集群内的IP及访问也很正常。

  后来到pod的容器内,却不能访问service 的name. 这明显是dns出了问题。

  而pod里的容器内ping 集群内各IP都可以,却连baidu这样的域名 都ping不通。

  为什么很多教程里在验证dns都需要下载busybox,dig类的docker,因为一般的docker容器里可能连ping都没有。

https://blog.csdn.net/networken/article/details/105604173

这个教程是极棒的问题排查方式 ,可以通过更改各POD容器里的/etc/resolv.confj里的nameserver,开始它都默认指向kube-dns的集群地址,这个时候集群dns有问题,所以啥域名也拼不通,直接将它换成阿里云的域名解析服务器223.5.5.5,发现解析www.baidu.com没有问题了。 

    这个时候将nameserver更改成kube-dns 服务下的一个pod比如说coredns-546565776c-v7465 的集群内的本地地址,这个时候dns也是正常的,可以解析集群内的service name 及外部的域名,比如百度,说明 什么?,说明了是这个kube-dns的service出了问题。 而service是通过proxy来分发的。

   这个时候我们去kubectl -n kube-system logs -f  kube-proxy-c4fws ,发现了

] Failed to list IPVS destinations, error: parseIP Error ip=[253 0 0 16 2 69 0 0 221 232 251 54 204 98 3 124

很多类似这样的打印,所以这样就可以在百度找到

   https://blog.csdn.net/networken/article/details/105604173根据它的指引,我们可以找到根据原因 

https://github.com/kubernetes/kubernetes/issues/89520

下面作部分的引用 :

After some study, I find that this issue most likely is caused by the low linux kernel version.
I have reproduced this problem on Linux CentOS 3.10.0-693.el7.x86_64.

Accroding to the code, netlink will try to get d.AddressFamily attribute, but I find the kernel just does not support it :(

This is the Destination Attributes defined in /usr/include/linux/ip_vs.h (kernel 3.10)

/*
 * Attributes used to describe a destination (real server)
 *
 * Used inside nested attribute IPVS_CMD_ATTR_DEST
 */
enum {
	IPVS_DEST_ATTR_UNSPEC = 0,
	IPVS_DEST_ATTR_ADDR,		/* real server address */
	IPVS_DEST_ATTR_PORT,		/* real server port */

	IPVS_DEST_ATTR_FWD_METHOD,	/* forwarding method */
	IPVS_DEST_ATTR_WEIGHT,		/* destination weight */

	IPVS_DEST_ATTR_U_THRESH,	/* upper threshold */
	IPVS_DEST_ATTR_L_THRESH,	/* lower threshold */

	IPVS_DEST_ATTR_ACTIVE_CONNS,	/* active connections */
	IPVS_DEST_ATTR_INACT_CONNS,	/* inactive connections */
	IPVS_DEST_ATTR_PERSIST_CONNS,	/* persistent connections */

	IPVS_DEST_ATTR_STATS,		/* nested attribute for dest stats */
	__IPVS_DEST_ATTR_MAX,
};

No IPVS_DEST_ATTR_ADDR_FAMILY attribute is defined!

But in new kernel version, the Destination Attributes is defined like this:

/*
 * Attributes used to describe a destination (real server)
 *
 * Used inside nested attribute IPVS_CMD_ATTR_DEST
 */
enum {
	IPVS_DEST_ATTR_UNSPEC = 0,
	IPVS_DEST_ATTR_ADDR,		/* real server address */
	IPVS_DEST_ATTR_PORT,		/* real server port */

	IPVS_DEST_ATTR_FWD_METHOD,	/* forwarding method */
	IPVS_DEST_ATTR_WEIGHT,		/* destination weight */

	IPVS_DEST_ATTR_U_THRESH,	/* upper threshold */
	IPVS_DEST_ATTR_L_THRESH,	/* lower threshold */

	IPVS_DEST_ATTR_ACTIVE_CONNS,	/* active connections */
	IPVS_DEST_ATTR_INACT_CONNS,	/* inactive connections */
	IPVS_DEST_ATTR_PERSIST_CONNS,	/* persistent connections */

	IPVS_DEST_ATTR_STATS,		/* nested attribute for dest stats */

	IPVS_DEST_ATTR_ADDR_FAMILY,	/* Address family of address */

	IPVS_DEST_ATTR_STATS64,		/* nested attribute for dest stats */

	IPVS_DEST_ATTR_TUN_TYPE,	/* tunnel type */

	IPVS_DEST_ATTR_TUN_PORT,	/* tunnel port */

	IPVS_DEST_ATTR_TUN_FLAGS,	/* tunnel flags */

	__IPVS_DEST_ATTR_MAX,
};

Obviously, the kernel has added some attributes (IPVS_DEST_ATTR_ADDR_FAMILY, IPVS_DEST_ATTR_STATS64...).

That is why kube-proxy works well on systems with a higher version of the kernel.

So we can address this issue by upgrading our linux kernel.
Not sure which kernel version is the minimum requirement, maybe we should document something about this.

 

最后,通过将linux内核更新到4.x.x

## 载入公钥
$ rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

## 安装 ELRepo 最新版本
$ yum install -y https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm

## 列出可以使用的 kernel 包版本
$ yum list available --disablerepo=* --enablerepo=elrepo-kernel

## 安装指定的 kernel 版本:
$ yum install -y kernel-lt-4.4.218-1.el7.elrepo --enablerepo=elrepo-kernel

## 查看系统可用内核
$ cat /boot/grub2/grub.cfg | grep menuentry

menuentry 'CentOS Linux (3.10.0-1062.el7.x86_64) 7 (Core)' --class centos (略)
menuentry 'CentOS Linux (4.4.218-1.el7.elrepo.x86_64) 7 (Core)' --class centos ...(略)

## 设置开机从新内核启动
$ grub2-set-default "CentOS Linux (4.4.218-1.el7.elrepo.x86_64) 7 (Core)"

## 查看内核启动项
$ grub2-editenv list
saved_entry=CentOS Linux (4.4.218-1.el7.elrepo.x86_64) 7 (Core)
重启系统使内核生效:

$ reboot
启动完成查看内核版本是否更新:

$ uname -r

4.4.218-1.el7.elrepo.x86_64
 

最后重启后,一切正常。

注:可以看是否不通过ipvs的方式,这样是否就不用升级内核了,毕竟 这样重的操作,不方便实现一键安装,中间需要通过重启服务器等操作。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Kubernetes,可以通过CoreDNS来进行域名解析,并且不影响其他服务。CoreDNSKubernetes默认的DNS插件,它可以将Kubernetes的服务名称解析为相应的IP地址。 要使用CoreDNS进行域名解析,你需要在Kubernetes集群创建一个ConfigMap来配置CoreDNS。以下是一个示例ConfigMap: ``` apiVersion: v1 kind: ConfigMap metadata: name: coredns-custom namespace: kube-system data: Corefile: | .:53 { errors health kubernetes cluster.local in-addr.arpa ip6.arpa { pods insecure upstream /etc/resolv.conf fallthrough in-addr.arpa ip6.arpa } prometheus :9153 forward . /etc/resolv.conf cache 30 loop reload loadbalance } ``` 在这个ConfigMap,我们定义了CoreDNS的配置文件。其包括了指定的DNS服务器地址(/etc/resolv.conf)以及Kubernetes集群的服务名称解析规则。 接下来,你需要更新CoreDNS的Deployment来使用这个ConfigMap。以下是一个示例Deployment: ``` apiVersion: apps/v1 kind: Deployment metadata: name: coredns namespace: kube-system labels: k8s-app: kube-dns addonmanager.kubernetes.io/mode: Reconcile spec: replicas: 1 selector: matchLabels: k8s-app: kube-dns template: metadata: labels: k8s-app: kube-dns spec: containers: - name: coredns image: k8s.gcr.io/coredns:1.8.4 resources: limits: memory: 170Mi requests: cpu: 100m memory: 70Mi args: [ "-conf", "/etc/coredns/Corefile" ] volumeMounts: - name: config-volume mountPath: /etc/coredns readOnly: true volumes: - name: config-volume configMap: name: coredns-custom dnsPolicy: "Default" serviceAccountName: coredns ``` 在这个Deployment,我们使用了之前创建的ConfigMap来配置CoreDNS。同时,我们将ConfigMap挂载到了CoreDNS容器的/etc/coredns目录下,以便CoreDNS可以读取这个ConfigMap。 最后,你需要重启CoreDNS的Deployment以使其加载新的配置文件: ``` kubectl rollout restart deployment/coredns -n kube-system ``` 这样,你就可以在Kubernetes使用CoreDNS进行域名解析了,并且不会影响其他服务。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dualven_in_csdn

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值