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.
Note: this is not an officially supported Google product.
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.
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.9.0/manifests.yaml
The Kube Startup CPU Boost components run in kube-startup-cpu-boost-system
namespace.
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.9.0
EOF
kubectl kustomize | kubectl apply -f -
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
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
-
Create
StartupCPUBoost
object in your workload's namespaceapiVersion: 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 withapp.kubernetes.io/name=spring-demo-app
label indemo
namespace. The resources will be increased by 50% until the POD ConditionReady
becomesTrue
. -
Schedule your workloads and observe the results
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"]
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
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"
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
Define the POD condition, the resource boost effect will last until the condition is met.
spec:
durationPolicy:
podCondition:
type: Ready
status: "True"