How to guess the right size for your Kubernetes Pods?

Pavan Kumar
Level Up Coding
Published in
5 min readOct 31, 2022

--

Guessing the right size for your Kubernetes resources and FinOps management using Goldilocks

Have you ever wondered what the right size for your Kubernetes Pods is? Or Did you often overcommit the resources for your Pod and then were surprised to see the cloud costs at the end of the month? This is the most common scenario that happens with most Kubernetes resources. What is the best way to find out the resources for our workloads then? Does it mean that we will always have to overcommit the resources or always go by guess? No, not always. Goldilocks is here to help. Goldilocks is a utility that can help you identify a starting point for resource requests and limits. By using the Kubernetes vertical-pod-autoscaler (opens new window) in recommendation mode, we can see a suggestion for resource requests on each of our apps. This tool creates a VPA for each workload in a namespace and then queries them for information.

What is the entire story all about? (TLDR)

  1. Accommodate the required resources to your Kubernetes workloads.
  2. Understand how Goldilocks could be used to determine the correct resources for the Kubernetes Pods.

Story Resources

  1. GitHub Link: https://github.com/pavan-kumar-99/medium-manifests
  2. GitHub Branch: goldilocks

Prerequisites

  1. A Kubernetes Cluster ( EKS, AKS, Kind Cluster, etc ).

Installing Goldilocks

By using the Kubernetes vertical-pod-autoscaler (opens new window)in recommendation mode, we can see a suggestion for resource requests on each of our apps. This tool creates a VPA for each workload in a namespace and then queries them for information.

Once your VPAs are in place, you’ll see recommendations appear in the Goldilocks dashboard. Goldilocks can be installed via helm chart and the values could be found here.

This is the custom helm values file that I have used to install Goldilocks.

As a part of this, I am installing the following components.

  1. VPA ( Only Recommender ): So, when a VPA is installed in a recommender mode, it will only provide recommendations to our workloads but does no changes to it.
  2. metrics-server ( Goldilocks metrics server ): This is to extract the VPA metrics from the VPA pod.
  3. Controller ( Goldilock controller ): This is responsible for creating the VPA’s for the resources in the namespaces. The namespaces should be labeled with goldilocks.fairwinds.com/enabled=true.
  4. Dashboard ( Goldilock Dashboard ): To visualize the sizings for the Kubernetes resources ( Pods, Containers ).
$ helm repo add fairwinds-stable https://charts.fairwinds.com/stable$ git clone https://github.com/pavan-kumar-99/medium-manifests.git \
-b goldilocks
$ cd medium-manifests$ helm upgrade -i goldilocks -n goldilocks --create-namespace goldilocks fairwinds-stable/goldilocks -f goldilocks-helm-values.yaml
GoldiLocks components

I have also exposed the Dashboard as a load balancer. Let us try accessing it now.

$ kubectl get svc -n goldilocks goldilocks-dashboard -o \ jsonpath='{.status.loadBalancer.ingress[0].ip}'

You can now visit the IP, by opening http://<IP> in the browser. Now the dashboard should be empty.

Getting Data

Now, let us get into action. Let us now visualize the resources needed for an Ingress controller by installing it using the helm chart.

$ helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx$ helm repo update$ helm install ingress ingress-nginx/ingress-nginx

Let us now label both the namespaces. default and goldilocks to get a sense of the resources needed by our Pods. You should now observe in the controller pod logs that the VPA’s are getting created for all the resources in the namespaces that are labeled with goldilocks.fairwinds.com/enabled=true

$ kubectl label ns default goldilocks.fairwinds.com/enabled=true$ kubectl label ns goldilocks goldilocks.fairwinds.com/enabled=true
Goldilocks Dashboard

You should now find a very beautiful dashboard that gives you a hunch of what are the requests/limits that are needed for this pod along with their respective QoS. In case you are wondering what QoS is please refer to this doc for further insights.

Alright, that's it? No, there's more. What would be your thoughts if you can see the costs for this Pod’s configuration as well? Yes, it is possible !!

You can add cost estimates by adding your e-mail here. You should receive an api-key from the Goldilocks team to activate the cost estimates.

So, I am using a GKE cluster of size e2-standard-2, and I am going to select the same option here by selecting the list from the drop-down.

GoldiLocks cost settings

After the cost estimates are enabled, you should see a dashboard with the cost estimates per pod/container with their respective QoS.

Costing per pod.

Closing Thoughts

So this is how Goldilocks can be utilized by Developers, SRE, and DevOps teams to calculate the right estimates for all their workloads and also from the FinOps perspective. Please feel free to share your experience while implementing this in your clusters.

Until next time…..

Recommended

--

--

Senior Cloud DevOps Engineer || CKA | CKS | CSA | CRO | AWS | ISTIO | AZURE | GCP | DEVOPS Linkedin:https://www.linkedin.com/in/pavankumar1999/