Skip to content

Commit

Permalink
⚡ Update devcontainer & WIP on Startup CPU Boost
Browse files Browse the repository at this point in the history
  • Loading branch information
nzuguem committed Jan 21, 2025
1 parent 76a19c3 commit 26cc912
Show file tree
Hide file tree
Showing 9 changed files with 178 additions and 4 deletions.
1 change: 1 addition & 0 deletions .devcontainer/scripts/postStartCommand.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set -e
# Configure Bash
cat <<EOF >> /home/vscode/.bashrc
source <(fzf --bash)
alias kubectl=kubecolor
alias k=kubectl
complete -o default -F __start_kubectl k
export PATH="${KREW_ROOT:-/home/vscode/.krew}/bin:$PATH"
Expand Down
9 changes: 8 additions & 1 deletion .github/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
# syntax=docker/dockerfile:1
FROM mcr.microsoft.com/devcontainers/base:ubuntu

## Install Taskfile
## Install Tools
RUN <<EOF
set -e

# Install Taskfile
sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d

# Install kubecolor
mkdir -p /tmp/kubecolor
wget https://github.com/kubecolor/kubecolor/releases/download/v0.5.0/kubecolor_0.5.0_linux_amd64.tar.gz -O /tmp/kubecolor/kubecolor.tar.gz
tar -xvzf /tmp/kubecolor/kubecolor.tar.gz -C /tmp/kubecolor
mv /tmp/kubecolor/kubecolor /usr/bin/local
rm -Rf /tmp/kubecolor
EOF
Binary file added discovery/images/kube-startup-cpu-boost.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions discovery/in-place-resource-resize-1.27-alpha/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# [In-Place Resource Resize - v1.27 [alpha]][in-place-resource-resize-blog]

## Késako ?

In-place resize allows operators to **dynamically modify** the CPU and memory resources of a **running pod** **without causing scheduling interruptions or downtime during the resizing process**. **This therefore allows a `kubectl patch ...` to be made on the `resources` of a deployment**

Instead of manually patching (`kubectl patch ...`), we can use the Kubernetes operator [Kube Startup CPU Boost
][kube-startup-cpu-boost-gh].

**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.

![Kube Startup CPU Boost](../images/kube-startup-cpu-boost.png)

## Install *Kube Startup CPU Boost*

```bash
task kube-startup-cpu-boost-install
```

## Test with Java Application

Java applications often require varying resources at different stages. During startup, the JVM typically demands more resources due to the heavy compute load involved in initial class loading and optimization. Once the application is running, resource requirements generally decrease. Since the JVM utilizes multi-threading, providing additional CPU resources can significantly speed up startup times.

### Without *Kube Startup CPU Boost*

```bash
kubectl apply -f discovery/in-place-resource-resize-1.27-alpha/spring-demo.deploy.yml

## Show Logs
kubectl logs deploy/spring-demo-app | grep "Started DemoApplication"
### ... Started DemoApplication in 90.322 seconds (process running for 100.79)
```

### *Kube Startup CPU Boost* in Action

```bash
kubectl delete -f discovery/in-place-resource-resize-1.27-alpha/spring-demo.deploy.yml

## Deploy Startup CPU Boost
## Increase container CPU requests and limits by 100% (to 2 cores) until the Pod reaches Ready condition.
kubectl apply -f discovery/in-place-resource-resize-1.27-alpha/startup-cpu-boost.yml

kubectl apply -f discovery/in-place-resource-resize-1.27-alpha/spring-demo.deploy.yml

## Show Logs
kubectl logs deploy/spring-demo-app | grep "Started DemoApplication"
### ... Started DemoApplication in 39.925 seconds (process running for 100.79)
```

## Resources

- [Faster startup times for Kubernetes workloads with Kube Startup CPU Boost][understanding-kubernetes-dynamic-resource-scaling-and-cpu-boost]
- [Warm up the relationship between Java and Kubernetes][understanding-kubernetes-dynamic-resource-scaling-and-cpu-boost]

