In this example, we’ll optimize Online Boutique, a demo e-commerce application running on microservices, by tuning the resources allocated to a selection of pods. This is a common use case where we want to minimize the cost associated with running an application without impacting the SLO.
Notice: all the required artifacts are published in this public repository.
Environment setup
The test environment includes the following instances:
Akamas: the instance running Akamas.
Cluster: an instance hosting a Minikube cluster.
You can configure the Minikube cluster using the scripts provided in the public repository by running the command
To gather metrics about the application we will use Prometheus. It will be automatically configured by applying the artifacts in the repository with the following command:
kubectl apply -f kubernetes-online-boutique/kube/
Application and Test tool
The targeted system is Online Boutique, a microservice-based demo application. In the same namespace, a deployment running the load generator will stress the boutique and forward the performance metrics to Prometheus.
To configure the application and the load generator on your (Minikube) cluster, apply the definitions provided in the public repository by running the following command:
kubectl apply -f kubernetes-online-boutique/kube/
Optimization setup
In this section, we will guide you through the steps required to set up the optimization on Akamas.
If you have not installed the Kubernetes optimization pack yet, take a look at the Kubernetes optimization pack page to proceed with the installation.
Notice: the artifacts to create the Akamas entities can be found in the public repository, under the akamas directory.
System
System Online Boutique
Here’s the definition of the system containing our components and telemetry-instances for this example:
name:Online Boutiquedescription:The Online Boutique by Google
We’ll use a component of type WebApplication to represent at a high level the Online Boutique application. To identify the related Prometheus metrics the configuration requires the prometheus property for the telemetry service, detailed later in this guide.
The public repository contains the definition of all the services that compose Online Boutique. In this guide, for the sake of simplicity, we’ll only tune the resources of the containers in the frontend and the product-catalog pods, defined as components of type Kubernetes Container.
Here’s their definition:
name:frontenddescription:The frontend of the online boutique by GooglecomponentType:Kubernetes Containerproperties:prometheus:job:.*instance:.*name:.*pod:ak-frontend.*container:server
name:productcatalogservicedescription:The productcatalogservice of the online boutique by GooglecomponentType:Kubernetes Containerproperties:prometheus:job:.*instance:.*name:.*pod:ak-productcatalogservice.*container:server
To create the component in the system run the following command:
To better illustrate the process, here is a snippet of the template file used to update the resource limits for the frontend deployment.
apiVersion:apps/v1kind:Deploymentmetadata:name:ak-frontendnamespace:akamas-demospec:selector:matchLabels:app:ak-frontendtemplate:metadata:labels:app:ak-frontend# other definitions...spec:containers: - name:serverimage:gcr.io/google-samples/microservices-demo/frontend:v0.2.2# other definitions...resources:requests:cpu:${frontend.cpu_limit}memory:${frontend.memory_limit}limits:cpu:${frontend.cpu_limit}memory:${frontend.memory_limit}# other definitions...
The following are respectively the script to start and stop the load generator:
If you have not installed the Prometheus telemetry provider yet, take a look at the telemetry provider page Prometheus provider to proceed with the installation.
With the definition of the telemetry instance shown below, we import the end-user performance metrics provided by the load-generator, along with a custom definition of "cost" given by a weighted sum of the CPU and memory allocated for the pods in the cluster:
With this study, we want to minimize the "cost" of running the application, which, according to the definition described in the previous section, it means reducing the resources allocated to the tuned pods in the cluster. At the same time, we want the application to stay within the expected SLO, and that is obtained by defining a constraint on the response time and error rate recorded by the load generator.