Categorygithub.com/kogakzbj9/customScheduler
repositorypackage
0.0.0-20250101114222-01f56fc12762
Repository: https://github.com/kogakzbj9/customscheduler.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# 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:

  1. Ensure you have Go installed on your machine.

  2. Navigate to the project directory:

    cd customScheduler
    
  3. 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:

  1. Ensure you have Docker installed on your machine.

  2. 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.

  3. Navigate to the project directory:

    cd customScheduler
    
  4. 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:

  1. Tag the Docker image with the registry URL:

    docker tag custom-scheduler:latest <your-registry-url>/custom-scheduler:latest
    
  2. 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:

  1. 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: 50
    • waitTime: 10
  2. Verify the creation of the ConfigMap:

    kubectl get configmap custom-scheduler-config -o yaml
    
  3. Create a service account for the custom scheduler:

    kubectl create serviceaccount custom-scheduler -n kube-system
    
  4. Create a cluster role binding for the custom scheduler:

    kubectl create clusterrolebinding custom-scheduler --clusterrole=system:kube-scheduler --serviceaccount=kube-system:custom-scheduler
    
  5. 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
    
  6. Create a role binding for storage-admin:

    kubectl create rolebinding -n kube-system storage-admin --role=storage-admin --serviceaccount=kube-system:custom-scheduler
    
  7. Deploy role, rolebinding

    kubectl apply -f role.yaml
    kubectl apply -f rolebinding.yaml
    
  8. Verify the creation of the custom-scheduler deployment:

    kubectl get deployments -n kube-system -l app=custom-scheduler
    
  9. Deploy the custom scheduler plugin as a Kubernetes Deployment:

    kubectl apply -f custom-scheduler-deployment.yaml -n kube-system
    
  10. Verify that the custom scheduler plugin is running:

kubectl get pods -n kube-system -l app=custom-scheduler
  1. 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:

  1. 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
    
  2. Apply the updated deployment:

    kubectl apply -f custom-scheduler-deployment.yaml
    
  3. 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:

  1. Create a test pod with the custom scheduler name:

    kubectl apply -f test-pod.yaml
    
  2. Verify that the test pod is scheduled by the custom scheduler:

    kubectl get pod test-pod -o jsonpath='{.spec.schedulerName}'
    
  3. 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:

  1. Check the events for the test pod:

    kubectl describe pod test-pod
    
  2. Check the logs for the test pod:

    kubectl logs test-pod
    
  3. 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.