Scheduling is the process of selecting a node for a pod to run on.
In this lab we will write our own pods scheduler.
It is probably not something that you will ever need to do, but still it’s a good practice to understand how scheduling works in K8S and how you can extend it.
#### Sample KubeSchedulerConfiguration##### You can configure `kube-scheduler` to run more than one profile.# Each profile has an associated scheduler name and can have a different# set of plugins configured in its extension points.# With the following sample configuration, # the scheduler will run with two profiles: # - default plugins # - all scoring plugins disabledapiVersion:kubescheduler.config.k8s.io/v1beta1kind:KubeSchedulerConfigurationprofiles:-schedulerName:default-scheduler-schedulerName:no-scoring-schedulerplugins:preScore:disabled:-name:'*'score:disabled:-name:'*'
Once you have your scheduler code, you can use it in your pod scheduler:
# In this sample we use deployment but it will apply to any pod...apiVersion:apps/v1kind:Deploymentspec:spec:# This is the import part of this file.# Here we define our custom schedulerschedulerName:CodeWizardScheduler# <------containers:-name:nginximage:nginx
The “trick” is loop over all the waiting pods and search for the custom scheduler match in spec.schedulerName
...
# Get a list of all our pods in pending stateforPODin$(kubectlgetpods\--server${CLUSTER_URL}\--all-namespaces\--outputjsonpath='{.items..metadata.name}'\--field-selector=status.phase==Pending);do# Get the desired schedulerName if th epod has defined any schedulerNameCUSTOM_SCHEDULER_NAME=$(kubectlgetpod${POD}\--outputjsonpath='{.spec.schedulerName}')# Check if the desired schedulerName is our custome one# If its a match this is where our custom scheduler will "jump in"if["${CUSTOM_SCHEDULER_NAME}"=="${CUSTOM_SCHEDULER}"];then# Do your magic here ......# Schedule the PODS as you wishfi...