A "reference" implementation for building a Kubernetes scheduler in Rust. This is not intended as a replacement for the real Kubernetes scheduler, nor should it be used in any sort of production environment, but it does do an extremely basic job of scheduling pods onto nodes in a Kubernetes cluster.
The reference implementation relies on the kube-rs/kube crate to interact with the
Kubernetes API, as well as the k8s-openapi crate for the various Kubernetes
API objects. It sets up a controller that watches Unschedulable
Pods and all Nodes in the cluster. When an
unschedulable pod arrives, it will randomly try to pick (up to) five nodes in the cluster, checking CPU and memory
constraints, as well as nodeSelector
constraints for each. If it finds one that succeeds, it will create a binding
for the pod to the node. Otherwise, it will return an error and try again later.
Note that because the scheduler is checking only a tiny fraction of the possible scheduling constraints that Kubernetes provides, so it is highly likely that the pod binding will fail in any sort of "real" cluster.
Mainly this was intended as an exercise in learning more about the kube
Rust crate and the surrounding ecosystem, as
well as to demonstrate that building a Kubernetes scheduler in Rust is possible. Whether it's a good idea remains to
be seen.
To run the scheduler: cargo run
. Note that you don't need to run this in a pod inside your cluster as long as you
have a kubeconfig in a standard location with cluster admin privileges.
To run the tests: cargo test
. Note that we have laughably low test coverage.
We do use pre-commit
in this repo to check formatting and linting. Install
pre-commit here, and then run pre-commit install
to configure the hooks.
I don't really expect to do any more on this project, but if you want to extend it, or you find things that I've done that could be better, I'll happily accept PRs.