Usage
Kayak is a Layer 2 virtual IP manager that uses etcd for distributed locking.
Each kayak instance is configured with a virtual IP and list of HTTP health checks.
- On startup, the instance will acquire a lease from etcd that it must renew at a regular interval. This acts as a heartbeat to indicate that the instance is still alive.
- Next, the instance will execute the health checks in a periodic loop.
- If all checks succeed, the instance will reach out to etcd and attempt to acquire a distributed lock that controls the virtual IP. The lock is associated with the lease and will be removed if the lease expires.
- If the instance is able to acquire the lock it will then assign itself the virtual IP and begin broadcasting periodic ARP Announcements or NDP Advertisements.
- If any health check fails, the virtual IP will be removed from the node and the lock will be released.
- If the instance dies for whatever reason (e.g. hardware failure), its lease and associated lock will expire, allowing other instances to acquire the lock and broadcast the virtual IP.
Full configuration for kayak can be found in the config file.
etcd
etcd uses the raft distributed consensus algorithm, which means that:
- It will never have a "split brain" state where the cluster is stuck having multiple nodes think they have the lock at the same time.
- As long as a majority of the etcd nodes in the system are functioning properly, one of the clients will be able to acquire the lock. (For this reason it is recommended to run an etcd cluster with an odd
n = 2k + 1number of nodes, in which case at mostkcan fail.)
See the documentation for instructions on how to deploy an etcd cluster.
A Note on Distributed Locks
Distributed locks are somewhat of a misnomer. As noted in the Jepson report for etcd and the etcd docs, it is impossible to guarantee that only a single service will hold a lock in an asynchronous system with failable members. For example, consider a system with two kayak nodes A and B, where each node has acquired a lease from etcd. Suppose that node A acquires the distributed lock and assigns the virtual IP to itself. However, if the lease renewal packets are delayed, etcd will conclude that A has died and expire its lease and lock. Node B will then be able to acquire the lock and assign the virtual IP to itself. Meanwhile A (running on its very slow network) hasn't received a response that its lease has expired and thinks everything is fine. We thus have the scenario where two nodes believe they have acquired the lock at the same time. (More lovely details about the theory of this in the equivalent case of leader election can be read here.) In practice, node A will release its lock once it receives a notification that its lease has expired. If the network is down completely and that notification never arrives, it will also release the lock when the independent client keepalive doesn't receive a response within the configured timeout.
Similar Projects
-
keepalived is the traditional solution for virtual IP management and uses VRRP for leader election. However, this protocol comes with two notable downsides:
- Leader election does not use consensus, so during a network partition multiple nodes can elect themselves as leader (and thus claim the virtual IP) indefinitely.
- VRRP is not encrypted or authenticated, so it is possible for other parties to disrupt the election. (This can happen quite easily if, for example, another keepalived deployment on the same LAN is misconfigured to use the same virtual router ID. Ask me how I know that...)
-
kube-vip is a newer solution specifically aimed at managing virtual IPs for Kubernetes. Kube-vip was one of the prime inspirations for kayak and comes with many, many features, including:
- Control-plane load balancing using IPVS
- Service
LoadBalancermanagement - Wireguard, and a lot more
Unfortunately these many features mean kube-vip is non-trivial to configure, and its reliance on the kubernetes API makes bootstrapping a cluster complicated. Kayak is intended to be simpler and only manage the virtual IP, and does not come with a load balancer. (If you need one may I suggest the excellent haproxy, or river once that becomes stable. Unfortunately I cannot recommend IPVS, since it runs in kernel space and is very difficult to debug.) Kayak also only relies on etcd and can be used in non-kubernetes environments.
Deployment
Systemd
Statically linked binaries are built in a sourcehut build environment and are published on the releases page. A sample file for running kayak as a systemd service can be found here.
Podman
Container images are published on Quay. Kayak needs CAP_NET_ADMIN and CAP_NET_RAW so it cannot be run rootless (though other privileges are dropped). For example,
sudo podman run --rm \
--read-only \
--network=host \
--security-opt=no-new-privileges \
--cap-drop=all --cap-add=net_admin,net_raw \
-v ./config.toml:/etc/kayak/config.toml:ro \
quay.io/jwgarber/kayak:v0.3.0
You will also likely need to mount the etcd certificates, in which case you should set the --user <uid>:<gid> flag of the user that owns them so kayak can read them. If SELinux is enabled you will also need to set --security-opt label=type:<type> for the SELinux type that can access the certificates (usually whatever type etcd runs as). Docker is probably similar.
Kubernetes
Bootstrapping a highly-available Kubernetes cluster was one of the main motivations for kayak, and deployment is very similar to the kubeadm instructions for keepalived. The first option is to run kayak, haproxy, and etcd as systemd services. This avoids any cyclic dependencies when bootstrapping the cluster, and ensures that kayak can clean up the virtual IP if/when you nuke your cluster during troubleshooting.[^1]
The second way is to run haproxy and kayak as static pods, and use the etcd cluster deployed by Kubernetes. Again, this deployment is very similar to the kubeadm instructions mentioned above. (For the security conscious, I should note that this will theoretically give kayak access to all internal Kubernetes resources, including configmaps and secrets. If possible, it is recommended to enable RBAC to ensure that each application only has access to the appropriate etcd keys, e.g. using something similar to this Calico guide.)
Sample files for deploying kayak with kubeadm can be found here.
[^1]: This applies when you deploy kayak as a static pod on your control nodes (option 2). Kayak will always try to remove the virtual IP whenever it exits; however, if you forcibly kill the controllers (e.g. using rke2-killall.sh), then kayak will get SIGKILL'd and be unable to remove the virtual IP. If you then start to re-install your cluster, it's possible that a second node will get assigned the virtual IP even when it hasn't been removed from the first. This can be avoided if you always ensure to reboot a node after removing the controller from it, since that will remove the virtual IP. In my local tests this doesn't seem to be a problem with kubeadm, but I can't guarantee it will stay that way.