2016-07-22 20:42:44 +08:00
|
|
|
HA endpoints for K8s
|
|
|
|
====================
|
|
|
|
|
|
|
|
The following components require a highly available endpoints:
|
|
|
|
* etcd cluster,
|
|
|
|
* kube-apiserver service instances.
|
|
|
|
|
2018-09-20 16:27:16 +08:00
|
|
|
The latter relies on a 3rd side reverse proxy, like Nginx or HAProxy, to
|
2016-07-22 20:42:44 +08:00
|
|
|
achieve the same goal.
|
|
|
|
|
|
|
|
Etcd
|
|
|
|
----
|
|
|
|
|
2018-10-26 21:55:54 +08:00
|
|
|
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
|
2018-08-31 20:34:13 +08:00
|
|
|
* `etcd_access_addresses`
|
|
|
|
* `etcd_client_url`
|
|
|
|
* `etcd_cert_alt_names`
|
|
|
|
* `etcd_cert_alt_ips`
|
2016-07-22 20:42:44 +08:00
|
|
|
|
2018-08-31 20:34:13 +08:00
|
|
|
### Example of a VIP w/ FQDN
|
|
|
|
```yaml
|
|
|
|
etcd_access_addresses: https://etcd.example.com:2379
|
|
|
|
etcd_client_url: https://etcd.example.com:2379
|
|
|
|
etcd_cert_alt_names:
|
|
|
|
- "etcd.kube-system.svc.{{ dns_domain }}"
|
|
|
|
- "etcd.kube-system.svc"
|
|
|
|
- "etcd.kube-system"
|
|
|
|
- "etcd"
|
|
|
|
- "etcd.example.com" # This one needs to be added to the default etcd_cert_alt_names
|
|
|
|
```
|
|
|
|
|
|
|
|
### Example of a VIP w/o FQDN (IP only)
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
etcd_access_addresses: https://2.3.7.9:2379
|
|
|
|
etcd_client_url: https://2.3.7.9:2379
|
|
|
|
etcd_cert_alt_ips:
|
|
|
|
- "2.3.7.9"
|
|
|
|
```
|
2016-07-22 20:42:44 +08:00
|
|
|
|
|
|
|
Kube-apiserver
|
|
|
|
--------------
|
2016-07-13 23:13:47 +08:00
|
|
|
|
|
|
|
K8s components require a loadbalancer to access the apiservers via a reverse
|
2017-06-17 01:25:46 +08:00
|
|
|
proxy. Kubespray includes support for an nginx-based proxy that resides on each
|
2016-09-28 19:05:08 +08:00
|
|
|
non-master Kubernetes node. This is referred to as localhost loadbalancing. It
|
|
|
|
is less efficient than a dedicated load balancer because it creates extra
|
|
|
|
health checks on the Kubernetes apiserver, but is more practical for scenarios
|
2017-01-18 03:15:48 +08:00
|
|
|
where an external LB or virtual IP management is inconvenient. This option is
|
2017-11-24 00:15:48 +08:00
|
|
|
configured by the variable `loadbalancer_apiserver_localhost` (defaults to
|
|
|
|
`True`. Or `False`, if there is an external `loadbalancer_apiserver` defined).
|
2017-07-18 22:44:08 +08:00
|
|
|
You may also define the port the local internal loadbalancer uses by changing,
|
2017-11-24 00:15:48 +08:00
|
|
|
`nginx_kube_apiserver_port`. This defaults to the value of
|
|
|
|
`kube_apiserver_port`. It is also important to note that Kubespray will only
|
|
|
|
configure kubelet and kube-proxy on non-master nodes to use the local internal
|
|
|
|
loadbalancer.
|
2017-01-18 03:15:48 +08:00
|
|
|
|
2017-11-24 00:15:48 +08:00
|
|
|
If you choose to NOT use the local internal loadbalancer, you will need to
|
|
|
|
configure your own loadbalancer to achieve HA. Note that deploying a
|
|
|
|
loadbalancer is up to a user and is not covered by ansible roles in Kubespray.
|
|
|
|
By default, it only configures a non-HA endpoint, which points to the
|
|
|
|
`access_ip` or IP address of the first server node in the `kube-master` group.
|
|
|
|
It can also configure clients to use endpoints for a given loadbalancer type.
|
|
|
|
The following diagram shows how traffic to the apiserver is directed.
|
2016-09-28 19:05:08 +08:00
|
|
|
|
|
|
|
![Image](figures/loadbalancer_localhost.png?raw=true)
|
2016-07-13 23:13:47 +08:00
|
|
|
|
2016-10-17 21:42:30 +08:00
|
|
|
Note: Kubernetes master nodes still use insecure localhost access because
|
2016-09-28 19:05:08 +08:00
|
|
|
there are bugs in Kubernetes <1.5.0 in using TLS auth on master role
|
2016-10-17 21:42:30 +08:00
|
|
|
services. This makes backends receiving unencrypted traffic and may be a
|
|
|
|
security issue when interconnecting different nodes, or maybe not, if those
|
|
|
|
belong to the isolated management network without external access.
|
2016-09-28 19:05:08 +08:00
|
|
|
|
|
|
|
A user may opt to use an external loadbalancer (LB) instead. An external LB
|
2016-07-13 23:13:47 +08:00
|
|
|
provides access for external clients, while the internal LB accepts client
|
2016-11-09 18:31:12 +08:00
|
|
|
connections only to the localhost.
|
2016-07-13 23:13:47 +08:00
|
|
|
Given a frontend `VIP` address and `IP1, IP2` addresses of backends, here is
|
|
|
|
an example configuration for a HAProxy service acting as an external LB:
|
|
|
|
```
|
|
|
|
listen kubernetes-apiserver-https
|
|
|
|
bind <VIP>:8383
|
|
|
|
option ssl-hello-chk
|
|
|
|
mode tcp
|
|
|
|
timeout client 3h
|
|
|
|
timeout server 3h
|
2017-02-24 22:58:54 +08:00
|
|
|
server master1 <IP1>:6443
|
|
|
|
server master2 <IP2>:6443
|
2016-07-13 23:13:47 +08:00
|
|
|
balance roundrobin
|
|
|
|
```
|
|
|
|
|
2018-01-09 21:01:50 +08:00
|
|
|
Note: That's an example config managed elsewhere outside of Kubespray.
|
|
|
|
|
|
|
|
And the corresponding example global vars for such a "cluster-aware"
|
|
|
|
external LB with the cluster API access modes configured in Kubespray:
|
2016-07-13 23:13:47 +08:00
|
|
|
```
|
2017-11-24 00:15:48 +08:00
|
|
|
apiserver_loadbalancer_domain_name: "my-apiserver-lb.example.com"
|
2016-07-13 23:13:47 +08:00
|
|
|
loadbalancer_apiserver:
|
|
|
|
address: <VIP>
|
|
|
|
port: 8383
|
|
|
|
```
|
|
|
|
|
2017-11-29 23:24:02 +08:00
|
|
|
Note: The default kubernetes apiserver configuration binds to all interfaces,
|
|
|
|
so you will need to use a different port for the vip from that the API is
|
2018-01-09 21:01:50 +08:00
|
|
|
listening on, or set the `kube_apiserver_bind_address` so that the API only
|
2017-11-29 23:24:02 +08:00
|
|
|
listens on a specific interface (to avoid conflict with haproxy binding the
|
2018-09-20 16:27:16 +08:00
|
|
|
port on the VIP address)
|
2017-11-29 23:24:02 +08:00
|
|
|
|
2016-07-13 23:13:47 +08:00
|
|
|
This domain name, or default "lb-apiserver.kubernetes.local", will be inserted
|
2018-01-09 21:01:50 +08:00
|
|
|
into the `/etc/hosts` file of all servers in the `k8s-cluster` group and wired
|
|
|
|
into the generated self-signed TLS/SSL certificates as well. Note that
|
2016-07-13 23:13:47 +08:00
|
|
|
the HAProxy service should as well be HA and requires a VIP management, which
|
2018-01-09 21:01:50 +08:00
|
|
|
is out of scope of this doc.
|
|
|
|
|
|
|
|
There is a special case for an internal and an externally configured (not with
|
|
|
|
Kubespray) LB used simultaneously. Keep in mind that the cluster is not aware
|
|
|
|
of such an external LB and you need no to specify any configuration variables
|
|
|
|
for it.
|
|
|
|
|
|
|
|
Note: TLS/SSL termination for externally accessed API endpoints' will **not**
|
|
|
|
be covered by Kubespray for that case. Make sure your external LB provides it.
|
|
|
|
Alternatively you may specify an externally load balanced VIPs in the
|
|
|
|
`supplementary_addresses_in_ssl_keys` list. Then, kubespray will add them into
|
|
|
|
the generated cluster certifactes as well.
|
2016-07-13 23:13:47 +08:00
|
|
|
|
2018-01-09 21:01:50 +08:00
|
|
|
Aside of that specific case, the `loadbalancer_apiserver` considered mutually
|
|
|
|
exclusive to `loadbalancer_apiserver_localhost`.
|
2016-07-13 23:13:47 +08:00
|
|
|
|
2018-01-04 00:40:21 +08:00
|
|
|
Access API endpoints are evaluated automagically, as the following:
|
2016-07-13 23:13:47 +08:00
|
|
|
|
2018-01-09 21:01:50 +08:00
|
|
|
| Endpoint type | kube-master | non-master | external |
|
|
|
|
|------------------------------|----------------|---------------------|---------------------|
|
|
|
|
| Local LB (default) | https://bip:sp | https://lc:nsp | https://m[0].aip:sp |
|
|
|
|
| Local LB + Unmanaged here LB | https://bip:sp | https://lc:nsp | https://ext |
|
|
|
|
| External LB, no internal | https://bip:sp | https://lb:lp | https://lb:lp |
|
|
|
|
| No ext/int LB | https://bip:sp | https://m[0].aip:sp | https://m[0].aip:sp |
|
2016-07-13 23:13:47 +08:00
|
|
|
|
|
|
|
Where:
|
|
|
|
* `m[0]` - the first node in the `kube-master` group;
|
|
|
|
* `lb` - LB FQDN, `apiserver_loadbalancer_domain_name`;
|
2018-01-09 21:01:50 +08:00
|
|
|
* `ext` - Externally load balanced VIP:port and FQDN, not managed by Kubespray;
|
2016-07-13 23:13:47 +08:00
|
|
|
* `lc` - localhost;
|
2018-01-09 21:01:50 +08:00
|
|
|
* `bip` - a custom bind IP or localhost for the default bind IP '0.0.0.0';
|
2018-01-04 00:40:21 +08:00
|
|
|
* `nsp` - nginx secure port, `nginx_kube_apiserver_port`, defers to `sp`;
|
2016-07-13 23:13:47 +08:00
|
|
|
* `sp` - secure port, `kube_apiserver_port`;
|
|
|
|
* `lp` - LB port, `loadbalancer_apiserver.port`, defers to the secure port;
|
|
|
|
* `ip` - the node IP, defers to the ansible IP;
|
|
|
|
* `aip` - `access_ip`, defers to the ip.
|
2017-01-18 03:15:48 +08:00
|
|
|
|
2018-01-09 21:01:50 +08:00
|
|
|
A second and a third column represent internal cluster access modes. The last
|
|
|
|
column illustrates an example URI to access the cluster APIs externally.
|
|
|
|
Kubespray has nothing to do with it, this is informational only.
|
|
|
|
|
|
|
|
As you can see, the masters' internal API endpoints are always
|
|
|
|
contacted via the local bind IP, which is `https://bip:sp`.
|
|
|
|
|
2018-01-04 00:40:21 +08:00
|
|
|
**Note** that for some cases, like healthchecks of applications deployed by
|
|
|
|
Kubespray, the masters' APIs are accessed via the insecure endpoint, which
|
|
|
|
consists of the local `kube_apiserver_insecure_bind_address` and
|
|
|
|
`kube_apiserver_insecure_port`.
|