Skip to content

Kube Startup CPU Boost is a controller that increases CPU resource requests and limits during Kubernetes workload startup time

License

Notifications You must be signed in to change notification settings

google/kube-startup-cpu-boost

Kube Startup CPU Boost

Kube Startup CPU Boost is a controller that increases CPU resource requests and limits during Kubernetes workload startup time. Once the workload is up and running, the resources are set back to their original values.

Build Version Go Report Card GitHub

Note: this is not an officially supported Google product.


Table of contents

Description

The primary use cases for Kube Startup CPU Boosts are workloads that require extra CPU resources during startup phase - typically JVM based applications.

The Kube Startup CPU Boost leverages In-place Resource Resize for Kubernetes Pods feature introduced in Kubernetes 1.27. It allows to revert workload's CPU resource requests and limits back to their original values without the need to recreate the Pods.

The increase of resources is achieved by Mutating Admission Webhook.

Installation

Requires Kubernetes 1.27 on newer with InPlacePodVerticalScaling feature gate enabled.

To install the latest release of Kube Startup CPU Boost in your cluster, run the following command:

kubectl apply -f https://github.com/google/kube-startup-cpu-boost/releases/download/v0.7.0/manifests.yaml

The Kube Startup CPU Boost components run in kube-startup-cpu-boost-system namespace.

Install with Kustomize

You can use Kustomize to install the Kube Startup CPU Boost with your own kustomization file.

cat <<EOF > kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- https://github.com/google/kube-startup-cpu-boost?ref=v0.7.0
EOF
kubectl kustomize | kubectl apply -f -

Installation on Kind cluster

You can use KIND to get a local cluster for testing.

cat <<EOF > kind-poc-cluster.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
name: poc
nodes:
- role: control-plane
- role: worker
- role: worker
featureGates:
  InPlacePodVerticalScaling: true 
EOF
kind create cluster --config kind-poc-cluster.yaml

Installation on GKE cluster

You can use GKE Alpha cluster to run against the remote cluster.

gcloud container clusters create poc \
    --enable-kubernetes-alpha \
    --no-enable-autorepair \
    --no-enable-autoupgrade \
    --region europe-central2

Usage

  1. Create StartupCPUBoost object in your workload's namespace

    apiVersion: autoscaling.x-k8s.io/v1alpha1
    kind: StartupCPUBoost
    metadata:
      name: boost-001
      namespace: demo
    selector:
      matchExpressions:
      - key: app.kubernetes.io/name
        operator: In
        values: ["spring-demo-app"]
    spec:
      resourcePolicy:
        containerPolicies:
        - containerName: spring-demo-app
          percentageIncrease:
            value: 50
      durationPolicy:
        podCondition:
          type: Ready
          status: "True"

    The above example will boost CPU requests and limits of a container spring-demo-app in a PODs with app.kubernetes.io/name=spring-demo-app label in demo namespace. The resources will be increased by 50% until the POD Condition Ready becomes True.

  2. Schedule your workloads and observe the results

Features

[Boost target] POD label selector

Define the PODs that will be subject for resource boost with a label selector.

spec:
  selector:
    matchExpressions:
    - key: app.kubernetes.io/name
       operator: In
       values: ["spring-rest-jpa"]

[Boost resources] percentage increase

Define the percentage increase for a target container(s). The CPU requests and limits of selected container(s) will be increase by the given percentage value.

spec:
  containerPolicies:
   - containerName: spring-rest-jpa
     percentageIncrease:
       value: 50

[Boost resources] fixed target

Define the fixed resources for a target container(s). The CPU requests and limits of selected container(s) will be set to the given values. Note that specified requests and limits have to be higher than the ones in the container.

spec:
  containerPolicies:
   - containerName: spring-rest-jpa
     fixedResources:
       requests: "1"
       limits: "2"

[Boost duration] fixed time

Define the fixed amount of time, the resource boost effect will last for it since the POD creation.

spec:
 durationPolicy:
  fixedDuration:
    unit: Seconds
    value: 60

[Boost duration] POD condition

Define the POD condition, the resource boost effect will last until the condition is met.

spec:
 durationPolicy:
   podCondition:
     type: Ready
     status: "True" 

License

Apache License 2.0