DNS
1.1 Name Resolution
1.1.1 Within One Namespace
When the service web-service and test pod are in the same namespace.
curl http://web-service
1.1.2 Separate in Two Namespaces
1.1.3 Full Qualified Domain Name
For service:
curl http://web-service.app.svc or curl http://web-service.app.cluster.local
For pod
curl http://10-244-2-5.app.pod or curl http:// http://10-244-2-5.app.pod.cluster.local
10-244-2-5 is the a dashed name of the pod IP.
1.2 CoreDNS
CoreDNS chains plugins. Each plugin performs a DNS function, such as Kubernetes service discovery, prometheus metrics, rewriting queries, or just serving from zone files. And many more.
Prior to version v1.12 the DNS implemented by kubernetes was known as kube-dns. With Kubernetes version 1.12 the recommended DNS server is CoreDNS.
Reference:
https://coredns.io/
1.2.1 Installation
The CoreDNS server is deployed as a POD in the kube-system namespace in the kubernetes cluster. Well they are deployed as two pods for redundancy, as part of a replicaset. They are actually a replicaset within a deployment. But it doesn’t really matter.
After the CoreDNS pods are installed, next step is for other pods to point to the coreDNS server. When we deploy CoreDNS solution, it also creates a service to make it available to other components within a cluster. The service is named as kube-dns by default. The IP address of this service is configured as nameserver on the PODs. You don’t have to configure this yourself. The DNS configurations on PODs are done by kubernetes kubelet automatically when the PODs are created. The CoreDNS service IP is configured as follows
In addition to pointing to CoreDNS server, pod’s /etc/resolv.conf also include search entries for services.
So that you can use just web-service, or web-service.default or web-service.default.svc or web service.default.svc.cluster.local.
Try:
host web-service
web-service.default.svc.cluster.local 10.244.2.5
But this doesn’t apply to pods. You need to use fully qualified domain name of pod.
1.2.2 Configuration
CoreDNS requires a configuration file. Kubernetes uses a file named Corefile located at /etc/coredns. Within this file you have a number of plugins configured.
Also note that this core file is passed into the pod has a configMap object. That way if you need to modify this configuration you can edit the ConfigMap object.
1.2.3 Plugins
1.2.3.1 kubernetes
This plugin implements the Kubernetes DNS-Based Service Discovery Specification and pod name resolution. CoreDNS running the kubernetes plugin can be used as a replacement for kube-dns in a kubernetes cluster.
It has multiple options (see the sample in Configuration):
- The pods option, is what is responsible for creating a record for PODs in the cluster, a record being created for each POD by converting their IPs into a dashed format that's disabled by default. But it can be enabled with this option.
Reference:
https://coredns.io/plugins/kubernetes/
1.2.3.2 Proxy
In the sample in Configuration, any record that this DNS server can’t solve, for example say a POD tries to reach www.google.com, use host’s resolv.conf’s nameservers.
The proxy has support for multiple backends. The load balancing features include multiple policies, health checks, and failovers. If all hosts fail their health check the proxy plugin will fail back to randomly selecting a target and sending packets to it.
Reference:
https://coredns.io/plugins/proxy/