Script to detect "orphaned" TLS secrets when Cert manager (cainjector) complains about "unable to fetch certificate that owns the secret", because deleting a Certificate will not (default) delete the… This article provides a Bash script that detects and cleans up "orphaned" TLS secrets in Kubernetes—secrets that remain after their corresponding cert-manager Certificate resources have been deleted. The script addresses the cert-manager error "unable to fetch certificate that owns the secret" by identifying secrets without a matching certificate and optionally deleting them, with support for dry-run mode, namespace filtering, and verbose output. cleanup-cert-manager-secrets.sh This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters /bin/bash inspired by https://gist.github.com/lisawolderiksen/8c6026ef55f04e4f5d6a288b5e53214b Apache 2.0 License usage { cat << EOF This script detects TLS secrets which refer to certificates that don't exist anymore . This is the case when error "unable to fetch certificate that owns the secret" occurs in cert-manager cainjector logs. The reason is that a certificate has been removed without the secret being deleted. The solution is to clean up by deleting any secret which belonged to a certificate that no longer exists. Usage: $0 -n namespace -v $0 -n | --namespace