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.

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