2
votes

Setup

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

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'

Question

What do I have to do to make a pod resolvable via the Kubernetes clusters DNS system?

Sources I have been looking for an answer

1

1 Answers

1
votes

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)

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.