Supercharge Your Cluster: Implementing Descheduler on Kubernetes Cluster
Kubernetes provides a number of built-in functionalities to help with node workloads: NodeSelector, PodAffinity and Anti-PodAffinity. But those policies only apply when scheduling new pods. Once a pod is running, it doesn’t change in response to the cluster. This can create an improper workload distribution and resource utilization.
This issue can be solved with Descheduler. Descheduler provides an automated system for runtime rescheduling. It examines your cluster and re-allocates pods to your desired policies. It can help enhance performance, resource usage, and overall health of the cluster.
Why Do We Need Descheduler?
Kubernetes has its own approaches for affecting pod placement such as NodeSelector, NodeAffinity and Pod Topology Spread Constraints, but these are only used at scheduling time. Deploying the nodes means you have control of the deployment aspect of the function, but node utilization or node labels require manual handling to redeploy from 0 to N pod distribution.
Descheduler fills this gap by automatically re-scheduling the pods according to specified policies. This eliminates operator intervention and enables workload optimization without any human interaction.
Next up in Series: Install a Helm on Your K8S Cluster,Step 1
Make sure that Helm is installed and has been configured to work with your Kubernetes cluster.
Step 1: Add Descheduler Helm Chart Repo
If not you can add the descheduler chart repo: https://kubernetes-sigs.github.io/descheduler/
Run the following commands:
kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/descheduler/main/deploy/descheduler-operator/deploy/descheduler-operator.yaml
Update the descheduler-image in the descheduler-configmap with a custom imagehelmmicrosofthostapplicationavito.
helm repo update
Step 2: Install Descheduler with Custom Values
Customise a values file (descheduler-values. yaml) for the policies you want to setup and the parameters.
Simple descheduler-values example. yaml file:
descheduler:
policyConfig:
policies:
- name: "RemovePodsHavingTooManyRestarts"
strategy: "RemovePodsHavingTooManyRestarts"
params:
threshold: 5
excludeKinds: ["DaemonSet"]
- name: "LowNodeUtilization"
strategy: "LowNodeUtilization"
params:
thresholds:
cpu: 20
memory: 20
targetThresholds:
cpu: 40
memory: 40
- name: "RemoveDuplicatePods"
strategy: "RemoveDuplicatePods"
schedule:
interval: "1h"
This configuration contains policies for:
Filtering out already restarted pods
Redistributing utilization across nodes by evicting pods from underutilized nodes
Nuke unnecessary pods, to release resources
Use the command below to apply the configuration with Helm:
helm install descheduler descheduler/descheduler -f descheduler-values. yaml
Step 3: Confirm the Successful Installation of Descheduler
Verify that the Descheduler pod is functioning as expected:
kubectl get pods -n kube-system | grep descheduler
Conclusion :-
Well, folks, we’ve come to the end of our Descheduler journey! Let’s take a moment to reflect on what we’ve learned and why it matters for your Kubernetes clusters.
Remember how we started by talking about the challenges of keeping our clusters running smoothly? Descheduler has proven to be a fantastic tool to help with that. It’s like having a helpful assistant that tidies up your cluster, making sure everything is in its right place.