Why does Okteto delete my Kubernetes resources when I click “Destroy All”? How can I prevent that?

I ran into this today. I hit the “Destroy” button in Okteto expecting a clean reset of my environment, and it wiped out all resources, even when ones that were not displayed in the UI (e.g. a volume snapshot)

How do I prevent that?

If you’re using Okteto and hit the “Destroy All” button (or run the okteto destroy --all), you might be surprised to see important Kubernetes resources disappear along with everything else.

Here’s how to prevent that :backhand_index_pointing_down:

:stop_sign: The problem

Destroy All (okteto destroy --all) is designed to clean up everything in your namespace:

  • Deployments
  • Services
  • Helm releases
  • Pipeline resources

That’s great for cleanup… but not if you have shared or persistent resources (like secrets, databases, or config maps) you want to keep.

:white_check_mark: The solution

Annotate any resource you want to preserve with:

metadata:
  annotations:
    dev.okteto.com/policy: keep

:locked: Example

apiVersion: v1
kind: Secret
metadata:
  name: my-important-secret
  annotations:
    dev.okteto.com/policy: keep

With this annotation in place, Okteto will skip deleting this resource during Destroy All.

:light_bulb: When to use this

This is especially useful for:

  • Shared databases
  • API keys / secrets
  • Persistent configs
  • Anything managed outside your dev lifecycle

:warning: Tip

Be intentional about what you mark as keep. If overused, your environment can drift from a clean state.


Simple trick, but it can save you from painful data loss :+1: