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.

163 lines
7.1 KiB

  1. HA endpoints for K8s
  2. ====================
  3. The following components require a highly available endpoints:
  4. * etcd cluster,
  5. * kube-apiserver service instances.
  6. The latter relies on a 3rd side reverse proxy, like Nginx or HAProxy, to
  7. achieve the same goal.
  8. Etcd
  9. ----
  10. The etcd clients (kube-api-masters) are configured with the list of all etcd peers. If the etcd-cluster has multiple instances, it's configured in HA already.
  11. Kube-apiserver
  12. --------------
  13. K8s components require a loadbalancer to access the apiservers via a reverse
  14. proxy. Kubespray includes support for an nginx-based proxy that resides on each
  15. non-master Kubernetes node. This is referred to as localhost loadbalancing. It
  16. is less efficient than a dedicated load balancer because it creates extra
  17. health checks on the Kubernetes apiserver, but is more practical for scenarios
  18. where an external LB or virtual IP management is inconvenient. This option is
  19. configured by the variable `loadbalancer_apiserver_localhost` (defaults to
  20. `True`. Or `False`, if there is an external `loadbalancer_apiserver` defined).
  21. You may also define the port the local internal loadbalancer uses by changing,
  22. `nginx_kube_apiserver_port`. This defaults to the value of
  23. `kube_apiserver_port`. It is also important to note that Kubespray will only
  24. configure kubelet and kube-proxy on non-master nodes to use the local internal
  25. loadbalancer.
  26. If you choose to NOT use the local internal loadbalancer, you will need to
  27. configure your own loadbalancer to achieve HA. Note that deploying a
  28. loadbalancer is up to a user and is not covered by ansible roles in Kubespray.
  29. By default, it only configures a non-HA endpoint, which points to the
  30. `access_ip` or IP address of the first server node in the `kube-master` group.
  31. It can also configure clients to use endpoints for a given loadbalancer type.
  32. The following diagram shows how traffic to the apiserver is directed.
  33. ![Image](figures/loadbalancer_localhost.png?raw=true)
  34. Note: Kubernetes master nodes still use insecure localhost access because
  35. there are bugs in Kubernetes <1.5.0 in using TLS auth on master role
  36. services. This makes backends receiving unencrypted traffic and may be a
  37. security issue when interconnecting different nodes, or maybe not, if those
  38. belong to the isolated management network without external access.
  39. A user may opt to use an external loadbalancer (LB) instead. An external LB
  40. provides access for external clients, while the internal LB accepts client
  41. connections only to the localhost.
  42. Given a frontend `VIP` address and `IP1, IP2` addresses of backends, here is
  43. an example configuration for a HAProxy service acting as an external LB:
  44. ```
  45. listen kubernetes-apiserver-https
  46. bind <VIP>:8383
  47. option ssl-hello-chk
  48. mode tcp
  49. timeout client 3h
  50. timeout server 3h
  51. server master1 <IP1>:6443
  52. server master2 <IP2>:6443
  53. balance roundrobin
  54. ```
  55. Note: That's an example config managed elsewhere outside of Kubespray.
  56. And the corresponding example global vars for such a "cluster-aware"
  57. external LB with the cluster API access modes configured in Kubespray:
  58. ```
  59. apiserver_loadbalancer_domain_name: "my-apiserver-lb.example.com"
  60. loadbalancer_apiserver:
  61. address: <VIP>
  62. port: 8383
  63. ```
  64. Note: The default kubernetes apiserver configuration binds to all interfaces,
  65. so you will need to use a different port for the vip from that the API is
  66. listening on, or set the `kube_apiserver_bind_address` so that the API only
  67. listens on a specific interface (to avoid conflict with haproxy binding the
  68. port on the VIP address)
  69. This domain name, or default "lb-apiserver.kubernetes.local", will be inserted
  70. into the `/etc/hosts` file of all servers in the `k8s-cluster` group and wired
  71. into the generated self-signed TLS/SSL certificates as well. Note that
  72. the HAProxy service should as well be HA and requires a VIP management, which
  73. is out of scope of this doc.
  74. There is a special case for an internal and an externally configured (not with
  75. Kubespray) LB used simultaneously. Keep in mind that the cluster is not aware
  76. of such an external LB and you need no to specify any configuration variables
  77. for it.
  78. Note: TLS/SSL termination for externally accessed API endpoints' will **not**
  79. be covered by Kubespray for that case. Make sure your external LB provides it.
  80. Alternatively you may specify an externally load balanced VIPs in the
  81. `supplementary_addresses_in_ssl_keys` list. Then, kubespray will add them into
  82. the generated cluster certificates as well.
  83. Aside of that specific case, the `loadbalancer_apiserver` considered mutually
  84. exclusive to `loadbalancer_apiserver_localhost`.
  85. Access API endpoints are evaluated automatically, as the following:
  86. | Endpoint type | kube-master | non-master | external |
  87. |------------------------------|----------------|---------------------|---------------------|
  88. | Local LB (default) | https://bip:sp | https://lc:nsp | https://m[0].aip:sp |
  89. | Local LB + Unmanaged here LB | https://bip:sp | https://lc:nsp | https://ext |
  90. | External LB, no internal | https://bip:sp | https://lb:lp | https://lb:lp |
  91. | No ext/int LB | https://bip:sp | https://m[0].aip:sp | https://m[0].aip:sp |
  92. Where:
  93. * `m[0]` - the first node in the `kube-master` group;
  94. * `lb` - LB FQDN, `apiserver_loadbalancer_domain_name`;
  95. * `ext` - Externally load balanced VIP:port and FQDN, not managed by Kubespray;
  96. * `lc` - localhost;
  97. * `bip` - a custom bind IP or localhost for the default bind IP '0.0.0.0';
  98. * `nsp` - nginx secure port, `nginx_kube_apiserver_port`, defers to `sp`;
  99. * `sp` - secure port, `kube_apiserver_port`;
  100. * `lp` - LB port, `loadbalancer_apiserver.port`, defers to the secure port;
  101. * `ip` - the node IP, defers to the ansible IP;
  102. * `aip` - `access_ip`, defers to the ip.
  103. A second and a third column represent internal cluster access modes. The last
  104. column illustrates an example URI to access the cluster APIs externally.
  105. Kubespray has nothing to do with it, this is informational only.
  106. As you can see, the masters' internal API endpoints are always
  107. contacted via the local bind IP, which is `https://bip:sp`.
  108. **Note** that for some cases, like healthchecks of applications deployed by
  109. Kubespray, the masters' APIs are accessed via the insecure endpoint, which
  110. consists of the local `kube_apiserver_insecure_bind_address` and
  111. `kube_apiserver_insecure_port`.
  112. Optional configurations
  113. ------------------------
  114. ### ETCD with a LB
  115. In order to use an external loadbalancing (L4/TCP or L7 w/ SSL Passthrough VIP), the following variables need to be overridden in group_vars
  116. * `etcd_access_addresses`
  117. * `etcd_client_url`
  118. * `etcd_cert_alt_names`
  119. * `etcd_cert_alt_ips`
  120. #### Example of a VIP w/ FQDN
  121. ```yaml
  122. etcd_access_addresses: https://etcd.example.com:2379
  123. etcd_client_url: https://etcd.example.com:2379
  124. etcd_cert_alt_names:
  125. - "etcd.kube-system.svc.{{ dns_domain }}"
  126. - "etcd.kube-system.svc"
  127. - "etcd.kube-system"
  128. - "etcd"
  129. - "etcd.example.com" # This one needs to be added to the default etcd_cert_alt_names
  130. ```
  131. #### Example of a VIP w/o FQDN (IP only)
  132. ```yaml
  133. etcd_access_addresses: https://2.3.7.9:2379
  134. etcd_client_url: https://2.3.7.9:2379
  135. etcd_cert_alt_ips:
  136. - "2.3.7.9"
  137. ```