gpt4 book ai didi

kubernetes - 除非给出完整的 FQDN,否则指向其他命名空间中服务的 ExternalName 不会解析

转载 作者:行者123 更新时间:2023-12-02 12:12:57 25 4
gpt4 key购买 nike

我在命名空间 A 中有一个类型为 ClusterIP 的服务 my-service,它可以对几个 pod 进行负载均衡。我想在命名空间 B 中创建另一个类型为 ExternalName 的服务,它指向命名空间 A 中的 my-service

我创建了以下 YAML:

apiVersion: v1
kind: Service
metadata:
name: my-service
namespace: B
spec:
type: ExternalName
externalName: my-service.A

如果我执行到在命名空间 B 中运行的 pod 并执行:

# ping my-service
ping: my-service: Name or service not known

但是,如果我将上面 YAML 中的 externalName 更改为以下内容:

apiVersion: v1
kind: Service
metadata:
name: my-service
namespace: B
spec:
type: ExternalName
externalName: my-service.A.svc.cluster.local <--- full FQDN here

事情按预期进行。此外,如果我直接从命名空间 B 中的 pod ping my-service 它正在被解析:

# ping my-service.A
PING my-service.A.svc.cluster.local (10.0.80.133) 56(84) bytes of data.

为什么 my-service.A 在 ExternalName Service 中没有解析为 my-service.A.svc.cluster.local

我的 K8s 版本是 1.14.8 并且使用了 CoreDNS。

最佳答案

基于 kubernetes documentationokd这就是它应该如何工作的

Kubernetes DNS schedules a DNS Pod and Service on the cluster, and configures the kubelets to tell individual containers to use the DNS Service’s IP to resolve DNS names.

What things get DNS names?

Every Service defined in the cluster (including the DNS server itself) is assigned a DNS name. By default, a client Pod’s DNS search list will include the Pod’s own namespace and the cluster’s default domain.


Services are assigned a DNS A or AAAA record, depending on the IP family of the service, for a name of the form my-svc.my-namespace.svc.cluster-domain.example. This resolves to the cluster IP of the Service.


当你想使用my-service时,kubedns有日志。A

I0306 09:44:32.424126       1 logs.go:41] skydns: incomplete CNAME chain from "my-service.dis.": rcode 3 is not equal to success

这就是为什么您需要服务的完整路径,在您的情况下是

my-service.A.svc.cluster.local

因为

Using an external domain name service tells the system that the DNS name in the externalName field (example.domain.name in the previous example) is the location of the resource that backs the service. When a DNS request is made against the Kubernetes DNS server, it returns the externalName in a CNAME record telling the client to look up the returned name to get the IP address.


我希望这能回答您的问题。如果您还有其他问题,请告诉我。

关于kubernetes - 除非给出完整的 FQDN,否则指向其他命名空间中服务的 ExternalName 不会解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60551378/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com