2

This question is relevant to local cluster (kubernetes 1.10+ version, Linux). After creating a StatefulSet to manage several pods, I met a use case that requires setting up FQDN identity for the pods.

For instance, I wish to have the first pod with FQDN identity of <some-statefulset>-0.<some-subdomain>.default.svc.cluster.local. Desired behavior can be achieved by adding <IP-address> <some-statefulset>-0.<some-subdomain>.default.svc.cluster.local into /etc/hosts file, but I want to have the FQDN to be identified automatically in the local cluster without changing the /etc/hosts file.

Not sure whether I need to enable some settings when starting the local cluster.

jtee
  • 55
  • 1
  • 2
  • 9
  • 1
    Are you talking about being able to access them internally to the cluster, or from outside? When you use a ``StatefulSet`` you usually want to have a headless service with it. This will provide you DNS names for accessing them within the cluster. See https://kubernetes.io/docs/concepts/services-networking/service/#headless-services and https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#srv-records – Graham Dumpleton Apr 11 '18 at 00:20
  • I updated the question with a FQDN example. I did set up a headless service that has the same name as the pod's subdomain, but I still not able to check the hostname using nslookup. – jtee Apr 11 '18 at 00:24
  • 1
    If you have a DNS deployed for your Kubernetes cluster, you should already be able to use ``my-pod-0.my-svc.my-namespace.svc.cluster.local``. Does that at least work? Can you show a concrete example of the FQDN you have already tried? If have internal DNS working it should work without mucking around with ``/etc/hosts``. – Graham Dumpleton Apr 11 '18 at 01:31
  • Sorry for late reply. The FQDN I tried (`some-statefulset-0.some-service.default.svc.cluster.local`) has exactly the same format as the one you suggested, but I am not able to use it. My guess is `kube-dns` add-on didn't set up correctly on local cluster. I went over this [tutorial](https://kubernetes.io/docs/tasks/administer-cluster/dns-debugging-resolution/), but found out that some necessary steps failed. I will continue working at the direction suggested by the tutorial, and post my findings if I am able to answer my own question. Thank you very much for the help! – jtee Apr 11 '18 at 21:06
  • Was your use case related to bypassing proxy for internal requests ? – Saurav Pathak Feb 08 '23 at 16:16

2 Answers2

1

By default the cluster.local is the internal domain. To reach service from pods within the cluster,

svc_name.namespace_name.cluster.local

Sandy
  • 946
  • 11
  • 14
  • 1
    This doesn't answer the question at all. The question is about to get the pod with the domain configured automatically so that the `hostname --domain` command from the pod outputs something. – ZedTuX Jul 01 '20 at 07:11
0

Take a look at hostname and subdomain in the pod spec.

https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pod-s-hostname-and-subdomain-fields

Martín Coll
  • 3,368
  • 3
  • 37
  • 52