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.

120 lines
5.9 KiB

  1. K8s DNS stack by Kargo
  2. ======================
  3. For K8s cluster nodes, kargo 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. Note, custom ``ndots`` values affect only the dnsmasq daemon set (explained below).
  10. While the kubedns has the ``ndots=5`` hardcoded, which is not recommended due to
  11. [DNS performance reasons](https://github.com/kubernetes/kubernetes/issues/14051).
  12. You can use config maps for the kubedns app to workaround the issue, which is
  13. yet in the Kargo scope.
  14. Additional search (sub)domains may be defined in the ``searchdomains``
  15. and ``ndots`` vars. And additional recursive DNS resolvers in the `` upstream_dns_servers``,
  16. ``nameservers`` vars. Intranet/cloud provider DNS resolvers should be specified
  17. in the first place, followed by external resolvers, for example:
  18. ```
  19. skip_dnsmasq: true
  20. nameservers: [8.8.8.8]
  21. upstream_dns_servers: [172.18.32.6]
  22. ```
  23. or
  24. ```
  25. skip_dnsmasq: false
  26. upstream_dns_servers: [172.18.32.6, 172.18.32.7, 8.8.8.8, 8.8.8.4]
  27. ```
  28. The vars are explained below. For the early cluster deployment stage, when there
  29. is yet K8s cluster and apps exist, a user may expect local repos to be
  30. accessible via authoritative intranet resolvers. For that case, if none custom vars
  31. was specified, the default resolver is set to either the cloud provider default
  32. or `8.8.8.8`. And domain is set to the default ``dns_domain`` value as well.
  33. Later, the nameservers will be reconfigured to the DNS service IP that Kargo
  34. configures for K8s cluster.
  35. Also note, existing records will be purged from the `/etc/resolv.conf`,
  36. including resolvconf's base/head/cloud-init config files and those that come from dhclient.
  37. This is required for hostnet pods networking and for [kubelet to not exceed search domains
  38. limits](https://github.com/kubernetes/kubernetes/issues/9229).
  39. Instead, new domain, search, nameserver records and options will be defined from the
  40. aforementioned vars:
  41. * Superseded via dhclient's DNS update hook.
  42. * Generated via cloud-init (CoreOS only).
  43. * Statically defined in the `/etc/resolv.conf`, if none of above is applicable.
  44. * Resolvconf's head/base files are disabled from populating anything into the
  45. `/etc/resolv.conf`.
  46. DNS configuration details
  47. -------------------------
  48. Here is an approximate picture of how DNS things working and
  49. being configured by Kargo ansible playbooks:
  50. ![Image](figures/dns.jpeg?raw=true)
  51. Note that an additional dnsmasq daemon set is installed by Kargo
  52. by default. Kubelet will configure DNS base of all pods to use the
  53. given dnsmasq cluster IP, which is defined via the ``dns_server`` var.
  54. The dnsmasq forwards requests for a given cluster ``dns_domain`` to
  55. Kubedns's SkyDns service. The SkyDns server is configured to be an
  56. authoritative DNS server for the given cluser domain (and its subdomains
  57. up to ``ndots:5`` depth). Note: you should scale its replication controller
  58. up, if SkyDns chokes. These two layered DNS forwarders provide HA for the
  59. DNS cluster IP endpoint, which is a critical moving part for Kubernetes apps.
  60. Nameservers are as well configured in the hosts' ``/etc/resolv.conf`` files,
  61. as the given DNS cluster IP merged with ``nameservers`` values. While the
  62. DNS cluster IP merged with the ``upstream_dns_servers`` defines additional
  63. nameservers for the aforementioned nsmasq daemon set running on all hosts.
  64. This mitigates existing Linux limitation of max 3 nameservers in the
  65. ``/etc/resolv.conf`` and also brings an additional caching layer for the
  66. clustered DNS services.
  67. You can skip the dnsmasq daemon set install steps by setting the
  68. ``skip_dnsmasq: true``. This may be the case, if you're fine with
  69. the nameservers limitation. Sadly, there is no way to work around the
  70. search domain limitations of a 256 chars and 6 domains. Thus, you can
  71. use the ``searchdomains`` var to define no more than a three custom domains.
  72. Remaining three slots are reserved for K8s cluster default subdomains.
  73. When dnsmasq skipped, Kargo redefines the DNS cluster IP to point directly
  74. to SkyDns cluster IP ``skydns_server`` and configures Kubelet's
  75. ``--dns_cluster`` to use that IP as well. While this greatly simplifies
  76. things, it comes by the price of limited nameservers though. As you know now,
  77. the DNS cluster IP takes a slot in the ``/etc/resolv.conf``, thus you can
  78. specify no more than a two nameservers for infra and/or external use.
  79. Those may be specified either in ``nameservers`` or ``upstream_dns_servers``
  80. and will be merged together with the ``skydns_server`` IP into the hots'
  81. ``/etc/resolv.conf``.
  82. Limitations
  83. -----------
  84. * Kargo has yet ways to configure Kubedns addon to forward requests SkyDns can
  85. not answer with authority to arbitrary recursive resolvers. This task is left
  86. for future. See [official SkyDns docs](https://github.com/skynetservices/skydns)
  87. for details.
  88. * There is
  89. [no way to specify a custom value](https://github.com/kubernetes/kubernetes/issues/33554)
  90. for the SkyDNS ``ndots`` param via an
  91. [option for KubeDNS](https://github.com/kubernetes/kubernetes/blob/master/cmd/kube-dns/app/options/options.go)
  92. add-on, while SkyDNS supports it though. Thus, DNS SRV records may not work
  93. as expected as they require the ``ndots:7``.
  94. * the ``searchdomains`` have a limitation of a 6 names and 256 chars
  95. length. Due to default ``svc, default.svc`` subdomains, the actual
  96. limits are a 4 names and 239 chars respectively.
  97. * the ``nameservers`` have a limitation of a 3 servers, although there
  98. is a way to mitigate that with the ``upstream_dns_servers``,
  99. see below. Anyway, the ``nameservers`` can take no more than a two
  100. custom DNS servers because of one slot is reserved for a Kubernetes
  101. cluster needs.