Part 9: Project Cleanup, Kubernetes Starter
Written August 23rd, 2024 by Nathan Frank

Photo source by BoliviaInteligente on Unsplash
Recap
This article picks up from the eighth article: Full Project Setup in the Kubernetes Starter series.
Full setup hands on
Let's cleanup the project now that we are done. As we use a combination of kubernetes and helm we don't want to just delete the namespaces and call it done.
Removing namespaces directly while using Helm will lead to dangling resources that can't be deleted and likely a cluster that can't have these namespaces reused.
Follow these instructions to prevent having to find and cleanup finalizing resources.
Uninstall the environments first
If you've run the helm environments deploy-with-helm.sh installs:
Run
uninstall-with-helm.shCheck the status with
status-with-helm.sh, multiple times if needed until resources have been deleted.
Uninstall the main instance and shared elements
Run the
uninstall.shhelper scriptCheck the status by running the
status.shhelper scriptSee numerous entries like
No resources found in sample-vault namespace
Delete the PVC (Persistent Volume Claim)
In our case deleting this is fine, but in production this could delete the storage with other secrets in it.
Run
kubectl delete pvc data-sample-vault-0 -n sample-vaultVerify the PV is removed with
status.shhelper script
Delete the last remaining namespace
Run
kubectl delete ns sample-vaultThis step is manual as the PVC removal was manual as well.
If you've deleted a namespace that contained resources managed by helm
This can sometimes lead to issues where Helm can not be uninstalled, but there's dangling resources that need to be removed.
Run this to find the non finalized resources:
1kubectl api-resources --verbs=list --namespaced -o name | xargs -n 1 kubectl get --show-kind --ignore-not-found -n samplewhere
sampleis the namespace in question.Delete each one with the following:
1kubectl patch -n sample vaultstaticsecret.secrets.hashicorp.com vault-kv-app -p '{"metadata":{"finalizers":null}}' --type=mergewhere
vaultstaticsecret.secrets.hashicorp.comis a type of object andvault-kv-appis the name of the object that isn't getting deleted.
Wrap up
We've got an understanding on how to clean up the cluster we've been using along the way.
Moving along
Thanks for sticking with us through this exploration of modern software development and deployment. If you found any of this series helpful consider giving a clap, responding with comments, bookmarking or following me as an author.
Return to the Kubernetes starter overview.
