Skip to content

Instantly share code, notes, and snippets.

@aojea
Last active January 9, 2025 18:25
Show Gist options
  • Save aojea/27f47a220c46b29cc45664d5f05e9869 to your computer and use it in GitHub Desktop.
Save aojea/27f47a220c46b29cc45664d5f05e9869 to your computer and use it in GitHub Desktop.
Expose cluster domain to pods

Expose the cluster domain to Pods

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment