What’s the best way to manage unused ConfigMaps and Secrets in Kubernetes?

0
13
Asked By TechyTurtle98 On

I'm currently in the process of tidying up our Kubernetes clusters and I've noticed a lot of ConfigMaps and Secrets that seem to be obsolete. However, I'm hesitant to just delete them. You know how it goes—teams change their configurations, Helm releases can become outdated, but the old ConfigMaps and Secrets remain because `kubectl apply` doesn't automatically prune them. Since Kubernetes' garbage collection only kicks in when `ownerReferences` are properly set, these resources tend to accumulate over time. I'm curious about the best strategies for managing this situation.

Is manual cleanup feasible, or is that too overwhelming? Would custom scripts be a better option, like searching through all manifests for references? Or should we just leave them be since storage isn't too costly? I'm particularly worried about edge cases, such as Secrets used for Ingress TLS or `imagePullSecrets`, which can be tricky to keep track of compared to standard volume mounts. Anyone have a reliable process that avoids the risky 'scream testing' method (deleting and hoping for no complaints)?

4 Answers

Answered By ClusterMaster80 On

I’ve taken a more radical approach—create a new cluster without granting anyone the ability to manually create resources. Manage everything via GitOps instead. By keeping ephemeral resources in the same namespace as what they belong to, their cleanup becomes automatic when that resource is undeployed. This limits human error and enforces correct practices. My trick? I rebuild the clusters quarterly, making it easy to ensure everything's in order and preventing unwanted resources from lingering.

Answered By DevOpsDynamo42 On

We're implementing a GitOps approach using Argo CD, which helps a lot with this issue. It continuously reconciles every resource tied to an app, including ConfigMaps and Secrets, with what's outlined in our Git repositories. This means I can easily see what's in use and what’s currently deployed; plus, I get alerts if anything gets out of sync. It really removes the guesswork and lets us manage our resources with confidence.

CuriousCoder17 -

That sounds really efficient! I love the idea of having everything tracked like that.

CloudNinja22 -

Agreed! It’s nice to have that level of control.

Answered By CleanupGuru76 On

Check out this GitHub repo: https://github.com/yonahd/kor. It offers some interesting tools for managing your clusters and might help with cleaning up those orphaned resources.

CodeExplorer99 -

Thanks for sharing! It looks promising. Have you personally used it to streamline your processes?

DataDrivenDave -

Nice find! Definitely worth a look.

Answered By K8sEnthusiast24 On

With GitOps, any orphaned resources should ideally not exist. It emphasizes having a clean state for your resources.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.