I work on a variety of different Kubernetes clusters in a variety of different clouds. My problem here is that it's difficult to discover what the FQDN for a kubernetes Service is as different clusters have different configurations.
Is there a way via kubectl
to get the FQDN for a service? I don't see it when I use kubectl describe svc
.
It should be something like my-svc.my-namespace.svc.cluster-domain.example
according to this article: https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/
How do I figure out the cluster-domain.example
part of the FQDN? I could just go with my-svc.my-namespace.svc
and have it resolve, but I'd like to use the FQDN if I can.
The cluster domain is defined in configMap named coredns
in kube-system
namespace. This configMap is the source of truth and used by coreDNS.In the below Configmap cluster domain is cluster.local
kubectl get cm coredns -n kube-system -o yaml
apiVersion: v1
data:
Corefile: |
.:53 {
errors
health {
lameduck 5s
}
ready
kubernetes cluster.local in-addr.arpa ip6.arpa {
pods insecure
fallthrough in-addr.arpa ip6.arpa
ttl 30
}
prometheus :9153
forward . /etc/resolv.conf
cache 30
loop
reload
loadbalance
}
kind: ConfigMap
metadata:
creationTimestamp: "2020-04-03T14:24:44Z"
name: coredns
namespace: kube-system
resourceVersion: "177"
selfLink: /api/v1/namespaces/kube-system/configmaps/coredns
uid: d00d8e5d-d089-4d7a-a1d3-4460703c23d9
The subdomain is specified via flag --cluster-domain
to kubelet
, such that kubelet
can use it as the search domain in the file /etc/resolve.conf
of containers. When searching a Service name in a Pod, the FQDN is auto-completed by settings in the file /etc/resolve.conf
.
For kube-dns
, it includes 3 containers. One of them is named kube-dns
, it has a flag -domain
which has the same value as the cluster domain.