# Packages
# README
customScheduler
Description
This project implements a custom scheduler plugin for Kubernetes. The custom scheduler plugin allows you to define custom scheduling logic for your Kubernetes cluster. This project is under construction.
Building the Custom Scheduler Binary
To build the custom scheduler binary, follow these steps:
-
Ensure you have Go installed on your machine.
-
Navigate to the project directory:
cd customScheduler
-
Build the custom scheduler binary:
go build -o custom-scheduler .
Building the Docker Image
To build the Docker image for the custom scheduler, follow these steps:
-
Ensure you have Docker installed on your machine.
-
If you are using Minikube, run the following command to set up the Docker environment:
eval $(minikube docker-env)
This command configures Docker to use the Minikube Docker daemon, allowing you to build Docker images directly inside the Minikube environment.
-
Navigate to the project directory:
cd customScheduler
-
Build the Docker image:
docker build -t custom-scheduler:latest .
Pushing the Docker Image to a Registry
To push the Docker image to a registry, follow these steps:
-
Tag the Docker image with the registry URL:
docker tag custom-scheduler:latest <your-registry-url>/custom-scheduler:latest
-
Push the Docker image to the registry:
docker push <your-registry-url>/custom-scheduler:latest
Deploying the Custom Scheduler Plugin
To deploy the custom scheduler plugin to your Kubernetes cluster, follow these steps:
-
Create a ConfigMap for the custom scheduler configuration:
kubectl create configmap custom-scheduler-config --from-file=config.yaml -n kube-system
The ConfigMap should contain the following keys with their default values:
cpuThreshold
: 50waitTime
: 10
-
Verify the creation of the ConfigMap:
kubectl get configmap custom-scheduler-config -o yaml
-
Create a service account for the custom scheduler:
kubectl create serviceaccount custom-scheduler -n kube-system
-
Create a cluster role binding for the custom scheduler:
kubectl create clusterrolebinding custom-scheduler --clusterrole=system:kube-scheduler --serviceaccount=kube-system:custom-scheduler
-
Create a role binding for
extension-apiserver-authentication-reader
:kubectl create rolebinding -n kube-system extension-apiserver-authentication-reader --role=extension-apiserver-authentication-reader --serviceaccount=kube-system:custom-scheduler
-
Create a role binding for
storage-admin
:kubectl create rolebinding -n kube-system storage-admin --role=storage-admin --serviceaccount=kube-system:custom-scheduler
-
Deploy role, rolebinding
kubectl apply -f role.yaml kubectl apply -f rolebinding.yaml
-
Verify the creation of the custom-scheduler deployment:
kubectl get deployments -n kube-system -l app=custom-scheduler
-
Deploy the custom scheduler plugin as a Kubernetes Deployment:
kubectl apply -f custom-scheduler-deployment.yaml -n kube-system
-
Verify that the custom scheduler plugin is running:
kubectl get pods -n kube-system -l app=custom-scheduler
- Verify the correctness of the command execution results:
kubectl logs <pod-name> -n kube-system
Deploying the Custom Scheduler Using the Docker Image
To deploy the custom scheduler using the Docker image, follow these steps:
-
Update the
custom-scheduler-deployment.yaml
file to use the Docker image from your registry:apiVersion: apps/v1 kind: Deployment metadata: name: custom-scheduler namespace: kube-system labels: app: custom-scheduler spec: replicas: 1 selector: matchLabels: app: custom-scheduler template: metadata: labels: app: custom-scheduler spec: containers: - name: custom-scheduler image: <your-registry-url>/custom-scheduler:latest imagePullPolicy: IfNotPresent ports: - containerPort: 10259 serviceAccountName: custom-scheduler
-
Apply the updated deployment:
kubectl apply -f custom-scheduler-deployment.yaml
-
Verify that the custom scheduler is running using the Docker image:
kubectl get pods -n kube-system -l app=custom-scheduler
Testing the Custom Scheduler Plugin
To test the custom scheduler plugin, follow these steps:
-
Create a test pod with the custom scheduler name:
kubectl apply -f test-pod.yaml
-
Verify that the test pod is scheduled by the custom scheduler:
kubectl get pod test-pod -o jsonpath='{.spec.schedulerName}'
-
Check the status of the test pod:
kubectl get pod test-pod -o jsonpath='{.status.phase}'
Investigating Non-Running States of the Test Pod
If the test pod is not in the Running
state, follow these steps to investigate the issue:
-
Check the events for the test pod:
kubectl describe pod test-pod
-
Check the logs for the test pod:
kubectl logs test-pod
-
Common issues and resolutions:
Pending
: The pod is waiting to be scheduled. Check for resource constraints or scheduling issues.Failed
: The pod has encountered an error. Check the pod's events and logs for more details.Unknown
: The pod's state is unknown. Check the node's status and connectivity.
Using the cpuSpike Annotation
The custom scheduler plugin can also use the cpuSpike
annotation to override the default CPU threshold for a specific Pod. To use the cpuSpike
annotation, add it to the Pod's metadata with the desired CPU threshold value. For example:
apiVersion: v1
kind: Pod
metadata:
name: test-pod
annotations:
cpuSpike: "75"
spec:
containers:
- name: test-container
image: nginx
In this example, the cpuSpike
annotation is set to 75
, which means the custom scheduler will use a CPU threshold of 75% for this Pod instead of the default value.
Debug Logging
The custom scheduler plugin now includes debug logging to help you understand the flow of execution and the values of key variables. The debug logs are generated using klog
and can be found in the log files.
To enable debug logging, ensure that the klog
flags are set appropriately when running the custom scheduler. For example:
./custom-scheduler -v=4
The -v=4
flag sets the verbosity level to 4, which enables debug logging. You can adjust the verbosity level as needed.
Contributing
If you would like to contribute to this project, please open an issue or submit a pull request.
License
This project is licensed under the MIT License.