如以下答案所述:什么是无头服务,它是做什么的/完成了什么,以及一些合法的用例是什么? “DNS服务器将为服务返回多个A记录,每个记录指向支持该服务的单个pod的IP。”
因此,后端层中的pod可以相互通信。
我无法使用dig命令。 在minikube中未安装它。 最终我该如何安装它? 没有可用的apt。
我希望这更准确地解释了我想要实现的内容。
您提到想要获取与所选服务名称相关联的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
kubectl run --image tutum/dnsutils dns -it --rm -- bash
root@dns:/# dig +search <service>
如果有帮助,请告诉我。
容器默认没有IP地址。
您需要使用minikube service
或minikube 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