在Kubernetes集群中使Pod DNS名称可解析 [英] Make pod DNS name resolvable in Kubernetes cluster
问题描述
名为frontend的部署的Pod通过名为frontend的服务公开.
The pods of the deployment named frontend are exposed via a service named frontend.
NAME READY STATUS RESTARTS AGE
po/frontend-b48b88789-dcxs6 1/1 Running 0 2h
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
deploy/frontend 1 1 1 1 2h
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc/frontend ClusterIP 10.106.243.125 <none> 80/TCP 2h
问题
通过busybox查询服务前端的DNS名称将返回服务ip地址. 通过busybox查询pod frontend-b48b88789-dcxs6的DNS名称无法解析.
Problem
Querying via busybox the DNS name for the service frontend returns the services ip address. Querying via busybox the DNS name for the pod frontend-b48b88789-dcxs6 doesn't resolve.
/ # nslookup frontend
Server: 10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local
Name: frontend
Address 1: 10.106.243.125 frontend.exam.svc.cluster.local
/ # nslookup frontend-b48b88789-dcxs6
Server: 10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local
nslookup: can't resolve 'frontend-b48b88789-dcxs6'
问题
要通过Kubernetes集群DNS系统解析Pod,我该怎么做?
Question
What do I have to do to make a pod resolvable via the Kubernetes clusters DNS system?
我一直在寻找答案的来源
- https://kubernetes.io/docs /tasks/administer-cluster/dns-custom-nameservers/
- https://kubernetes.io/docs /concepts/services-networking/dns-pod-service/
推荐答案
I think that if you really need this, then what you actually might be interested in is StatefulSet which provides a somewhat static way of referencing to the pods that are spinned up by it. With StatefulSet, your pods will have a predictable name like myapp-0
, myapp-1
etc. and you will be able to resolve them as ie. myapp-0.mysvc
(where mysvc
is a "governing" service for the statefulset)
可预测的名称使配置集群所需的内容更容易配置,此外,您还将获得其他好处,例如顺序扩展,持久性存储的映射或创建始终命中给定Pod(如Pod N)的服务的能力. StatefulSet,例如,您能够创建始终指向myapp-0.mysvc
pod的myapp-0
服务.
Predictable names allow for easier configuration of things that need to form a cluster, plus you get other gains like sequential scaling, mapping of persistent storage or ability to create services that always hit given pod (as in pod number N) of the StatefulSet meaning you are for example capable of creating a myapp-0
service that always points to a myapp-0.mysvc
pod.
这篇关于在Kubernetes集群中使Pod DNS名称可解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!