You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
7.4 KiB

  1. K8s DNS stack by Kubespray
  2. ======================
  3. For K8s cluster nodes, Kubespray configures a [Kubernetes DNS](http://kubernetes.io/docs/admin/dns/)
  4. [cluster add-on](http://releases.k8s.io/master/cluster/addons/README.md)
  5. to serve as an authoritative DNS server for a given ``dns_domain`` and its
  6. ``svc, default.svc`` default subdomains (a total of ``ndots: 5`` max levels).
  7. Other nodes in the inventory, like external storage nodes or a separate etcd cluster
  8. node group, considered non-cluster and left up to the user to configure DNS resolve.
  9. DNS variables
  10. =============
  11. There are several global variables which can be used to modify DNS settings:
  12. #### ndots
  13. ndots value to be used in ``/etc/resolv.conf``
  14. It is important to note that multiple search domains combined with high ``ndots``
  15. values lead to poor performance of DNS stack, so please choose it wisely.
  16. The dnsmasq DaemonSet can accept lower ``ndots`` values and return NXDOMAIN
  17. replies for [bogus internal FQDNS](https://github.com/kubernetes/kubernetes/issues/19634#issuecomment-253948954)
  18. before it even hits the kubedns app. This enables dnsmasq to serve as a
  19. protective, but still recursive resolver in front of kubedns.
  20. #### searchdomains
  21. Custom search domains to be added in addition to the cluster search domains (``default.svc.{{ dns_domain }}, svc.{{ dns_domain }}``).
  22. Most Linux systems limit the total number of search domains to 6 and the total length of all search domains
  23. to 256 characters. Depending on the length of ``dns_domain``, you're limitted to less then the total limit.
  24. Please note that ``resolvconf_mode: docker_dns`` will automatically add your systems search domains as
  25. additional search domains. Please take this into the accounts for the limits.
  26. #### nameservers
  27. This variable is only used by ``resolvconf_mode: host_resolvconf``. These nameservers are added to the hosts
  28. ``/etc/resolv.conf`` *after* ``upstream_dns_servers`` and thus serve as backup nameservers. If this variable
  29. is not set, a default resolver is chosen (depending on cloud provider or 8.8.8.8 when no cloud provider is specified).
  30. #### upstream_dns_servers
  31. DNS servers to be added *after* the cluster DNS. Used by all ``resolvconf_mode`` modes. These serve as backup
  32. DNS servers in early cluster deployment when no cluster DNS is available yet. These are also added as upstream
  33. DNS servers used by ``dnsmasq`` (when deployed with ``dns_mode: dnsmasq_kubedns``).
  34. DNS modes supported by Kubespray
  35. ============================
  36. You can modify how Kubespray sets up DNS for your cluster with the variables ``dns_mode`` and ``resolvconf_mode``.
  37. ## dns_mode
  38. ``dns_mode`` configures how Kubespray will setup cluster DNS. There are four modes available:
  39. #### dnsmasq_kubedns (default)
  40. This installs an additional dnsmasq DaemonSet which gives more flexibility and lifts some
  41. limitations (e.g. number of nameservers). Kubelet is instructed to use dnsmasq instead of kubedns/skydns.
  42. It is configured to forward all DNS queries belonging to cluster services to kubedns/skydns. All
  43. other queries are forwardet to the nameservers found in ``upstream_dns_servers`` or ``default_resolver``
  44. #### kubedns
  45. This does not install the dnsmasq DaemonSet and instructs kubelet to directly use kubedns/skydns for
  46. all queries.
  47. #### manual
  48. This does not install dnsmasq or kubedns, but allows you to specify
  49. `manual_dns_server`, which will be configured on nodes for handling Pod DNS.
  50. Use this method if you plan to install your own DNS server in the cluster after
  51. initial deployment.
  52. #### none
  53. This does not install any of dnsmasq and kubedns/skydns. This basically disables cluster DNS completely and
  54. leaves you with a non functional cluster.
  55. ## resolvconf_mode
  56. ``resolvconf_mode`` configures how Kubespray will setup DNS for ``hostNetwork: true`` PODs and non-k8s containers.
  57. There are three modes available:
  58. #### docker_dns (default)
  59. This sets up the docker daemon with additional --dns/--dns-search/--dns-opt flags.
  60. The following nameservers are added to the docker daemon (in the same order as listed here):
  61. * cluster nameserver (depends on dns_mode)
  62. * content of optional upstream_dns_servers variable
  63. * host system nameservers (read from hosts /etc/resolv.conf)
  64. The following search domains are added to the docker daemon (in the same order as listed here):
  65. * cluster domains (``default.svc.{{ dns_domain }}``, ``svc.{{ dns_domain }}``)
  66. * content of optional searchdomains variable
  67. * host system search domains (read from hosts /etc/resolv.conf)
  68. The following dns options are added to the docker daemon
  69. * ndots:{{ ndots }}
  70. * timeout:2
  71. * attempts:2
  72. For normal PODs, k8s will ignore these options and setup its own DNS settings for the PODs, taking
  73. the --cluster_dns (either dnsmasq or kubedns, depending on dns_mode) kubelet option into account.
  74. For ``hostNetwork: true`` PODs however, k8s will let docker setup DNS settings. Docker containers which
  75. are not started/managed by k8s will also use these docker options.
  76. The host system name servers are added to ensure name resolution is also working while cluster DNS is not
  77. running yet. This is especially important in early stages of cluster deployment. In this early stage,
  78. DNS queries to the cluster DNS will timeout after a few seconds, resulting in the system nameserver being
  79. used as a backup nameserver. After cluster DNS is running, all queries will be answered by the cluster DNS
  80. servers, which in turn will forward queries to the system nameserver if required.
  81. #### host_resolvconf
  82. This activates the classic Kubespray behaviour that modifies the hosts ``/etc/resolv.conf`` file and dhclient
  83. configuration to point to the cluster dns server (either dnsmasq or kubedns, depending on dns_mode).
  84. As cluster DNS is not available on early deployment stage, this mode is split into 2 stages. In the first
  85. stage (``dns_early: true``), ``/etc/resolv.conf`` is configured to use the DNS servers found in ``upstream_dns_servers``
  86. and ``nameservers``. Later, ``/etc/resolv.conf`` is reconfigured to use the cluster DNS server first, leaving
  87. the other nameservers as backups.
  88. Also note, existing records will be purged from the `/etc/resolv.conf`,
  89. including resolvconf's base/head/cloud-init config files and those that come from dhclient.
  90. #### none
  91. Does nothing regarding ``/etc/resolv.conf``. This leaves you with a cluster that works as expected in most cases.
  92. The only exception is that ``hostNetwork: true`` PODs and non-k8s managed containers will not be able to resolve
  93. cluster service names.
  94. Limitations
  95. -----------
  96. * Kubespray has yet ways to configure Kubedns addon to forward requests SkyDns can
  97. not answer with authority to arbitrary recursive resolvers. This task is left
  98. for future. See [official SkyDns docs](https://github.com/skynetservices/skydns)
  99. for details.
  100. * There is
  101. [no way to specify a custom value](https://github.com/kubernetes/kubernetes/issues/33554)
  102. for the SkyDNS ``ndots`` param via an
  103. [option for KubeDNS](https://github.com/kubernetes/kubernetes/blob/master/cmd/kube-dns/app/options/options.go)
  104. add-on, while SkyDNS supports it though.
  105. * the ``searchdomains`` have a limitation of a 6 names and 256 chars
  106. length. Due to default ``svc, default.svc`` subdomains, the actual
  107. limits are a 4 names and 239 chars respectively.
  108. * the ``nameservers`` have a limitation of a 3 servers, although there
  109. is a way to mitigate that with the ``upstream_dns_servers``,
  110. see below. Anyway, the ``nameservers`` can take no more than a two
  111. custom DNS servers because of one slot is reserved for a Kubernetes
  112. cluster needs.