kubernetes Scheduling Component Kube-scheduler Source analysis
1. Dispatch Flow chart
2 Introduction to the default scheduling algorithm
3 Data Structure
func
Main ()
{
Runtime. Gomaxprocs (runtime. NUMCPU ())
S:=options. Newschedulerserver ()
S.addflags (Pflag.commandline)
Util. Initflags ()
Util. Initlogs ()
defer util. Flushlogs ()
Verflag. Printandexitifrequested ()
App. Run (s)
}
The main function first constructs and initializes the schedulerserver structure, and the following is a look at the main data structures
Scheduling can be divided into two parts, the first part is the scheduling algorithm part, the second part is the dispatch execution part.
Data structure of Genericscheduler dispatch execution part
type genericscheduler struct{
Cacheschedulercache. Cache
predicates map[String]algorithm. Fitpredicate
Prioritizers []algorithm. Priorityconfig
Extenders []algorithm. Schedulerextender
Pods algorithm. Podlister
Random *rand. Rand
Random Locksync.mutex
Lastnodeindex UInt64
}
The Fitpredicate function is used to determine in node whether the resource requested by the pod satisfies the need.
type Priorityconfig struct{
Function priorityfunction
Weight int
}
Priorityconfig structures include function functions and weight integer variables, function functions are used to represent predictive algorithms, and weight variables are used to indicate the weighting of predictive algorithms.
The schedule in Genericscheduler is the function that is responsible for scheduling, which uses the Findnodesthatfit and prioritizenodes two functions. 4 Execution Process
1, new schedulerserver structure body
2, incoming parameters and initialize
Run
1, through Kubeconfig to create kubeclient for access to Apiserver
2, create htttpserver for performance analysis, performance metrics
3. Create Scheduler.config objects (periodically get a list of the already scheduled pods and remove them from the Modeler assumption queue). Monitor the available node, get the service list,
Create Genericscheduler