dns - kubernetes集群中的DNS地址

标签 dns kubernetes cluster-computing

我遵循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/

相关文章:

python - 从主机名中提取域名

kubernetes - 在K8s中查找pod存在于哪些节点

Kubernetes:带有 StatefulSets 的 NFS

hadoop - Hadoop上的Mahout k-means

.htaccess RewriteRule subsubdomain.subdomain.domain.tld 到 subdomain.domain.tld/subsubdomain

.htaccess - 将根(且仅根)URL 重定向到另一个域?

Azure DNS 区域 : What should I do so that my custom DNS will be used instead of the Azure DNS with IP address 168. 63.129.16?

kubernetes pod的扩展资源

cloud - 购买集群/网格/云时间?

mysql - 设置 MySQL/MariaDB galera 集群时出现问题