Quick Start¶
This guide creates a policy that right-sizes Deployments in a staging namespace using the p95 of the last 7 days of data.
1. Install k8s-sustain¶
helm repo add k8s-sustain https://noony.github.io/k8s-sustain
helm repo update
helm install k8s-sustain k8s-sustain/k8s-sustain \
--namespace k8s-sustain \
--create-namespace
2. Create a Policy¶
staging-policy.yaml
apiVersion: k8s.sustain.io/v1alpha1
kind: Policy
metadata:
name: staging-rightsizing
spec:
update:
types:
deployment: Ongoing # controller recycles stale pods; webhook injects resources
rightSizing:
resourcesConfigs:
cpu:
window: 168h # 7-day lookback
requests:
percentile: 95
headroom: 10 # +10% safety buffer
limits:
keepLimitRequestRatio: true
memory:
window: 168h
requests:
percentile: 95
headroom: 20
limits:
keepLimitRequestRatio: true
3. Opt in a Deployment¶
Add the annotation to the pod template of any Deployment you want right-sized:
kubectl patch deployment my-app -n staging \
--type=json \
-p='[{"op":"add","path":"/spec/template/metadata/annotations","value":{"k8s.sustain.io/policy":"staging-rightsizing"}}]'
Or add it directly in the Deployment manifest:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
namespace: staging
spec:
template:
metadata:
annotations:
k8s.sustain.io/policy: staging-rightsizing # (1)!
spec:
containers:
- name: app
image: my-app:latest
- This annotation tells k8s-sustain which policy governs this workload.
4. Wait for data¶
Cold start
Recording rules need at least one evaluation cycle (~1 minute) before data is available.
For meaningful percentile recommendations, allow data to accumulate for at least a few hours.
The operator logs no metrics yet, skipping for workloads with no data yet.
5. Check the Policy status¶
Look for the Ready condition:
status:
conditions:
- type: Ready
status: "True"
reason: ReconciliationSucceeded
message: All targeted workloads have been processed.
6. Verify resource changes¶
kubectl get deployment my-app -n staging \
-o jsonpath='{.spec.template.spec.containers[*].resources}'
The controller reconciles on a fixed 10m interval by default. To see changes sooner during testing, run the controller locally with --reconcile-interval=2m (see CLI Reference).
Next steps¶
- Use OnCreate mode to inject resources at pod creation without restarting existing pods → Update Modes
- Enable in-place updates for zero-restart resource changes on k8s ≥ 1.31 → In-Place Updates
- Right-size CronJobs → CronJob guide