What this repo does are:
- Study kubernetes scheduler following 自作して学ぶKubernetes Scheduler with sanposhiho/mini-kube-scheduler.
- Simplify the original repo https://github.com/sanposhiho/mini-kube-scheduler
- Implement ToDos in sanposhiho/mini-kube-scheduler .
- Gain basic understanding of Scheduling Framework by hands-on.
Scheduler
: Custom Scheduler (minisched)SchedulingQueue
: Store Pods to schedule to a node.activeQ
: A queue to store Pods to start scheduling.unschedulableQ
: A queue to store Pods that are failed to schedule (with the plugins that made it unschedulable.)podBackoffQ
: A queue to store Pods that are in back-off state.
client
: Used to update Pod to bind it to a node.
Informer
withHandler
(Scheduler.addPodToSchedulingQueue()
) +FilterFunc
Service
:- Initialize Scheduler and set the event handler for informer with
New()
- Call
Scheduler.Run()
to startScheduler
.
- Initialize Scheduler and set the event handler for informer with
Plugin
: Implement logic for extension points in each scheduling context and called in the scheduler.
Diagram:
Files:
hack
: Shell scriptsetcd.sh
: Functions to start/stop/cleanup etcd.openapi.sh
: Generatezz_generated.openapi.go
forkube-apiserver
.run.sh
: Start etcd and run the scheduler.
k8sapiserver
: Dependency to run a scheduler.minisched
: Implementation of mini-kube-scheduler.sched.go
: Run dependency (apiserver
) and the scheduler within a scenario (create nodes and a pod).scheduler
: Scheduler service to manageminisched
.
- Initial Random Scheduler: Randomly schedule a Pod to available nodes.
- Filter Plugins: Use
NodeUnschedulable
plugin. - Score Plugins: Schedule based on the score of each node. (
NodeName
) - PreScore Plugins: Move common logic in the ScorePlugin to PreScorePlugin to reuse it.
- Permit Plugins: Delay n seconds based on the name of the node.
- Scheduling Queue: Make the simple queue closer to the one used in
kube-scheduler
. (podBackoffQ
andUnschedulableQ
+ Logic to put back a queue) - Event Handler: Trigger
MoveAllToActiveOrBackoffQueue
when a new node is added. - Flush Queue: Flush
podBackoffQ
andUnschedulableQ
periodically.
Tips: Development Tips
- kubernetes.io/docs
- github.com
- https://github.com/sanposhiho/mini-kube-scheduler
- https://github.com/draios/kubernetes-scheduler
- https://github.com/kubernetes/kubernetes/blob/v1.23.4/pkg/scheduler/internal/queue/scheduling_queue.go
- https://github.com/kubernetes/enhancements/tree/master/keps/sig-scheduling/624-scheduling-framework
- https://github.com/kubernetes-sigs/kube-scheduler-simulator
- https://github.com/kubernetes-sigs/scheduler-plugins
- Others
- 自作して学ぶKubernetes Scheduler (mercari engineering)
- 自作して学ぶKubernetes scheduler入門 (CloudNative Days 2021)
- Writing custom Kubernetes schedulers
- Kubernetes Scheduler 自作入門
- Building a Kubernetes Scheduler using Custom Metrics - Mateo Burillo, Sysdig (YouTube)
- 'unknown revision v0.0.0' errors, seemingly due to 'require k8s.io/foo v0.0.0' #79384