Kube-Scheduler plugin

The development of K8S is more and more like a frame, then leaves a variety of extensions to developers. Developers can combine their business scenes based on these interfaces to realize their own scenes. The Kube Scheduler fully reflects this character, and the previous article on Kube Scheduler itself, today I want to introduce how to add a schedule plugin for Scheduler.

We first define this plugin by YAML

apiVersion: kubescheduler.config.k8s.io/v1beta1kind: KubeSchedulerConfigurationclientConnection: kubeconfig: “/ etc / kubernetes / scheduler.conf” profiles: -schedulerName: default-schedulerplugins: score: enabled: -name: HelloWorldPlugindisabled: -name: “*” PluginConfig: -name: HelloWorldPluginargs: xxx: “xxx” YYY: “123” zzz: 3

We define a HelloWorldPlugin plugin and define the startup parameters of this plugin. Then you need to modify the Kube Scheduler startup parameter to specify the above profile through -config.

Next we need to implement this plugin, Scheduler determines the scheduled host by score the score of each plugin. So we need to implement a score interface

typeScorePlugininterface {Plugin // score Score (ctxcontext.Context, state * CycleState, p * v1.Pod, nodeNamestring) (int64, * Status) ScoreExtensions () ScoreExtensions} typeScoreExtensionsinterface {// score normalization, each widget ensure fair Sex Normalizescore (CTXContext.Context, State * CycleState, P * v1.pod, scorendescorelist) * status}

We implements this interface according to your business needs, such as the following example, based on the horizontal network bandwidth: first get the network traffic of the host through PrometHues, and score the network traffic size.

func (n * HelloWorldPlugin) Score (ctxcontext.Context, state * framework.CycleState, p * v1.Pod, nodeNamestring) (int64, * framework.Status) {nodeBandwidth, err: = n.prometheus.GetNodeBandwidthMeasure (nodeName) iferr! = nil {return0, framework.NewStatus (framework.Error, fmt.Sprintf ( “errorgettingnodebandwidthmeasure:% s”, err))} klog.Infof ( “[NetworkTraffic] node ‘% s’bandwidth:% s”, nodeName, nodeBandwidth .Value) Returnint64 (NodeBandWidth.Value), NIL}

We hope that the larger network traffic, the less score, so we translate into the final score by simply dealing with the following simple formula.

– (node.score * framework.maxnodescore / higherscore)} Klog.infof (“[NetworkTraft] NodesfinalScore:% v”, score) Returnnil} is implemented in plug-in based on network traffic schedule.

This article address: