Fix Kubernetes Resources Stuck Deleting with Finalizers
Diagnose a Kubernetes custom resource stuck during deletion and inspect its finalizers, using a Knative Broker example and kubectl commands.
Sometimes when you delete your CustomResourceDefinition (CRD) without deleting some dependencies first or your config will depend on another proces which takes place your delete action might freeze.
I had a problem setting up a knative configuration, and I had to delete a full config and create it again.
I found that my brokers.eventing.knative.dev CRD hold and nothing could be done:
$ kubectl delete -f knative-broker.yaml
broker.eventing.knative.dev "default" deleted
...
Now to fix it:
- Download a yaml file with a broken resource:
kubectl get brokers.eventing.knative.dev -o yaml > my-resource.yaml
- Find a finalizers list in your resource
apiVersion: v1
items:
- apiVersion: eventing.knative.dev/v1
kind: Broker
metadata:
annotations:
eventing.knative.dev/broker.class: Kafka
creationTimestamp: "2022-07-04T09:45:23Z"
deletionGracePeriodSeconds: 0
deletionTimestamp: "2022-07-04T12:43:01Z"
finalizers:
- brokers.eventing.knative.dev
- Make a finalizers list empty
apiVersion: v1
items:
- apiVersion: eventing.knative.dev/v1
kind: Broker
metadata:
annotations:
eventing.knative.dev/broker.class: Kafka
creationTimestamp: "2022-07-04T09:45:23Z"
deletionGracePeriodSeconds: 0
deletionTimestamp: "2022-07-04T12:43:01Z"
finalizers: []
- Apply your changes and unblock your work
kubectl apply -f my-resource.yaml