Sometimes, you may want to temporarily shut down an application in Kubernetes to save resources, perform maintenance, or simply pause it in non-production environments. Kubernetes doesn’t have a literal “power off” switch, but you can accomplish the same by scaling the workloads to zero replicas and later scaling them back up.
This guide shows you how to gracefully turn off and turn on a Kubernetes application using kubectl
.
What Does “Turn Off” Mean in Kubernetes?
In Kubernetes, turning off an application means scaling its Deployments or StatefulSets to zero, stopping the associated pods. This is like powering off a system without deleting it.
All configuration, Persistent Volume Claims (PVCs), Services, and Secrets remain intact, you’re just halting execution.
Example: ThingsBoard Application
Suppose your application (e.g., ThingsBoard) includes the following components:
Component | Kubernetes Resource | Namespace |
---|---|---|
thingsboard | Deployment | thingsboard |
postgresql | StatefulSet | thingsboard |
thingsboard-service | Service | thingsboard |
thingsboard-tls | Secret | thingsboard |
You only need to scale the Deployment
and StatefulSet
to stop the application.
Turn Off the Application
- List Running Workloads
kubectl get deployments,statefulsets -n thingsboard
Sample output:
NAME READY UP-TO-DATE AVAILABLE AGE
deployment/thingsboard 1/1 1 1 5d
statefulset/postgresql 1/1 1 1 5d
- Scale Replicas to Zero
kubectl scale deployment thingsboard --replicas=0 -n thingsboard
kubectl scale statefulset postgresql --replicas=0 -n thingsboard
This stops all running pods, just like turning off a system.
- Confirm It’s Off
kubectl get pods -n thingsboard
You should see no running pods or pods in Terminating
state if they’re still stopping.
Turn On the Application
- Scale Back to Original Replica Count
kubectl scale deployment thingsboard --replicas=1 -n thingsboard
kubectl scale statefulset postgresql --replicas=1 -n thingsboard
(Adjust the replica count if your app had more pods.)
- Watch Them Spin Up
kubectl get pods -n thingsboard -w
Wait until pods reach Running
status.