在Kubernetes中检索服务的全名 [英] Retrieve the full name of a service in Kubernetes
问题描述
默认情况下,根据 k8s文档,为服务分配了一个DNS A记录,格式为my-svc.my-namespace.svc.cluster-domain.example
.
By default,according to k8s documentation, Services are assigned a DNS A record for a name of the form my-svc.my-namespace.svc.cluster-domain.example
.
是否有用于检索服务全名的命令?
Is there a command to retrieve the full name of a service?
推荐答案
您可以从任何Pod进行DNS查询,您将获得FQDN.
You can do a DNS query from any pod and you would get the FQDN.
# nslookup api-server
Server: 10.96.0.10
Address: 10.96.0.10#53
Name: api-server.default.svc.cluster.local
Address: 10.104.225.18
root@api-server-6ff8c8b9c-6pgkb:/#
cluster-domain.example
只是文档中的一个示例. cluster.local
是分配的默认群集域.因此,默认情况下任何服务的FQDN为<service-name>.<namespace>.svc.cluster.local
.
cluster-domain.example
is just a example in the documentation. cluster.local
is the default cluster domain assigned. So the FQDN of any service by default would be <service-name>.<namespace>.svc.cluster.local
.
您不需要使用FQDN来访问服务-对于相同名称空间中的服务,只需服务名称就足够了.对于其他名称空间中的服务,<service-name>.<namespace>
就足够了,因为kubernetes会自动设置DNS搜索域.
You don't need to use the FQDN to access services - for services in same namespace, just the service name would be enough. For services in other namespaces, <service-name>.<namespace>
would be enough as kubernetes would automatically set up the DNS search domains.
这篇关于在Kubernetes中检索服务的全名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!