It may be required for some applications to be aware of the cluster domain.
This information is not exposed directly, the cluster domain is a kubelet property, https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet/
--cluster-domain string
However, if you set the subdomain
field in a Pod, then you are able to access the FQDN directly from the Pod
The Pod spec also has an optional subdomain field which can be used to indicate that the pod is part of sub-group of the namespace. For example, a Pod with spec.hostname set to "foo", and spec.subdomain set to "bar", in namespace "my-namespace", will have its hostname set to "foo" and its fully qualified domain name (FQDN) set to "foo.bar.my-namespace.svc.cluster.local" (once more, as observed from within the Pod).
apiVersion: v1
kind: Pod
metadata:
name: fqdn-pod
spec:
subdomain: x
containers:
- name: my-container
image: busybox:stable
command: ["sleep", "infinity"]
$ kubectl exec -it fqdn-pod -- hostname -f
fqdn-pod.x.default.svc.cluster.local