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.

113 lines
4.9 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 proxies, like Nginx or HAProxy, to
  7. achieve the same goal.
  8. Etcd
  9. ----
  10. The `etcd_access_endpoint` fact provides an access pattern for clients. And the
  11. `etcd_multiaccess` (defaults to `True`) group var controls that behavior.
  12. It makes deployed components to access the etcd cluster members
  13. directly: `http://ip1:2379, http://ip2:2379,...`. This mode assumes the clients
  14. do a loadbalancing and handle HA for connections.
  15. Kube-apiserver
  16. --------------
  17. K8s components require a loadbalancer to access the apiservers via a reverse
  18. proxy. Kubespray includes support for an nginx-based proxy that resides on each
  19. non-master Kubernetes node. This is referred to as localhost loadbalancing. It
  20. is less efficient than a dedicated load balancer because it creates extra
  21. health checks on the Kubernetes apiserver, but is more practical for scenarios
  22. where an external LB or virtual IP management is inconvenient. This option is
  23. configured by the variable `loadbalancer_apiserver_localhost` (defaults to
  24. `True`. Or `False`, if there is an external `loadbalancer_apiserver` defined).
  25. You may also define the port the local internal loadbalancer uses by changing,
  26. `nginx_kube_apiserver_port`. This defaults to the value of
  27. `kube_apiserver_port`. It is also important to note that Kubespray will only
  28. configure kubelet and kube-proxy on non-master nodes to use the local internal
  29. loadbalancer.
  30. If you choose to NOT use the local internal loadbalancer, you will need to
  31. configure your own loadbalancer to achieve HA. Note that deploying a
  32. loadbalancer is up to a user and is not covered by ansible roles in Kubespray.
  33. By default, it only configures a non-HA endpoint, which points to the
  34. `access_ip` or IP address of the first server node in the `kube-master` group.
  35. It can also configure clients to use endpoints for a given loadbalancer type.
  36. The following diagram shows how traffic to the apiserver is directed.
  37. ![Image](figures/loadbalancer_localhost.png?raw=true)
  38. Note: Kubernetes master nodes still use insecure localhost access because
  39. there are bugs in Kubernetes <1.5.0 in using TLS auth on master role
  40. services. This makes backends receiving unencrypted traffic and may be a
  41. security issue when interconnecting different nodes, or maybe not, if those
  42. belong to the isolated management network without external access.
  43. A user may opt to use an external loadbalancer (LB) instead. An external LB
  44. provides access for external clients, while the internal LB accepts client
  45. connections only to the localhost.
  46. Given a frontend `VIP` address and `IP1, IP2` addresses of backends, here is
  47. an example configuration for a HAProxy service acting as an external LB:
  48. ```
  49. listen kubernetes-apiserver-https
  50. bind <VIP>:8383
  51. option ssl-hello-chk
  52. mode tcp
  53. timeout client 3h
  54. timeout server 3h
  55. server master1 <IP1>:6443
  56. server master2 <IP2>:6443
  57. balance roundrobin
  58. ```
  59. And the corresponding example global vars config:
  60. ```
  61. apiserver_loadbalancer_domain_name: "my-apiserver-lb.example.com"
  62. loadbalancer_apiserver:
  63. address: <VIP>
  64. port: 8383
  65. ```
  66. Note: The default kubernetes apiserver configuration binds to all interfaces,
  67. so you will need to use a different port for the vip from that the API is
  68. listening on, or set the kube_apiserver_bind_address so that the API only
  69. listens on a specific interface (to avoid conflict with haproxy binding the
  70. port on the VIP adddress)
  71. This domain name, or default "lb-apiserver.kubernetes.local", will be inserted
  72. into the `/etc/hosts` file of all servers in the `k8s-cluster` group. Note that
  73. the HAProxy service should as well be HA and requires a VIP management, which
  74. is out of scope of this doc. Specifying an external LB overrides any internal
  75. localhost LB configuration.
  76. Note: In order to achieve HA for HAProxy instances, those must be running on
  77. the each node in the `k8s-cluster` group as well, but require no VIP, thus
  78. no VIP management.
  79. Access endpoints are evaluated automagically, as the following:
  80. | Endpoint type | kube-master | non-master |
  81. |------------------------------|---------------|---------------------|
  82. | Local LB (default) | http://lc:p | https://lc:nsp |
  83. | External LB, no internal | https://lb:lp | https://lb:lp |
  84. | No ext/int LB | http://lc:p | https://m[0].aip:sp |
  85. Where:
  86. * `m[0]` - the first node in the `kube-master` group;
  87. * `lb` - LB FQDN, `apiserver_loadbalancer_domain_name`;
  88. * `lc` - localhost;
  89. * `p` - insecure port, `kube_apiserver_insecure_port`
  90. * `nsp` - nginx secure port, `nginx_kube_apiserver_port`;
  91. * `sp` - secure port, `kube_apiserver_port`;
  92. * `lp` - LB port, `loadbalancer_apiserver.port`, defers to the secure port;
  93. * `ip` - the node IP, defers to the ansible IP;
  94. * `aip` - `access_ip`, defers to the ip.