gpt4 book ai didi

dns - kubernetes集群中的DNS地址

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

我遵循this kubernetes tutorial来设置DNS service并将两个单独的kubernetes pods连接在一起。一个应该用作网关,正在侦听端口80,另一个正在侦听端口90。

当我使用它们的节点IP,curl 10.32.0.24curl 10.32.0.25:90时,我可以访问它们。但是,我不知道如何通过我的DNS服务访问它们。什么是URL
Namespacedefault,这是kubectl cluster-info:的结果
Kubernetes master is running at IP_OF_MY_SERVER:6443
KubeDNS is running at IP_OF_MY_SERVER:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
我的deployment.yaml与本教程中的几乎相同:

apiVersion: v1
kind: Service
metadata:
name: default-subdomain
spec:
selector:
name: busybox
clusterIP: None
ports:
- name: foo # Actually, no port is needed.
port: 80
targetPort: 80
---
apiVersion: v1
kind: Pod
metadata:
name: busybox1
labels:
name: busybox
spec:
hostname: busybox-1
subdomain: default-subdomain
containers:
- image: time-provider
name: busybox
---
apiVersion: v1
kind: Pod
metadata:
name: busybox2
labels:
name: busybox
spec:
hostname: busybox-2
subdomain: default-subdomain
containers:
- image: gateway
name: busybox

最佳答案

Kubernetes DNS服务在集群内部工作,并为Pod(而非外部服务)提供DNS名称。
这是您使用的instruction的摘录:

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. This is best illustrated by example:

Assume a Service named foo in the Kubernetes namespace bar. A Pod running in namespace bar can look up this service by simply doing a DNS query for foo. A Pod running in namespace quux can look up this service by doing a DNS query for foo.bar.


因此,群集中资源的DNS名称仅存在于其中。
您通过NodeIP从外部网络调用该服务: curl 10.32.0.24curl 10.32.0.25:90。那是正确的方法。如果要使用DNS名称从外部连接到群集,则应使用任何其他DNS服务将名称指向您的群集节点或LoadBalancer。
我建议您使用 Service对象公开您的应用程序。这是一些有关它的文章: ways to connectuse a Service to access applications.

关于dns - kubernetes集群中的DNS地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49971397/

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