-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ff00f2c
commit dda7bce
Showing
9 changed files
with
855 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Kensei Nakada | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
# mini-kube-scheduler: Scheduler for learning Kubernetes Scheduler | ||
|
||
**このスケジューラーは本番環境での使用を想定して作成されたものではありません** | ||
|
||
Hello world. | ||
|
||
このスケジューラーは学習向けに開発されたもので、コマンドライン上から動作を確認しつつ、スケジューラーの機能の実装の様子を見て取ることができます。 | ||
|
||
また、client-goを用いてシナリオを記述し、スケジューラーの動作を試すことができます。 | ||
|
||
```go | ||
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 | ||
} | ||
``` | ||
|
||
## スケジューラーの進化を追う | ||
|
||
このスケジューラーはブランチごとに段階を踏んで進化していく様子を追うことができるように開発されています。 | ||
それぞれのブランチでスケジューラーの動作を確認し、コードを変更するなどして理解を深めることができます。 | ||
|
||
TODO: 各ブランチにそのブランチで追加された機能の説明を加える。 | ||
|
||
1. [initial scheduler](/tree/01/init-scheduler) | ||
|
||
最も初期の段階のスケジューラーであり、全てのNodeから完全にランダムにPodを配置します。 | ||
|
||
2. [filter plugins](/tree/02/filter-plugin) | ||
|
||
このブランチのスケジューラーはfilter pluginの実行に対応しています。unschedulable nodeプラグインのみが有効になっています。 | ||
|
||
3. [score plugins](/tree/03/score-plugin) | ||
|
||
このブランチのスケジューラーはさらにscore pluginの実行に対応しています。custom pluginであるnodenumberプラグインのみがscore pluginとして有効になっています。nodenumber プラグインの実装もブランチ内に存在しています。 | ||
|
||
4. [prescore plugins](/tree/04/prescore-plugins) | ||
|
||
このブランチのスケジューラーはさらにpre-score pluginの実行に対応しています。custom pluginであるnodenumberプラグインにpre-score pluginの機能を実装し、有効にしています。 | ||
|
||
5. [permit plugins](/tree/05/permit-plugins) | ||
|
||
このブランチのスケジューラーはさらにpremit pluginの実行に対応しています。custom pluginであるnodenumberプラグインにpremit pluginの機能を実装し、有効にしています。 | ||
また、このブランチでは、Binding Cycleが並行にgoroutineで実行されるようになっています。 | ||
|
||
6. [scheduling queue](/tree/06/scheduling-queue) | ||
|
||
このブランチにはScheduling Queueが実装されています。また、スケジュールの失敗時に、PodをunschedulableとしてQueueに戻すことにも対応しています。 | ||
|
||
7. [eventhandler](/tree/07/event-handler) | ||
|
||
このブランチにはEventHandlerを用いたQueueの更新に対応しています。これにて、スケジュールに失敗したPodの再スケジュールに対応しています。 | ||
|
||
|
||
# スケジューラーのメインロジックに関して | ||
|
||
スケジューラーのメインロジックは、[/minisched](./minisched)に存在しています。 | ||
このディレクトリ以下に変更を加えることで、起動するスケジューラーのロジックを変更することができます | ||
|
||
プログラムの実行時、このスケジューラーは[ここ](/scheduler/scheduler.go#L50-L80)で起動されます。 | ||
そのため、起動時の振る舞いを変更したい場合や、何か変数を渡したい場合などはこちらから変更してください。 | ||
|
||
# シナリオ | ||
|
||
[ここ](/sched.go#L70) でclient-goを用いてAPIを叩き、スケジューラーの動作を試すシナリオが記述されています。 | ||
自由に変更し、スケジューラーの動作確認に使用してください。 | ||
|
||
# シナリオ/スケジューラーの実行に関して | ||
|
||
スケジューラーを起動して、シナリオを実行するにはGoとetcdが必要になります | ||
etcdに関してはこちらのKubernetes本体に用意されているインストール方法を使用できます。 | ||
|
||
[kubernetes/kubernetes/hack/install-etcd.sh](https://github.com/kubernetes/kubernetes/blob/master/hack/install-etcd.sh). | ||
|
||
もちろん別の方法でinstallしていただいても構いません。 | ||
|
||
そして `make start` でスケジューラーとスケジューラーに必要なコンポーネントが立ち上がり、シナリオが実行されます。 | ||
|
||
# 参考 | ||
|
||
このmini-kube-schedulerのスケジューラーの起動やシナリオの実行などの全体的な仕組みに関しては[kubernetes-sigs/kube-scheduler-simulator](https://github.com/kubernetes-sigs/kube-scheduler-simulator)を参考にしております。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
# mini-kube-scheduler: Scheduler for learning Kubernetes Scheduler | ||
|
||
**This scheduler is not for production** | ||
|
||
[日本語版はこちら(Japanese ver)](/README.ja.md) | ||
|
||
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. | ||
|
||
```go | ||
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 evolution of Scheduler | ||
|
||
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. | ||
|
||
1. [initial scheduler](/tree/01/init-scheduler) | ||
|
||
This scheduler selects node for pod randomly. | ||
|
||
2. [filter plugins](/tree/02/filter-plugin) | ||
|
||
This scheduler selects node for pod with only filter plugin. Only unschedulable node plugin is enabled as filter plugin. | ||
|
||
3. [score plugins](/tree/03/score-plugin) | ||
|
||
This scheduler selects node for pod with filter and score plugin. Only nodenumber plugin(implemented as custom plugin) is enabled as score plugin. | ||
|
||
4. [prescore plugins](/tree/04/prescore-plugins) | ||
|
||
This scheduler supports pre-score plugins. The nodenumber plugin is improved so that it is also used as prescore plugins. | ||
|
||
5. [permit plugins](/tree/05/permit-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). | ||
|
||
6. [scheduling queue](/tree/06/scheduling-queue) | ||
|
||
This branch implements Scheduling Queue. It also supports putting the Pod back into the Queue as unschedulable when the schedule fails. | ||
|
||
7. [eventhandler](/tree/07/event-handler) | ||
|
||
This branch has support for updating Queues using EventHandler. It supports re-scheduling of pods that fail to schedule. | ||
|
||
## custom main logic of this scheduler | ||
|
||
Most of the codes for this scheduler is placed under [/minisched](./minisched). | ||
You can change this scheduler to what you want. | ||
|
||
And this scheduler is started on [here](/scheduler/scheduler.go#L50-L80) | ||
|
||
If you want to change how to start the scheduler, you can change here. | ||
|
||
## custom scenario | ||
|
||
You can write scenario [here](/sched.go#L70) and check this scheduler's behaviour. | ||
|
||
## How to start this scheduler and scenario | ||
|
||
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](https://github.com/kubernetes/kubernetes/blob/master/hack/install-etcd.sh). | ||
|
||
And, `make start` starts your scenario. | ||
|
||
## Note | ||
|
||
This mini-kube-scheduler starts scheduler, etcd, api-server and pv-controller. | ||
|
||
The whole mechanism is based on [kubernetes-sigs/kube-scheduler-simulator](https://github.com/kubernetes-sigs/kube-scheduler-simulator) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.