Skip to content

Commit 7d5d4f6

Browse files
committed
devel/scheduler: update intro and scheduling algo
1 parent 607df19 commit 7d5d4f6

File tree

1 file changed

+54
-36
lines changed

1 file changed

+54
-36
lines changed

contributors/devel/scheduler.md

Lines changed: 54 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,63 @@
11
# The Kubernetes Scheduler
22

3-
The Kubernetes scheduler runs as a process alongside the other master
4-
components such as the API server. Its interface to the API server is to watch
5-
for Pods with an empty PodSpec.NodeName, and for each Pod, it posts a Binding
6-
indicating where the Pod should be scheduled.
3+
The Kubernetes scheduler runs as a process alongside the other master components such as the API server.
4+
Its interface to the API server is to watch for Pods with an empty PodSpec.NodeName,
5+
and for each Pod, it posts a binding indicating where the Pod should be scheduled.
76

8-
## The scheduling process
7+
## Exploring the code
8+
9+
We are dividng scheduler into three layers from high level:
10+
- [plugin/cmd/kube-scheduler/scheduler.go](http://releases.k8s.io/HEAD/plugin/cmd/kube-scheduler/scheduler.go):
11+
This is the main() entry that does initialization before calling the scheduler framework.
12+
- [pkg/scheduler/scheduler.go](http://releases.k8s.io/HEAD/pkg/scheduler/scheduler.go):
13+
This is the scheduler framework that handles stuff (e.g. binding) beyond the scheduling algorithm.
14+
- [pkg/scheduler/generic_scheduler.go](http://releases.k8s.io/HEAD/pkg/scheduler/generic_scheduler.go):
15+
The scheduling algorithm that assigns nodes for pods.
16+
17+
## The scheduling algorithm
918

1019
```
11-
+-------+
12-
+---------------+ node 1|
13-
| +-------+
14-
|
15-
+----> | Apply pred. filters
16-
| |
17-
| | +-------+
18-
| +----+---------->+node 2 |
19-
| | +--+----+
20-
| watch | |
21-
| | | +------+
22-
| +---------------------->+node 3|
23-
+--+---------------+ | +--+---+
24-
| Pods in apiserver| | |
25-
+------------------+ | |
26-
| |
27-
| |
28-
+------------V------v--------+
29-
| Priority function |
30-
+-------------+--------------+
31-
|
32-
| node 1: p=2
33-
| node 2: p=5
34-
v
35-
select max{node priority} = node 2
20+
For given pod:
21+
22+
+---------------------------------------------+
23+
| Schedulable nodes: |
24+
| |
25+
| +--------+ +--------+ +--------+ |
26+
| | node 1 | | node 2 | | node 3 | |
27+
| +--------+ +--------+ +--------+ |
28+
| |
29+
+-------------------+-------------------------+
30+
|
31+
|
32+
v
33+
+-------------------+-------------------------+
34+
35+
Pred. filters: node 3 doesn't have enough resource
36+
37+
+-------------------+-------------------------+
38+
|
39+
|
40+
v
41+
+-------------------+-------------------------+
42+
| remaining nodes: |
43+
| +--------+ +--------+ |
44+
| | node 1 | | node 2 | |
45+
| +--------+ +--------+ |
46+
| |
47+
+-------------------+-------------------------+
48+
|
49+
|
50+
v
51+
+-------------------+-------------------------+
3652
53+
Priority function: node 1: p=2
54+
node 2: p=5
55+
56+
+-------------------+-------------------------+
57+
|
58+
|
59+
v
60+
select max{node priority} = node 2
3761
```
3862

3963
The Scheduler tries to find a node for each Pod, one at a time.
@@ -60,12 +84,6 @@ the policies used are selected by the functions `defaultPredicates()` and `defau
6084
However, the choice of policies can be overridden by passing the command-line flag `--policy-config-file` to the scheduler, pointing to a JSON file specifying which scheduling policies to use. See [examples/scheduler-policy-config.json](../../examples/scheduler-policy-config.json) for an example
6185
config file. (Note that the config file format is versioned; the API is defined in [plugin/pkg/scheduler/api](http://releases.k8s.io/HEAD/plugin/pkg/scheduler/api/)).
6286
Thus to add a new scheduling policy, you should modify [plugin/pkg/scheduler/algorithm/predicates/predicates.go] (http://releases.k8s.io/HEAD/plugin/pkg/scheduler/algorithm/predicates/predicates.go) or add to the directory [plugin/pkg/scheduler/algorithm/priorities](http://releases.k8s.io/HEAD/plugin/pkg/scheduler/algorithm/priorities/), and either register the policy in `defaultPredicates()` or `defaultPriorities()`, or use a policy config file.
63-
64-
## Exploring the code
65-
66-
If you want to get a global picture of how the scheduler works, you can start in
67-
[plugin/cmd/kube-scheduler/app/server.go](http://releases.k8s.io/HEAD/plugin/cmd/kube-scheduler/app/server.go)
68-
6987
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
7088
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/devel/scheduler.md?pixel)]()
7189
<!-- END MUNGE: GENERATED_ANALYTICS -->

0 commit comments

Comments
 (0)