MySQL 与 Kubernetes 集群集成的 DNS 错误

如何解决MySQL 与 Kubernetes 集群集成的 DNS 错误

发生了什么:
我正在尝试使用 externalName 规范创建服务端点,以允许在 pod 内运行的微服务访问本地主机上的本地 MySQL 服务器。

这是 yaml 文件的相关部分:

apiVersion: v1 
kind: Service 
metadata: 
  name: mysql 
  namespace: default 
spec: 
  type: ExternalName 
  externalName: host.minikube.internal

您期望发生的事情:
我希望能够连接,但我的 SpringBoot 容器显示 mysql 连接不起作用。我已经测试了微服务,它在 Docker 中使用相同的 MySQL 数据库运行。

如何重现它(尽可能少且精确):
minikube 和 kubernetes 的正常安装,使用上面给出的 mysql 服务运行 https://k8s.io/examples/admin/dns/dnsutils.yaml 中的 dnsutils 映像。

还有什么我们需要知道的吗?:
我已经测试了此处详述的故障排除 (https://kubernetes.io/docs/tasks/administer-cluster/dns-debugging-resolution/),但它没有解决问题。运行时:

kubectl exec -i -t dnsutils -- nslookup mysql.default

我收到以下消息:

Server: 10.96.0.10
Address: 10.96.0.10#53

mysql.default.svc.cluster.local canonical name = host.minikube.internal.
** server can't find host.minikube.internal: SERVFAIL

command terminated with exit code 1

我已验证 CoreDNS 已安装并正在运行:

NAME READY STATUS RESTARTS AGE
coredns-f9fd979d6-z58cr 1/1 Running 0 31m

端点已公开:

NAME ENDPOINTS AGE
kube-dns 172.17.0.2:53,172.17.0.2:53,172.17.0.2:9153 32m

我的 /etc/resolv.conf 只有一个条目:

nameserver 192.168.53.145

环境:

Kubernetes 版本(使用 kubectl 版本):

Client Version: version.Info{Major:"1",Minor:"20",GitVersion:"v1.20.0",GitCommit:"af46c47ce925f4c4ad5cc8d1fca46c7b77d13b38",GitTreeState:"clean",BuildDate:"2020-12-08T17:59:43Z",GoVersion:"go1.15.5",Compiler:"gc",Platform:"windows/amd64"}

Server Version: version.Info{Major:"1",Minor:"19",GitVersion:"v1.19.4",GitCommit:"d360454c9bcd1634cf4cc52d1867af5491dc9c5f",BuildDate:"2020-11-11T13:09:17Z",GoVersion:"go1.15.2",Platform:"linux/amd64"}

云提供商或硬件配置:
使用 Minikube 运行 Kubernetes 的本地 Windows 10 Pro x64 操作系统(例如:cat /etc/os-release):
NAME=Buildroot VERSION=2020.02.7 ID=buildroot VERSION_ID=2020.02.7 PRETTY_NAME="Buildroot 2020.02.7

内核(例如uname -a):Linux minikube 4.19.150 #1 SMP Fri Nov 6 15:58:07 PST 2020 x86_64 GNU/Linux

安装工具:使用相关的 kubectl 和 minikube .exe 文件安装 网络插件和版本(如果这是与网络相关的错误):

其他:

解决方法

这个问题似乎与 github 上描述的 Minikube issue 密切相关。

您可以看到,在您的 Pod 文件中的 /etc/hosts 中 - 没有任何 host.minikube.internal 条目:

$ kubectl exec -it dnsutils -- cat /etc/hosts | grep "host.minikube.internal"
$

Minikube 主机上,您可以访问 host.minikube.internal,因为 Minikube(版本 v1.10+)将此 hostname 条目添加到/etc/hosts 文件。您可以在 Host access | minikube 中找到更多信息。

这是我的 Minikube 示例(我使用的是 docker 驱动程序):

user@minikube:~$ kubectl exec -it dnsutils -- cat /etc/hosts | grep "host.minikube.internal"
user@minikube:~$
user@minikube:~$ minikube ssh
docker@minikube:~$ cat /etc/hosts | grep host.minikube.internal 
192.168.49.1    host.minikube.internal
docker@minikube:~$ ping host.minikube.internal
PING host.minikube.internal (192.168.49.1) 56(84) bytes of data.
64 bytes from host.minikube.internal (192.168.49.1): icmp_seq=1 ttl=64 time=0.075 ms
64 bytes from host.minikube.internal (192.168.49.1): icmp_seq=2 ttl=64 time=0.067 ms

host.minikube.internal 只是 /etc/hosts 文件中的条目,因此 nslookup 无法正确解析它(nslookup 查询名称服务器 ONLY .).

docker@minikube:~$ nslookup host.minikube.internal
Server:         192.168.49.1
Address:        192.168.49.1#53

** server can't find host.minikube.internal: NXDOMAIN

我认为在某些情况下可能有帮助的唯一解决方法是将 hostAliases 添加到 Deployment/Pod 清单文件:

...
spec:
  hostAliases:
  - ip: "192.168.49.1" # minikube IP
    hostnames:
    - "host.minikube.internal" # one or more hostnames that should resolve to the above address
  containers:
  - name: dnsutils
    image: gcr.io/kubernetes-e2e-test-images/dnsutils:1.3
...

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 <select id="xxx"> SELECT di.id, di.name, di.work_type, di.updated... <where> <if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 <property name="dynamic.classpath" value="tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-