Mac上Minikube中ExternalName的DNS解析 [英] DNS resolution of ExternalName in Minikube on Mac

查看:269
本文介绍了Mac上Minikube中ExternalName的DNS解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我在virtualbox中的minikube设置连接到在Mac上的docker中运行的postgres容器.但是我遇到了DNS解决问题.

I'm trying to connect to a postgres container running in docker on my mac, from my minikube setup in virtualbox. But I'm running into dns resolve issues.

我将PostgreSQL作为容器运行在Docker上

I'm running postgres as a container on docker

> docker ps                                                                                                                                                                                                                                                                                   
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
a794aca3a6dc        postgres            "docker-entrypoint.s…"   3 days ago          Up 3 days           0.0.0.0:5432->5432/tcp   postgres

在Mac/VirtualBox/Minikube设置上,我创建服务

On my Mac / VirtualBox / Minikube setup I create a service

kind: Service
apiVersion: v1
metadata:
  name: postgres-svc
spec:
  type: ExternalName
  externalName: 10.0.2.2
  ports:
    - port: 5432

10.0.2.2是主机接口的别名(找到此信息

10.0.2.2 is alias to host interface (found this information here)

> kubectl get service --all-namespaces
NAMESPACE     NAME                                             TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)                  AGE
default       kubernetes                                       ClusterIP      10.96.0.1        <none>        443/TCP                  21d
hazelnut      postgres-svc                                     ExternalName   <none>           10.0.2.2      5432/TCP                 27m
kube-system   kube-dns                                         ClusterIP      10.96.0.10       <none>        53/UDP,53/TCP,9153/TCP   21d
kube-system   kubernetes-dashboard                             ClusterIP      10.108.181.235   <none>        80/TCP                   19d
kube-system   tiller-deploy                                    ClusterIP      10.101.218.56    <none>        44134/TCP                20d

(我们的命名空间为hazelnut,不要问:-)

(our namespace is hazelnut, don't ask:-)

在我的部署中,如果我直接连接到10.0.2.2,它将毫无问题地连接到postgres,但是如果我尝试解析kubernetes服务的主机名,它将无法正常工作. 因此,这不是防火墙或路由问题,纯dns.

In my deployment, if I connect to 10.0.2.2 directly, it connects to the postgres without issue, but if I try to resolve the hostname of the kubernetes service it doesnt' work. So it's not a firewall or routing issue, pure dns.

我尝试了postgres-svc.hazelnut.cluster.localpostgres-svcpostgres-svc.hazelnut.svc.cluster.localpostgres-svc.hazelnut全部生成NXDOMAIN

I've tried postgres-svc.hazelnut.cluster.local, postgres-svc, postgres-svc.hazelnut.svc.cluster.local, postgres-svc.hazelnut all resulting in NXDOMAIN

kubernetes.default正常工作.

> nslookup kubernetes.default
Server:     10.96.0.10
Address:    10.96.0.10#53

Name:   kubernetes.default.svc.cluster.local
Address: 10.96.0.1

在此帖子中,他们提到使用kube-dns应该解决它,但我正在使用它,但无济于事

In this post they mention that using kube-dns should solve it, but I'm using it and to no avail

> kubectl get svc --namespace=kube-system
NAME                   TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                  AGE
kube-dns               ClusterIP   10.96.0.10       <none>        53/UDP,53/TCP,9153/TCP   21d
...

您知道如何使它正常工作吗?

Any idea how I can get this to work properly?

推荐答案

对于

For the ExternalName service type the externalName should be FQDN, not an IP address, e.g.

kind: Service
...
metadata:
  name: postgres-svc
spec:
  type: ExternalName
  externalName: mydb.mytestdomain

主机应能够解析该FQDN的名称.您可以在Mac主机的/etc/hosts中添加一条记录来实现:

The host machine should be able to resolve the name of that FQDN. You might add a record into the /etc/hosts at the Mac host to achieve that:

10.0.0.2    mydb.mytestdomain

实际上,coredns使用在Minikube VM的/etc/resolv.conf中配置的名称解析器.它指向VirtualBox NAT网络(10.0.2.3)中的名称解析器.反过来,VirtualBox依靠通过本地/etc/hosts文件查找的主机名解析机制.

Actually, coredns uses name resolver configured in the /etc/resolv.conf in the Minikube VM. It points to the name resolver in the VirtualBox NAT Network (10.0.2.3). In turn, VirtualBox relies on the host name resolving mechanism that looks through the local /etc/hosts file.

经过测试: MacOS 10.14.3, VBox 6.0.10, kubernetes 1.15.0, minikube 1.2.0, coredns

Tested for: MacOS 10.14.3, VBox 6.0.10, kubernetes 1.15.0, minikube 1.2.0, coredns

这篇关于Mac上Minikube中ExternalName的DNS解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