Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding nameservers to kubernetes

Tags:

dns

kubernetes

I'm using Kubernetes v1.0.6 on AWS that has been deployed using kube-up.sh.
Cluster is using kube-dns.

$ kubectl get svc kube-dns --namespace=kube-system
NAME       LABELS                                                                           SELECTOR           IP(S)       PORT(S)
kube-dns   k8s-app=kube-dns,kubernetes.io/cluster-service=true,kubernetes.io/name=KubeDNS   k8s-app=kube-dns   10.0.0.10   53/UDP

Which works fine.

$ kubectl exec busybox -- nslookup kubernetes.default
Server:    10.0.0.10
Address 1: 10.0.0.10 ip-10-0-0-10.eu-west-1.compute.internal

Name:      kubernetes.default
Address 1: 10.0.0.1 ip-10-0-0-1.eu-west-1.compute.internal

This is the resolv.conf of a pod.

$ kubectl exec busybox -- cat /etc/resolv.conf
nameserver 10.0.0.10
nameserver 172.20.0.2
search default.svc.cluster.local svc.cluster.local cluster.local eu-west-1.compute.internal

Is it possible to have the containers use an additional nameserver?

I have a secondary DNS based service discovery Oon let's say 192.168.0.1) that I would like my kubernetes containers to be able to use for dns resolution.

ps. A kubernetes 1.1 solution would also be acceptable :)

Thank you very much in advance, George

like image 605
George Antoniadis Avatar asked Oct 21 '15 13:10

George Antoniadis


People also ask

How is DNS handled in Kubernetes?

Kubernetes DNS schedules a DNS Pod and Service on the cluster, and configures the kubelets to tell individual containers to use the DNS Service's IP to resolve DNS names. Every Service defined in the cluster (including the DNS server itself) is assigned a DNS name.

What is Kubedns in Kubernetes?

kube-dns is the authoritative name server for the cluster domain (cluster. local) and it resolves external names recursively. Short names that are not fully qualified, such as myservice , are completed first with local search paths.

Why we need external DNS in Kubernetes?

Kubernetes ExternalDNS provides a solution. It sets up DNS records at DNS providers external to Kubernetes such that Kubernetes services are discoverable via the external DNS providers, and allows the controlling of DNS records to be done dynamically, in a DNS provider agnostic way.


2 Answers

The DNS addon README has some details on this. Basically, the pod will inherit the resolv.conf setting of the node it is running on, so you could add your extra DNS server to the nodes' /etc/resolv.conf. The kubelet also takes a --resolv-conf argument that may provide a more explicit way for you to inject the extra DNS server. I don't see that flag documented anywhere yet, however.

like image 75
rwehner Avatar answered Nov 06 '22 03:11

rwehner


In Kuberenetes (probably) 1.2 we'll be moving to a model where nameservers are assumed to be fungible. There are too many resolvers that break when different nameservers serve different subsets of DNS, and there is no real specification here that we can point to.

In other words, we'll start dropping the host's nameserver records from the container's merged resolv.conf and making our own DNS server the only nameserver line. Our DNS will be able to forward requests to upstream nameservers.

like image 20
Tim Hockin Avatar answered Nov 06 '22 04:11

Tim Hockin