kubernetes 集群中的 DNS 地址
A DNS address within kubernetes cluster
我关注 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 服务在集群内工作,并为 pods 提供 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.24
和 curl 10.32.0.25:90
。这是正确的方法。如果您想使用 DNS 名称从外部连接到集群,您应该使用任何其他 DNS 服务将名称指向您的集群节点或 LoadBalancer。
我建议您使用 Service
对象来公开您的应用程序。这是一些关于它的文章:ways to connect, use a Service to access applications.
我关注 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 服务在集群内工作,并为 pods 提供 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.