This scheduler is not for production
Hello world.
This is mini-kube-scheduler -- the scheduler for learning Kubernetes Scheduler.
And this repository also has scenario system. You can write scenario like this and check the scheduler's behaviours.
func scenario(client clientset.Interface) error {
ctx := context.Background()
// create node0 ~ node9, but all nodes are unschedulable
for i := 0; i < 9; i++ {
suffix := strconv.Itoa(i)
_, err := client.CoreV1().Nodes().Create(ctx, &v1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "node" + suffix,
},
Spec: v1.NodeSpec{
Unschedulable: true,
},
}, metav1.CreateOptions{})
if err != nil {
return fmt.Errorf("create node: %w", err)
}
}
klog.Info("scenario: all nodes created")
_, err := client.CoreV1().Pods("default").Create(ctx, &v1.Pod{
ObjectMeta: metav1.ObjectMeta{Name: "pod1"},
Spec: v1.PodSpec{
Containers: []v1.Container{
{
Name: "container1",
Image: "k8s.gcr.io/pause:3.5",
},
},
},
}, metav1.CreateOptions{})
if err != nil {
return fmt.Errorf("create pod: %w", err)
}
klog.Info("scenario: pod1 created")
// wait to schedule
time.Sleep(3 * time.Second)
pod1, err := client.CoreV1().Pods("default").Get(ctx, "pod1", metav1.GetOptions{})
if err != nil {
return fmt.Errorf("get pod: %w", err)
}
klog.Info("scenario: pod1 is bound to " + pod1.Spec.NodeName)
return nil
}
The scheduler evolves step by step, branch by branch. You can use them to learn the scheduler step by step.
TODO: I'm planning to add docs to describe what is new feature for each branchs.
This scheduler selects node for pod randomly.
This scheduler selects node for pod with only filter plugin. Only unschedulable node plugin is enabled as filter plugin.
This scheduler selects node for pod with filter and score plugin. Only nodenumber plugin(implemented as custom plugin) is enabled as score plugin.
This scheduler supports pre-score plugins. The nodenumber plugin is improved so that it is also used as prescore plugins.
This scheduler supports permit plugins. The nodenumber plugin is improved so that it is also used as permit plugins. And binding cycle is now goroutined(work in parallel).
This branch implements Scheduling Queue. It also supports putting the Pod back into the Queue as unschedulable when the schedule fails.
This branch has support for updating Queues using EventHandler. It supports re-scheduling of pods that fail to schedule.
Most of the codes for this scheduler is placed under /minisched. You can change this scheduler to what you want.
And this scheduler is started on here
If you want to change how to start the scheduler, you can change here.
You can write scenario here and check this scheduler's behaviour.
To run this scheduler and start scenario, you have to install Go and etcd. You can install etcd with kubernetes/kubernetes/hack/install-etcd.sh.
And, make start
starts your scenario.
This mini-kube-scheduler starts scheduler, etcd, api-server and pv-controller.
The whole mechanism is based on kubernetes-sigs/kube-scheduler-simulator and sanposhiho/kube-scheduler-simulator-cli