Scaling Down an Environment to Optimize Resource Usage
This document outlines the process for scaling down an environment in a Kubernetes cluster.
Scaling down
#!/bin/bash
# Namespace to scale resources (set to 'default' if not specified)
NAMESPACE=${1:-default}
echo "Scaling all Deployments and StatefulSets in the namespace: $NAMESPACE to 0 replicas."
# Scale Deployments to 0 replicas
kubectl -n $NAMESPACE get deployments -o name | while read deployment; do
echo "Scaling $deployment to 0 replicas."
kubectl -n $NAMESPACE scale $deployment --replicas=0
done
# Scale StatefulSets to 0 replicas
kubectl -n $NAMESPACE get statefulsets -o name | while read statefulset; do
echo "Scaling $statefulset to 0 replicas."
kubectl -n $NAMESPACE scale $statefulset --replicas=0
done
echo "All Deployments and StatefulSets in the namespace: $NAMESPACE have been scaled to 0 replicas."Scaling up
How to use:
Last updated
Was this helpful?

