If you don’t take steps to maintain your Kubernetes cluster, you could end up wasting money and storage on orphaned resources. Orphaned (or unused) resources, like ConfigMaps, Secrets, and Services, should be regularly located and removed to clear up storage space and prevent performance issues.
In this post, we’ll be focusing on how to find and remove orphaned ConfigMaps.
ConfigMaps are API objects created to hold small amounts of visible configuration data. These objects support unbinding of configuration data from container images and application code for optimum portability of applications, but they cannot hold secret/encrypted data.
ConfigMaps may get orphaned if they are left isolated from the deployment they were created to support, or if their owners have been purged. Once orphaned, these ConfigMaps waste temporary storage and increase the risk of cluster instability.
Finding and Deleting Orphaned ConfigMaps
Here are some steps you can take to find and remove orphaned ConfigMaps:
Step 1: Find all ConfigMaps
First off, you can generate a list of all ConfigMaps using this command:
This command will return the list of ConfigMaps across all namespaces, but as you’ll see, the ConfigMap object does not reference its owner. You’ll need to run another command to identify which of the ConfigMaps have owners and are in use.
Step 2: Compare with a List of Used ConfigMaps
To find any orphaned ConfigMaps, you have to get the list of pods across your cluster and list all ConfigMaps in use. Alternatively you can use the following to diff the list of ConfigMaps and used ConfigMaps, and get unused ConfigMaps:
Finally, you can compare the two lists and delete ConfigMaps from the first list that are not in use by any pod.
Step 3: Delete Orphaned ConfigMaps
Now that you have a list of orphaned ConfigMaps, you can run this command to delete them and free up memory in your cluster:
Once you’ve deleted all the orphaned ConfigMaps you found, you’ll have removed unneeded, unused resources from your cluster and freed up memory and storage space. If you remove orphaned resources regularly, you’ll ensure that your team is maintaining optimal Kubernetes resource management.
Simplify Locating Orphaned ConfigMaps with Blink
Finding and removing orphaned ConfigMaps takes a few steps and you might not remember to make it a part of your routine.
With a free Blink account, you can schedule automated checks just like this one so you can maintain your Kubernetes clusters in just a couple clicks.
Get started and create your free Blink account today.