Skip to main content
Version: 2.3

Sleep Mode & Auto-Delete in Loft

Loft provides two powerful features to reduce Kubernetes cost:

  • Sleep Mode which puts namespaces to sleep when nobody is using them, i.e. purging all pods while keeping all resources inside the namespaces during periods of inactivity
  • Auto-Delete which deletes namespaces that have been idle for a while

Both of these feature typically rely on Loft's inactivity detection.

Sleep Mode

With sleep mode, you can put Kubernetes namespaces to sleep which means that Loft will set replicas: 0 for all replica-controlled resources such as Deployments and StatefulSets. This means that Kubernetes will delete all pods but the entire configuration of resources within the namespace is still there.

Sleep mode can be:

  • Invoked manually
  • Triggered by an inactivity timeout (no one has ran a kubectl command in this namespace for X minutes)
  • Scheduled using a CRON syntax

Manual + Automatic Sleep / Wake-up

Start Sleep (manual)
  1. In the Spaces view, hover over the row of the space that you want to put to sleep
  2. While hovering over the row, you will see buttons appear on the right in the Actions column
  3. Click on the button to put the space to Sleep
  4. Notice how the Status column shows that the space is now sleeping.
Automatic Wakeup

Note that the space will automatically wake up again, once you run a kubectl command within the space.

Automatic Sleep Mode (individual space)
  1. In the Spaces view, hover over space that you want to configure automatic sleep mode for
  2. While hovering over the row, you will see buttons appear on the right in the Actions column
  3. Click on the button to Edit the space
  4. In the drawer that appears on the right, expand the Sleep Mode section
  5. Use the Sleep After Inactivity field to specify the Time (in minutes) to wait before putting the space to sleep if there is no more user activity in this namespace
  6. On the very bottom, click on the button to save the changes
Wake up space
  1. In the Spaces view, hover over the Status column of the space that you want to put to sleep
  2. While hovering over the row, you will see a tooltip appear that provide information about the sleep state of this space
  3. Click on the button to wakeup the space
  4. Notice how the Status column shows that the space is now Active again.

Scheduled Sleep / Wake-up

Scheduled Sleep & Wake-Up (individual space)
  1. In the Spaces view, hover over space that you want to configure automatic sleep mode for
  2. While hovering over the row, you will see buttons appear on the right in the Actions column
  3. Click on the button to Edit the space
  4. In the drawer that appears on the right, expand the Sleep Mode section
  5. Expand the Sleep & Wake-Up Schedule section
  6. Use the Sleep Schedule field and/or the Wake-Up Schedule field to specify the Conjob Times when the respective namespace should be put to sleep or woken up
  7. On the very bottom, click on the button to save the changes

Enforce Sleep Settings

Enforce Sleep Mode For All Spaces Created By User/Team
  1. Go to the Clusters view using the menu on the left
  2. Switch to the Space Constraints tab
  3. Option A: Hover over the space constraints object that you want to configure automatic sleep mode with and click on the button to Edit an existing space constraints object

    Option B: Click the button to create a new space constraints object

  4. In the drawer that appears on the right, expand the Enforce Space Settings section
  5. Use the Sleep After Inactivity field to specify the Time (in minutes) to wait before putting the space to sleep if there is no more user activity in this namespace
  6. On the very bottom, click on the or button to save the changes
  7. Switch to the Cluster Access tab
  8. Hover over the cluster access of the user or team that you want to configure automatic sleep mode for and click on the button to Edit the cluster access
  9. In the drawer that appears on the right, expand the Restrictions section
  10. Use the Enforce Space Constraints field to select the Space Constraint you edited or created in Step 3 above
  11. On the very bottom, click on the button to update the cluster access
Test with Impersonation

After following the steps above, all spaces created using the cluster access in step 7 will now enforce sleep mode. You can test this behavior by impersonating a user that uses this cluster access.

Auto-Delete

Loft lets you configure an auto-delete for namespaces that have not been used for a certain period of time (inactivity).

Configure Auto-Delete Timeout (individual space)
  1. In the Spaces view, hover over space that you want to configure auto-delete for
  2. While hovering over the row, you will see buttons appear on the right in the Actions column
  3. Click on the button to Edit the space
  4. In the drawer that appears on the right, expand the Sleep Mode section
  5. Use the Delete After Inactivity field to specify the Time (in minutes) to wait before putting the space to sleep if there is no more user activity involving this namespace
  6. On the very bottom, click on the button to save the changes
Enforce Auto-Delete Timeout For All Space Created By User/Team
  1. Go to the Clusters view using the menu on the left
  2. Switch to the Space Constraints tab
  3. Option A: Hover over the space constraints object that you want to configure auto-delete with and click on the button to Edit an existing space constraints object

    Option B: Click the button to create a new space constraints object

  4. In the drawer that appears on the right, expand the Enforce Space Settings section
  5. Use the Delete After Inactivity field to specify the Time (in minutes) to wait before deleting the space if there is no more user activity in this namespace
  6. On the very bottom, click on the or button to save the changes
  7. Switch to the Cluster Access tab
  8. Hover over the cluster access of the user or team that you want to enforce auto-delete for and click on the button to Edit the cluster access
  9. In the drawer that appears on the right, expand the Restrictions section
  10. Use the Enforce Space Constraints field to select the Space Constraint you edited or created in Step 3 above
  11. On the very bottom, click on the button to update the cluster access
Test with Impersonation

After following the steps above, all spaces created using the cluster access in step 7 will now enforce this auto-delete behavior. You can test this behavior by impersonating a user that uses this cluster access.

Inactivity Detection

All requests that are made through Loft count as activity in the namespace.

If your kube-context points to Loft's API server as a proxy before the actual connected cluster's API server, every kubectl request will be an activity and reset the inactivity timeout.