#kubernetes #coordination #consensus #api-bindings

kube-coordinate

Kubernetes leader election using the coordination.k8s.io API

7 releases ()

2.0.0-rc.0 Nov 20, 2025
0.2.1 Mar 6, 2024
0.1.3 Dec 11, 2023

#265 in Asynchronous

Download history 20361/week @ 2025-10-23 12975/week @ 2025-10-30 13372/week @ 2025-11-06 12557/week @ 2025-11-13 13432/week @ 2025-11-20 9693/week @ 2025-11-27 19997/week @ 2025-12-04 17242/week @ 2025-12-11 16803/week @ 2025-12-18 9015/week @ 2025-12-25 10891/week @ 2026-01-01 21959/week @ 2026-01-08 17748/week @ 2026-01-15 19562/week @ 2026-01-22 21978/week @ 2026-01-29 25453/week @ 2026-02-05

88,847 downloads per month

MIT/Apache

34KB
423 lines

Kube Coordinate

docs.rs Build Status

Kubernetes leader election using the coordination.k8s.io API.

Kube Coordinate builds upon the kube-rs ecosystem, and implements a streamlined version of the client-go leader election system. This implementation uses only Lease objects for coordination.

// Spawn a leader elector task, and get a handle to the state channel.
let handle = LeaderElector::spawn(/* ... */);
let state_chan = handle.state();

// Before taking action as a leader, just check the channel to ensure
// the lease is currently held by this process.
if state_chan.borrow().is_leader() {
    // Only perform leader actions if in leader state.
}

// Or, for a more sophisticated pattern, watch the state channel for changes,
// and use it to drive your application's state machine.
let state_stream = tokio_stream::wrappers::WatchStream::new(state_chan);
loop {
    tokio::select! {
        Some(state) = state_stream.next() => match state {
            LeaderState::Leader => (), // Leader tasks.
            _ => (), // Non-leader tasks.
        },
    }
}

Install

cargo add kube-coordinate

Versioning

This crate follows the semver major version of the kube crate.

k8s-openapi features

In order to ensure that this create remains future proof, and compatible with future versions of K8s, this crate specifies a default feature k8s-latest which ensures that k8s-openapi/latest feature is enabled. Simply disable default features for this create, and specify an override for the feature as kube-coordinate/k8s-openapi/latest.

License

kube-coordinate is licensed under the terms of the MIT License or the Apache License 2.0, at your choosing.

Dependencies

~69MB
~1M SLoC