Question

Cost-Effective Node Scaling in Kubernetes on DigitalOcean?

Hey all,

I’m running a Kubernetes cluster on DigitalOcean and looking for tips on optimizing node scaling to balance cost and performance. How do you manage scaling down during off-peak hours without affecting critical services? Any tools or strategies you’d recommend?


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
August 25, 2024

Hey there!

The DigitalOcean Managed Kubernetes services comes with a built-in autoscaler that can automatically adjust the number of nodes in your cluster based on the workload. During off-peak hours, the autoscaler can scale down your Kubernetes nodes, reducing your costs.

Also in addition to that, you can use PodDisruptionBudget (PDB) which specifies the minimum number of replicas that an application can tolerate having during a voluntary disruption, relative to how many it is intended to have. For example, if you set the replicas value for a pod to 5, and set the PDB to 1, potentially disruptive actions like cluster upgrades and resizes occur with no fewer than four pods running.

You can check out the official documentation on how to do that here:

https://docs.digitalocean.com/products/kubernetes/how-to/autoscale/

In addition to the node autoscaling, you should also set up a Horizontal Pod Autoscaler (HPA) which scales the number of pods in your deployment based on observed CPU utilization (or other select metrics). This allows your services to handle more traffic when needed and scale down during quieter times.

You can follow the steps on how to do that here:

https://docs.digitalocean.com/products/kubernetes/how-to/set-up-autoscaling/

Basically, combining HPA with node autoscaling provides a very good approach to resource allocation, so that you don’t over-provision during low-demand periods but also scale accordingly whenever your load goes up.

Additionally, you should also look into setting resource requests and limits:

  • requests - Specifies how much of a resource (such as CPU and memory resources) a pod is allowed to request on a node before being scheduled. If the node doesn’t have the available resources, the pod will not be scheduled. This prevents pods from being scheduled on nodes that are already under heavy workload.

  • limits - Specifies the amount of resources (such as CPU and memory resources) a pod is allowed to utilize on a node. This prevents pods from potentially slowing down the work of other pods.

You can follow the steps on how to set that up here:

https://docs.digitalocean.com/products/kubernetes/concepts/best-practices/

And one more thing, you should also keep an eye on the basic metrics that come out of the box which includes CPU usage, load averages, bandwidth, and disk I/O. And if you want to take this a step further, consider setting up advanced monitoring as well:

https://docs.digitalocean.com/products/kubernetes/how-to/monitor-advanced/

If you have any other questions, feel free to ask!

- Bobby

To optimize node scaling in your DigitalOcean Kubernetes cluster while balancing cost and performance, consider these tips:

  1. Cluster Autoscaler: Automatically adds/removes nodes based on workload needs. Use Pod Disruption Budgets (PDBs) to prevent downtime for critical services during scaling down.

  2. Horizontal Pod Autoscaler (HPA): Scales pods based on CPU/memory usage, helping avoid scaling the whole node pool unnecessarily.

  3. Node Affinity & Taints: Assign critical services to specific nodes, allowing you to scale down non-critical workloads safely.

  4. KEDA: Use scheduled scaling (e.g., cron jobs) to adjust resources during off-peak times.

  5. Spot Instances: Save on costs by running non-critical workloads on cheaper spot instances.

  6. Monitor & Right-size: Tools like Prometheus, Grafana, and Kubecost can help track resource usage and recommend optimal node sizes.

By using these strategies, you can scale down during off-peak hours without affecting key services.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.