如何使用minikube的DNS?

8
我该如何使用minikube(集群)的DNS? 我想收到所选无头服务所有pod关联的所有IP地址,但不想将其暴露在集群外部。 我目前正在创建后端层。
如以下答案所述:什么是无头服务,它是做什么的/完成了什么,以及一些合法的用例是什么? “DNS服务器将为服务返回多个A记录,每个记录指向支持该服务的单个pod的IP。”
因此,后端层中的pod可以相互通信。
我无法使用dig命令。 在minikube中未安装它。 最终我该如何安装它? 没有可用的apt。
我希望这更准确地解释了我想要实现的内容。
2个回答

8

您提到想要获取与所选服务名称相关联的Pod的IP地址,以测试无头服务的工作原理。

仅供测试目的,您可以使用端口转发。您可以将流量从本地机器转发到群集中的dns pod。要执行此操作,需要运行:

kubectl port-forward svc/kube-dns -n kube-system 5353:53

这将在您的主机上公开kubs-dns服务。您所需要做的就是使用dig命令(或其他替代命令)查询dns服务器。

dig @127.0.0.1 -p 5353 +tcp +short <service>.<namespace>.svc.cluster.local

您也可以从集群内部测试您的DNS,例如通过运行具有交互式 shell 的 pod 进行测试:
kubectl run --image tutum/dnsutils dns -it --rm -- bash
root@dns:/# dig +search <service>

如果有帮助,请告诉我。


无需进行端口转发。运行dnsutils pod并在其中使用dig命令即可完成任务。 - hal

-1

kubernetes/minikube问题4397所示:

容器默认没有IP地址。
您需要使用minikube serviceminikube tunnel来获取端点信息。

请参见“hello-minikube/创建服务”:

By default, the Pod is only accessible by its internal IP address within the Kubernetes cluster.

To make the hello-node Container accessible from outside the Kubernetes virtual network, you have to expose the Pod as a Kubernetes Service.

Expose the Pod to the public internet using the kubectl expose command:

kubectl expose deployment hello-node --type=LoadBalancer --port=8080

The --type=LoadBalancer flag indicates that you want to expose your Service outside of the cluster.

View the Service you just created:

kubectl get services

NAME         TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
hello-node   LoadBalancer   10.108.144.78   <pending>     8080:30369/TCP   21s
kubernetes   ClusterIP      10.96.0.1       <none>        443/TCP      

On Minikube, the LoadBalancer type makes the Service accessible through the minikube service command.

Run the following command:

minikube service hello-node

@hal 我在回答中提到的Create service部分是关于pod内部IP的。 - VonC

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接