<p>We use kustomize to create a unique configMap for our Deployments whenever a new change to configMap data is made.   We now are left with a number of old configMaps which are no longer in use by any Pods - I can find them in Rancher, but that's a pain - how can I automate cleaning up those configMaps that are no longer used by any Pods?</p>
<p>I've tried running:  <code>kubectl get configmaps --namespace mynamespace --output=json</code></p>
<p>I was hoping to see a reverse reference to the Pod that's using it - but I can't find the right info in there.</p>

<p>If your configmaps can be identified using a label, you can just use the <a href="https://kubernetes.io/docs/tasks/manage-kubernetes-objects/declarative-config/#alternative-kubectl-apply-f-directory-prune-l-your-label" rel="nofollow noreferrer">--prune</a> flag to get rid of the dangling resources. If you'd add it to your deployment pipelines the orphaned resources should slowly be cleaned from the cluster.</p>
<p>See this <a href="https://github.com/kubernetes-sigs/kustomize/issues/876#issuecomment-472600524" rel="nofollow noreferrer">comment</a> for how people are using this in conjunction with kustomize.</p>
