我遵循this kubernetes tutorial来设置DNS service
并将两个单独的kubernetes pods
连接在一起。一个应该用作网关,正在侦听端口80,另一个正在侦听端口90。
当我使用它们的节点IP,curl 10.32.0.24
和curl 10.32.0.25:90
时,我可以访问它们。但是,我不知道如何通过我的DNS服务访问它们。什么是URL
?Namespace
是default
,这是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 namespacebar
. A Pod running in namespacebar
can look up this service by simply doing a DNS query forfoo
. A Pod running in namespacequux
can look up this service by doing a DNS query forfoo.bar
.
因此,群集中资源的DNS名称仅存在于其中。
您通过NodeIP从外部网络调用该服务:
curl 10.32.0.24
和curl 10.32.0.25:90
。那是正确的方法。如果要使用DNS名称从外部连接到群集,则应使用任何其他DNS服务将名称指向您的群集节点或LoadBalancer。我建议您使用
Service
对象公开您的应用程序。这是一些有关它的文章:ways to connect,use a Service to access applications.
关于dns - kubernetes集群中的DNS地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49971397/