<!-- Links -->
[in-place-resource-resize-blog]: https://kubernetes.io/blog/2023/05/12/in-place-pod-resize-alpha/
[understanding-kubernetes-dynamic-resource-scaling-and-cpu-boost]: https://cloud.google.com/blog/products/containers-kubernetes/understanding-kubernetes-dynamic-resource-scaling-and-cpu-boost?hl=en
[kube-startup-cpu-boost-gh]: https://github.com/google/kube-startup-cpu-boost
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: spring-demo-app
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: spring-demo-app
template:
metadata:
labels:
app.kubernetes.io/name: spring-demo-app
spec:
containers:
- name: spring-demo-app
image: ghcr.io/google/spring-demo-app:latest
args:
- --spring.config.location=file:/config/application.yaml
env:
- name: JAVA_OPTS
value: -XX:MaxRAMPercentage=75
volumeMounts:
- name: spring-demo-app-config
mountPath: /config
ports:
- name: http
containerPort: 8080
startupProbe:
periodSeconds: 2
failureThreshold: 60
httpGet:
path: /actuator/health
port: http
scheme: HTTP
livenessProbe:
httpGet:
path: /actuator/health
port: http
scheme: HTTP
resources:
limits:
cpu: "1"
memory: 512Mi
requests:
cpu: 500m
memory: 512Mi
volumes:
- name: spring-demo-app-config
configMap:
name: spring-demo-app-config

---

apiVersion: v1
kind: ConfigMap
metadata:
name: spring-demo-app-config
data:
application.yaml: |
spring:
datasource:
url: jdbc:h2:mem:mydb
username: sa
password: password
driverClassName: org.h2.Driver
jpa:
hibernate:
ddl-auto: create
database-platform: org.hibernate.dialect.H2Dialect
defer-datasource-initialization: true
management:
endpoints:
web:
exposure:
include:
- health
- prometheus
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: autoscaling.x-k8s.io/v1alpha1
kind: StartupCPUBoost
metadata:
name: boost-001
selector:
matchExpressions:
- key: app.kubernetes.io/name
operator: In
values: ["spring-demo-app"]
spec:
resourcePolicy:
containerPolicies:
- containerName: spring-demo-app
fixedResources:
requests: "1"
limits: "2"
durationPolicy:
fixedDuration:
unit: Seconds
value: 120
8 changes: 8 additions & 0 deletions discovery/tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,11 @@ tasks:
microcks-uninstall:
desc: Uninstall Microcks.
cmd: helm del -n microcks microcks

kube-startup-cpu-boost-install:
desc: Install Startup CPU Boost.
cmd: kubectl apply -f https://github.com/google/kube-startup-cpu-boost/releases/download/v0.11.3/manifests.yaml

kube-startup-cpu-boost-uninstall:
desc: Uninstall Startup CPU Boost.
cmd: kubectl delete -f https://github.com/google/kube-startup-cpu-boost/releases/download/v0.11.3/manifests.yaml
3 changes: 3 additions & 0 deletions kind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ featureGates:
# Kubernetes 1.31 - Alpha
# https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates/
ImageVolume: true
# Kubernetes 1.27 - Alpha
# https://kubernetes.io/blog/2023/05/12/in-place-pod-resize-alpha/
InPlacePodVerticalScaling: true
nodes:
- role: control-plane
image: kindest/node:v1.32.0
Expand Down
5 changes: 2 additions & 3 deletions security/ESO/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ task security:eso-install
## Create Secret Store
kubectl apply -f security/ESO/secretmanager.store.yml

## Storing a secret in AWS Secret Manager
## Storing a secret in AWS Secret Manager
aws secretsmanager create-secret \
--name my-eso-secret \
--description "My ESO Secret." \
Expand Down Expand Up @@ -60,10 +60,9 @@ task security:eso-uninstall
- [Secrets store CSI driver vs external secrets in a nutshel][eso-vs-csi-secrets-store]
- [Clarity: secrets store CSI driver vs external secrets... what to use? #478][eso-vs-csi-secrets-store-clarity]


<!-- Links -->
[eso-doc]:https://external-secrets.io/latest/
[k8s-secret-management-blog]: https://toungafranck.com/2024/05/09/gestion-des-secret-sur-kubernetes/
[eso-aws-custom-endpoints]: https://external-secrets.io/latest/provider/aws-secrets-manager/#custom-endpoints
[eso-vs-csi-secrets-store]: https://www.yuribacciarini.com/secrets-store-csi-driver-vs-external-secrets-in-a-nutshel/
[eso-vs-csi-secrets-store-clarity]: https://github.com/external-secrets/external-secrets/issues/478
[eso-vs-csi-secrets-store-clarity]: https://github.com/external-secrets/external-secrets/issues/478

0 comments on commit 26cc912

Please sign in to comment.