Created
March 21, 2019 20:35
-
-
Save devnulled/29ba05ecfc5bd67327c6b148ac3dd4cd to your computer and use it in GitHub Desktop.
Deleting Stuck or Hung Kubernetes CRD's and CR's
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
# | |
# How to patch and delete CustomResourceDefinitions and CustomResources in Kubernetes | |
# | |
# | |
# Just copied and pasted from this solution in a kubernetes bug report: | |
# | |
# https://github.com/kubernetes/kubernetes/issues/60538 | |
# | |
# remove the CRD finalizer blocking on custom resource cleanup | |
kubectl patch crd/crontabs.stable.example.com -p '{"metadata":{"finalizers":[]}}' --type=merge | |
# now the CRD can be deleted (orphaning custom resources in etcd) | |
kubectl delete -f crd.yaml | |
customresourcedefinition.apiextensions.k8s.io "crontabs.stable.example.com" deleted | |
Error from server (NotFound): error when deleting "crd.yaml": the server could not find the requested resource (delete crontabs.stable.example.com my-new-cron-object) | |
# when the CRD is recreated, it resurfaces the existing custom resources | |
kubectl create -f crd.yaml | |
customresourcedefinition.apiextensions.k8s.io "crontabs.stable.example.com" created | |
Error from server (AlreadyExists): error when creating "crd.yaml": object is being deleted: crontabs.stable.example.com "my-new-cron-object" already exists | |
# the custom resources can now be edited to remove finalizers | |
kubectl patch crontab/my-new-cron-object -p '{"metadata":{"finalizers":[]}}' --type=merge | |
crontab.stable.example.com "my-new-cron-object" patched | |
# and now both custom resource and CRD can be deleted | |
kubectl delete -f crd.yaml | |
customresourcedefinition.apiextensions.k8s.io "crontabs.stable.example.com" deleted | |
Error from server (NotFound): error when deleting "crd.yaml": crontabs.stable.example.com "my-new-cron-object" not found |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment