Optimize cost of a Kubernetes deployment subject to Horizontal Pod Autoscaler
In this guide, you optimize the cost (or resource footprint) of a Kubernetes deployment where the number of replicas is controlled by the HPA. The study tunes both pod resource settings (CPU and memory requests and limits) and HPA options (target CPU utilization) at the same time, while also taking into account your application performance and reliability requirements (SLOs). This optimization happens in production, leveraging Akamas Studio live optimization capabilities.
Prerequisites
an Akamas Studio instance
a Kubernetes cluster, with a deployment to be optimized
a Horizontal Pod Autoscaler working on the desired deployment
a supported telemetry data source configured to collect metrics from the target Kubernetes cluster (see here for the full list)
a way to apply configuration changes recommended by Akamas Studio to the target deployment and HPA. In this guide, Akamas Studio interacts directly with the Kubernetes APIs via
kubectl.You need a service account with permissions to update your deployment (see below for other integration options).
Optimization setup
In this guide, we assume the following setup:
the Kubernetes deployment to be optimized is called frontend (in the hipster-shop namespace)
in the deployment, there is a container named server, where the app runs
the HPA is called frontend-hpa
both Dynatrace and Prometheus are used as observability tools
Let's set up the Akamas Studio optimization for this use case.
System
For this optimization, you need the following components to model the frontend tech stack:
The Kubernetes Workload, Container and Pod components, containing metrics like CPU used for the different objects and parameters to be tuned like CPU limits at the container levels (from the Kubernetes optimization pack)
An HPA component, which contains HPA parameters like the target CPU utilization
A Web Application component, which contains service-level metrics like throughput and response time of the microservice (from the Web Applicationoptimization pack)
Let's start by creating the system, which represents the Kubernetes deployment to be optimized. To create it, write a system.yaml manifest like this:
Then run:
Now create the three Kubernetes components. Create a workload.yaml manifest like the following:
Then create a container.yaml manifest like the following:
And a pod.yaml manifest like the following:
Now create the entities by running:
Now create an application.yaml manifest like the following:
The run:
Finally, create anhpa.yaml manifest like the following:
Then run:
Workflow
To optimize a Kubernetes microservice in production, you need to create a workflow that defines how the new configuration recommended by Akamas will be deployed in production.
Let's explore the high-level tasks required in this scenario and the options you have to adapt it to your environment:
Let's now create a workflow.yaml manifest like the following:
Then run:
Telemetry
To collect metrics of your target Kubernetes deployment, you create a telemetry instance based on your observability setup.
Create a dynatrace.yamlmanifest like the following:
Then run:
Create a prometheus.yamlmanifest like the following:
Then run:
Study
It's now time to create the Akamas study to achieve your optimization objectives.
Let's explore how the study is designed by going through the main concepts. The complete study manifest is available at the bottom.
You can now create a study.yaml manifest like the following:
Then run:
You can now follow the live optimization progress and explore the results using the Akamas UI.
Last updated
Was this helpful?