Skip to content

Commit

Permalink
Add copy edits
Browse files Browse the repository at this point in the history
  • Loading branch information
vansia43 committed Apr 9, 2024
1 parent 9f21a00 commit 991037c
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions docs/kubernetes/kubernetes-rightsizing.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
title: Kubernetes Rightsizing
title: Kubernetes Rightsizing | Cloud Cost Handbook

Without proper resource allocation, Kubernetes clusters can become overprovisioned, leading to wasted resources and increased costs. _Kubernetes rightsizing_ is the process of optimizing resource allocation to find a balance between performance, efficiency, and cost-effectiveness. The goal of rightsizing is to match the resources allocated to each workload with the actual resource requirements of the workload, therefore avoiding overprovisioning.

## Kubernetes Resource Management

Kubernetes [resource management](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/) is based on setting resource parameters, like CPU (compute) and memory. Kubernetes orchestrates the allocation of pods onto nodes based on resource requirements, to ensure efficient utilization of cluster resources. Each container within a Kubernetes pod needs a certain amount of CPU and memory to optimally function. Kubernetes provides mechanisms for specifying resource _requests_ and _limits_ for each container in a pod.
Kubernetes [resource management](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/) is based on setting resource parameters, like CPU (compute) and memory. Kubernetes orchestrates the allocation of pods onto nodes, based on resource requirements, to ensure efficient utilization of cluster resources. Each container within a Kubernetes pod needs a certain amount of CPU and memory to optimally function. Kubernetes provides mechanisms for specifying resource _requests_ and _limits_ for each container in a pod.

- **Resource requests:** The amount of CPU and memory that a container needs to run. A container, running within a pod on a node, can use more resources than what is specified in its `requests`.
- **Resource requests:** The amount of CPU and memory that a container needs to run. A container running within a pod on a node can use more resources than what is specified in its `requests`.
- **Resource limits:** The maximum amount of CPU and memory that a container can consume. Containers cannot use more resources than what’s specified in its `limits`.

The `requests` and `limits` are set within the resources for each container with a pod as follows.
The `requests` and `limits` are set within the resources for each container within a pod as follows.

```yaml
apiVersion: v1
Expand All @@ -34,20 +34,19 @@ spec:

Rightsizing Kubernetes resources is especially important from both a cost and infrastructure perspective.

- **Cost optimization:** Overprovisioned workloads lead to unnecessary expenses since more resources are allocated than what is required.
- **Cost optimization:** Overprovisioned workloads lead to unnecessary expenses since more resources are allocated than what's required.
- **Performance optimization:** Applications need to have the necessary computing power and memory to perform efficiently. It’s important to properly allocate resources and avoid issues with your applications’ performance. Containers that try to use more resources than allocated, like memory, could run into errors, like `OOMKilled`.
- **Scalability:** During peak usage periods or times (e.g., increased demand based on seasonality) when you need resources to scale, resources need to be rightsized to meet changing or increased demands. Understanding these peak usage periods better helps to determine how you should rightsize for the future.
- **Scalability:** During peak usage periods or times (e.g., increased demand based on seasonality), and when you need resources to scale, resources need to be rightsized to meet changing or increased demands. Understanding these peak usage periods better helps to determine how you should rightsize for the future.

## Kubernetes Rightsizing Process

Kubernetes rightsizing is a continuous process to monitor your infrastructure, collect metrics, adjust resources, and finally, review and reassess.
Kubernetes rightsizing is a continuous process to monitor your infrastructure, collect metrics, adjust resources, and finally, review and reassess. The process repeats itself as you continually monitor changes or spikes in usage.

![The Kubernetes rightsizing process with four boxes pointing to each other: Monitor Infrastructure, Collect Metrics, Adjust Resources, Review and Reassess. The last box has an arrow that points back to the first.](/img/kubernetes/rightsize-k8s.png)

- **Monitor Infrastructure:** You can use Kubernetes monitoring tools, like [Prometheus](https://prometheus.io/), to gather insights about resource usage patterns. You can also use other tools, like the [Vantage Kubernetes agent](https://docs.vantage.sh/kubernetes_agent) integration and [rightsizing recommendations](https://docs.vantage.sh/cost_recommendations#kubernetes-rightsizing), to keep an eye on your costs and resource usage over time.
- **Collect Metrics:** Review metrics, like average or maximum usage, for each container. Be sure to review current and historical workload data to make decisions on resource allocation. Rightsizing recommendations in Vantage provide a view of your current configuration, average, and maximum usage for CPU and memory. The chart includes a per-day average usage. The table provides a 30-day average and 30-day average max usage. An estimate of potential monthly savings is also provided based on the recommended configuration.

- **Adjust Resources:** There are several tools and methods you can use to adjust Kubernetes resources. You can manually adjust resources or consider automated alternatives. Some suggestions are provided below:
- **Adjust Resources:** There are several tools and methods you can use to adjust Kubernetes resources. You can manually adjust resources or consider automated alternatives. Some suggestions are provided below.
- **Horizontal Pod Autoscaler (HPA):** This [Kubernetes tool](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/) automatically scales workloads based on demands. Horizontal scaling indicates that more pods will be deployed. As each load decreases, the HPA will also scale down the pods within the workload.
- **Vertical Pod Autoscaler (VPA):** You can also vertically scale workloads using the VPA. Vertical scaling means you adjust the existing infrastructure to meet demands rather than adding new pods. [This project](https://github.com/kubernetes/autoscaler/tree/9f87b78df0f1d6e142234bb32e8acbd71295585a/vertical-pod-autoscaler) automatically sets requests for containers based on usage.
- **Quality of Service (QOS):** Adjust resource requests and limits to ensure your workloads are assigned the necessary [QOS class](https://kubernetes.io/docs/tasks/configure-pod-container/quality-service-pod/). This ensures your workloads receive the necessary resources when node resources are exceeded.
Expand All @@ -65,22 +64,22 @@ spec:
image: test-nodejs-image
resources:
requests:
memory: "1Gi"
memory: "1000Mi"
cpu: "1000m"
limits:
memory: "2Gi"
cpu: "2"
memory: "2000Mi"
cpu: "2000m"
...
```

Based on the above configuration:

- The container’s `requests` parameter is set to 1 Gi of memory and 1000 mCPU to run.
- The container’s `limits` parameter is set to 2 Gi of memory and 2000 mCPU.
- The container’s `requests` parameter is set to 1000 MiB of memory and 1000 mCPU to run.
- The container’s `limits` parameter is set to 2000 MiB of memory and 2000 mCPU.

Over time, the actual resource utilization is _significantly lower_ than the currently allocated resources. The application, on average, uses about 300 MiB of memory and 200 mCPU under normal operating conditions. In this case, the workload is overprovisioned. The allocated resources exceed the actual requirements of the application, which could lead to higher costs and wasted resources.

In the example below, this container is monitored via the Vantage Kubernetes Rightsizing Recommendations feature. Average and maximum usage are provided along with the recommended suggestion to rightsize and potential monthly savings.
In the example below, this container is monitored by the Vantage Kubernetes agent and rightsizing recommendations. Average and maximum usage are provided along with the recommended suggestion to rightsize and potential monthly savings.

![The Kubernetes Rightsizing UI in the Vantage console with a sample recommendation](/img/kubernetes/k8s-rightsizing-ui.png)

Expand Down

0 comments on commit 991037c

Please sign in to comment.