rogulski.it

My name is Piotr, a passionate pythonista and this is my blog!

How to delete kubernetes stuck CRD deletion

Posted at — Jul 4, 2022

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:

  1. Download a yaml file with a broken resource:
kubectl get brokers.eventing.knative.dev -o yaml > my-resource.yaml
  1. 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
  1. 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: []
  1. Apply your changes and unblock your work
kubectl apply -f my-resource.yaml