The scheduling framework, which is a framework for creating your own Kubernetes scheduler, has been put in place. However, it is still in the alpha stage, so there is not enough information to actually make and try it, and it is a confusing situation. So, in this article, I will introduce a sample of a simple scheduling framework and how to run it. Furthermore, as an application example, we will explain the Coscheduling plug-in developed by kubernetes scheduler sigs.
I will explain only roughly. For more information, please refer to the good commentary already available.
A k8s management component that controls which node the pod starts on. By default, one default-scheduler is running.
scheduling framework There were some cases where people who were not satisfied with the default-scheduler webhook extension developed a scheduler with full scratch. However, full scratching seems excessive, as some parts behave the same as the default-scheduler. Therefore, a framework was created that allows scheduler development by describing only the behavior of the part that you want to change based on default-scheduler. That is the scheduling framework. (maybe)
The behavior of default schdeuler is roughly divided into the following phases
Code only the phase part you want to replace for these By compiling in combination with the default scheduler You can create a scheduler that says, "Change only the part you want to change and the others are the same as the default."
Actually, there are more detailed phases. There are small extension points such as PreFilter that run before Filter. See Kubernetes: Understanding kube-scheduler at the source code level and Official Manual for more information.
The sample source can be found on github. In addition, since I touched Go for the first time this time, please point out any strange points.
sample-scheduler.go
import(
"k8s.io/kubernetes/cmd/kube-scheduler/app"
//(Abbreviation)
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
)
type SampleScheduler struct {
framework.PreFilterPlugin
framework.PostBindPlugin
}
sample-scheduler.go
func (cs *SampleScheduler) PostBind(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeName string) {
klog.Infof("pod %v is binded to %v", pod.Name, nodeName)
}
sample-scheduler.go
func New(_ runtime.Object, _ framework.FrameworkHandle) (framework.Plugin, error) {
return &SampleScheduler{}, nil
}
sample-scheduler.go
func main() {
command := app.NewSchedulerCommand(
app.WithPlugin(Name, New),
)
logs.InitLogs()
defer logs.FlushLogs()
if err := command.Execute(); err != nil {
os.Exit(1)
}
}
app.NewSchedulerCommand
, command
with the extension plugin will be generated in the default scheduler.go build sample-scheduler.go
scheduler-config.yaml
apiVersion: kubescheduler.config.k8s.io/v1beta1
kind: KubeSchedulerConfiguration
leaderElection:
leaderElect: false
clientConnection:
kubeconfig: "/etc/kubernetes/admin.conf"
profiles:
- schedulerName: sample-scheduler
plugins:
preFilter:
enabled:
- name: SampleScheduler
postBind:
enabled:
- name: SampleScheduler
plugins. <extension point> .enabled
schedulerName: sample-scheduler
. Used to specify the scheduler when creating a pod.sudo ./sample-scheduler --authentication-kubeconfig=/etc/kubernetes/scheduler.conf --authorization-kubeconfig=/etc/kubernetes/scheduler.conf --config=scheduler-config.yaml --secure-port=10260
--config =
--Secure-port = 10260
is the listening port setting. It will start with the default of 10259 without it, but if there is a port conflict, you can avoid it by specifying it like this.--authentication-kubeconfig =
, --authorization-kubeconfig =
specifies the kubeconfig used by the scheduler. This time, we will use /etc/kubernetes/scheduler.conf
.default-scheduler
and sample-scheduler
are running.apiVersion: v1
kind: Pod
metadata:
name: sample-scheduler-pod
labels:
name: scheduler-example
spec:
schedulerName: sample-scheduler
containers:
- name: container1
image: k8s.gcr.io/pause:2.0
schedulerName: Specify the scheduler created by sample-scheduler
klog.Infof ("pod% v is bounded to% v ", pod.Name, nodeName)
described in the extension point has been executed.I1225 07:09:30.512923 10010 sample-scheduler.go:27] pre filter called for pod sample-scheduler-pod
I1225 07:09:30.516019 10010 sample-scheduler.go:34] pod sample-scheduler-pod is binded to node-hoge-hoge
The above sample has too little processing, and I think there is a big gap with the practical level. So, as a reference, I will briefly introduce how the k8s official extension plugin coscheduler uses the scheduling framework. The repository is kubernetes-sigs/scheduler-plugins
The default scheduler schedules pods one by one. However, if you want to launch multiple linked pods, The following deadlocks can occur:
The above deadlock occurs because you start the pods one by one. Therefore, you can avoid it by starting them all at once. This is called coschedule (or gang scheduling).
By using a combination of custom resources and scheduler plug-ins in this way, advanced scheduling is achieved.
Recommended Posts