Turn Off and Turn On an Application in Kubernetes

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:

ComponentKubernetes ResourceNamespace
thingsboardDeploymentthingsboard
postgresqlStatefulSetthingsboard
thingsboard-serviceServicethingsboard
thingsboard-tlsSecretthingsboard

You only need to scale the Deployment and StatefulSet to stop the application.


Turn Off the Application

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

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


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

  1. 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.)


  1. Watch Them Spin Up
kubectl get pods -n thingsboard -w

Wait until pods reach Running status.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top