Kubernetes cost optimisation techniques

You can use several techniques to optimize the cost of running your workload on a Kubernetes cluster.

  1. Cluster Autoscaler: Use Cluster Autoscaler to automatically adjust the number of nodes in your cluster based on the current resource usage. This technique will help you to save on costs by scaling down when resources are not needed and scaling up when they are. 
  2. Right-sizing of node pools: Create multiple node pools with different sizes, and schedule your workloads to the appropriate pool. Use taints, tolerations, and node selectors to schedule workloads onto specific node pools.
  3. Horizontal pod autoscaling (HPA): Use HPA to automatically adjust the number of pod replicas based on current resource usage. It will help you save on costs by scaling down when resources are not needed and scaling up when they are.
  4. Vertical Pod Autoscaler (VPA): Use VPA to automatically adjust your pods’ resource requests and limits based on the actual resource (memory or CPU) usage.
  5. Use spot (preemptible) VMs: Use spot instances for non-critical workloads, which are a lower-cost alternative to on-demand VMs. for non-critical workloads. It is important to remember the cloud provider will terminate spot VMs when there is a shortage of this particular VM size in a given region.
  6. Use Kubernetes cost management tools: Use Kubernetes cost management tools like KubeCost, Kubernetes Cost Explorer, Kubestat, and Kubernetes Cost Optimizer to get an overview of your cluster’s cost and identify areas for optimization. These areas usually include over-provisioning memory and CPU for pods.

From the above list, the Cluster Autoscaler, right-sizing of node pools, and monitoring resources are the easiest and the most gainful to Kubernetes optimising techniques. Once you apply the priority techniques, consider using VPA, HPA and spot instances for non-critical workloads.