3 min read | by Jordi Prats
To be able take advantage of using a Cluster Autoscaler (same applies to AWS Karpenter) we need make sure we properly set the resources any scheduled Pod is requesting to Kubernetes:
When we are not use the resources a given Pod or container is going to use, we can use the Vertical Pod Autoscaler to help us define them
The Vertical Pod Autoscaler can be found as part of the kubernetes autoscaler git repository. We can choose to install it using the script it provides of use one of the available helm charts, for example cowboysysop's helm. We can install it like so:
$ helm repo add cowboysysop https://cowboysysop.github.io/charts/ $ helm install my-release cowboysysop/vertical-pod-autoscaler
Once installed, we will be able to create a VerticalPodAutoscaler object that will define which mode the VPA operates in:
A VerticalPodAutoscaler object that is configured to Off would look like this:
apiVersion: autoscaling.k8s.io/v1 kind: VerticalPodAutoscaler metadata: name: pet2cattle-webserver spec: targetRef: apiVersion: "apps/v1" kind: Deployment name: pet2cattle-webserver updatePolicy: updateMode: "Off"
Once it's been applied to the system and have been able to collect metrics to make it's recommendations, we can retrieve them using kubectl describe vpa:
$ kubectl get vpa NAME MODE CPU MEM PROVIDED AGE pet2cattle-webserver Off 11m 26214400 True 107s $ kubectl describe vpa pet2cattle-webserver Name: pet2cattle-webserver Namespace: pet2cattle Labels: <none> Annotations: <none> API Version: autoscaling.k8s.io/v1 Kind: VerticalPodAutoscaler Metadata: (...) Spec: Target Ref: API Version: apps/v1 Kind: Deployment Name: pet2cattle-webserver Update Policy: Update Mode: Off Status: Conditions: Last Transition Time: 2022-02-07T11:23:51Z Status: True Type: RecommendationProvided Recommendation: Container Recommendations: Container Name: webapp Lower Bound: Cpu: 10m Memory: 26214400 Target: Cpu: 11m Memory: 26214400 Uncapped Target: Cpu: 11m Memory: 26214400 Upper Bound: Cpu: 541m Memory: 1160861333 Container Name: socat Lower Bound: Cpu: 10m Memory: 26214400 Target: Cpu: 11m Memory: 26214400 Uncapped Target: Cpu: 11m Memory: 26214400 Upper Bound: Cpu: 541m Memory: 566273869 Container Name: git-sync Lower Bound: Cpu: 10m Memory: 26214400 Target: Cpu: 11m Memory: 26214400 Uncapped Target: Cpu: 11m Memory: 26214400 Upper Bound: Cpu: 541m Memory: 566273869 Container Name: static Lower Bound: Cpu: 203m Memory: 1967849540 Target: Cpu: 671m Memory: 2162292018 Uncapped Target: Cpu: 671m Memory: 2162292018 Upper Bound: Cpu: 37571m Memory: 106473866755 Events: <none>
If we are using the Auto mode but want to skip some of the containers, we can add a containerPolicies to skip it as follows: Exempting containers from applying VPA recommendations
apiVersion: autoscaling.k8s.io/v1 kind: VerticalPodAutoscaler metadata: name: pet2cattle-webserver spec: targetRef: apiVersion: "apps/v1" kind: Deployment name: pet2cattle-webserver updatePolicy: updateMode: "Auto" resourcePolicy: containerPolicies: - containerName: my-opt-sidecar mode: "Off"
Posted on 14/02/2022