Showing posts with label KEDA. Show all posts
Showing posts with label KEDA. Show all posts

7/18/2025

Troubleshooting Kubernetes 01 : Delete Orphan Objects (CRDs)

 


When it comes to application maintenance, version upgrade is a kind of thing we have to attend to once a year or two.

But it would make your life easy if the applications are deployed in Kubernetes.

I thought to share recent activity we engaged with to upgrade KEDA in AKS (Azure Kubernetes Service).


Story Begins Here…


First of all we had to uninstall the existing version of KEDA.

First of all we had to uninstall the existing version of KEDA.

You can follow below blog posts to uninstall and install the KEDA.

https://keda.sh/docs/2.12/deploy/#uninstall

https://keda.sh/docs/2.12/deploy/#install

Now after uninstalling the KEDA, we should be able to delete the namespace keda , but unfortunately we can’t delete it.



When you execute “kubectl delete ns keda”, command, it was stucked in the “Terminating” status.


But when you check resources in that namespace you can't find any. So what can be the culprit?



Now the main reason we are using KEDA in our current project is to use ScaledJobs to process application data in an event driven way.

Now the main reason for this kind of situation is, still dependent orphan objects (CRDs) still living there.


Lets dig into the hole…


We can see all the KEDA specific api-resources from below command


  1. Now we can get the “triggerauthentications” api-resources type objects and delete them as below.


2. Then we can get the KEDA specific CRDs and delete them as below.



But when you try to delete other CRDs , it will fail and those will still hanging aroung here.


3. What we can do to get rid of those is to differentiate finalizers using the kubectl patch command.



Now we can delete the remaining KEDA specific CRDs.


4. Now we need to check KEDA specific apiservices and delete them.


5. Finally you can see all the dependent orphan objects are deleted. As a last step we can delete the keda namespace now.








5/25/2025

Upgrading KEDA: Clean Uninstall and Reinstall Guide



When working with Kubernetes-based event-driven autoscaling using KEDA (Kubernetes Event-driven Autoscaling), it’s sometimes necessary to uninstall the current version and perform a clean reinstall—especially when troubleshooting or upgrading to a newer release.

In this post, we’ll walk you through a complete KEDA uninstall and reinstall process, including how to properly remove all ScaledObjects and ScaledJobs.


🧼 Step 1: Uninstall KEDA

The first step is to remove KEDA from your cluster using Helm:

helm uninstall keda -n keda

For reference, see the official uninstall documentation: KEDA Uninstall Guide


🧹 Step 2: Clean Up ScaledObjects and ScaledJobs

Before KEDA can be fully uninstalled, it's important to delete any existing ScaledObjects and ScaledJobs. These resources may prevent a clean uninstall if not removed.

🔍 List Existing Resources

kubectl get scaledobjects.keda.sh,scaledjobs.keda.sh -A

NAMESPACE   NAME                         MIN   MAX   TRIGGERS         AUTHENTICATION       READY   ACTIVE   AGE
default     ***********                  20    20    azure-servicebus service-bus-auth     -       -        722d
default     ***********                  20    20    azure-servicebus service-bus-auth     -       -        2y266d
default     ***********                  20    20    azure-servicebus service-bus-auth     -       -        2y266d
default     ***********                  20    20    azure-servicebus service-bus-auth     -       -        715d
default     ***********                  20    20    azure-servicebus service-bus-auth     -       -        2y266d
default     ***********                  20    20    azure-servicebus service-bus-auth     -       -        729d
default     ***********                  20    20    azure-servicebus service-bus-auth     -       -        729d
default     ***********                  20    20    azure-servicebus service-bus-auth     -       -        2y266d
default     ***********                  20    20    azure-servicebus service-bus-auth     -       -        729d
default     ***********                  20    20    azure-servicebus service-bus-auth     -       -        2y266d
default     ***********                  20    20    azure-servicebus service-bus-auth     -       -        721d
default     ***********                  20    20    azure-servicebus service-bus-auth     -       -        651d
default     ***********                  20    20    azure-servicebus service-bus-auth     -       -        721d

🛠 Remove Finalizers (Optional but Recommended)

If finalizers are present on ScaledJobs, they can block deletion. Use the following script to remove them:

for i in $(kubectl get scaledjobs -A -o jsonpath='{.items[*].metadata.name}{"\n"}'); do
  kubectl patch scaledjob.keda.sh/$i -p '{"metadata":{"finalizers":null}}' --type=merge
done

❌ Delete the ScaledJobs

Once finalizers are cleared, delete all the ScaledJobs:

for i in $(kubectl get scaledjobs -A -o jsonpath='{.items[*].metadata.name}{"\n"}'); do
  kubectl delete scaledjob $i
done

🔍 Step 3: Verify Resource Cleanup

Check whether all KEDA-related resources are removed:

kubectl get all -n keda

Picture



🧯 Step 4: Manual Deletion (If Helm Uninstall Fails)

If helm uninstall doesn’t completely remove KEDA components, you can manually delete them with the following commands:

kubectl delete deployment.apps/keda-operator -n keda
kubectl delete deployment.apps/keda-metrics-apiserver -n keda
kubectl delete service/keda-metrics-apiserver -n keda

🚀 Step 5: Install the Latest Version of KEDA

Once cleanup is complete, install the latest version of KEDA.

Option 1: Apply Directly from GitHub

kubectl apply --server-side -f https://github.com/kedacore/keda/releases/download/v2.12.0/keda-2.12.0-core.yaml

Option 2: Apply a Local File

kubectl apply --server-side -f keda-2.12.0-core.yaml

namespace/keda serverside-applied
customresourcedefinition.apiextensions.k8s.io/clustertriggerauthentications.keda.sh serverside-applied
customresourcedefinition.apiextensions.k8s.io/scaledjobs.keda.sh serverside-applied
customresourcedefinition.apiextensions.k8s.io/scaledobjects.keda.sh serverside-applied
customresourcedefinition.apiextensions.k8s.io/triggerauthentications.keda.sh serverside-applied
serviceaccount/keda-operator serverside-applied
role.rbac.authorization.k8s.io/keda-operator serverside-applied
clusterrole.rbac.authorization.k8s.io/keda-external-metrics-reader serverside-applied
clusterrole.rbac.authorization.k8s.io/keda-operator serverside-applied
rolebinding.rbac.authorization.k8s.io/keda-operator serverside-applied
rolebinding.rbac.authorization.k8s.io/keda-hpa-controller-external-metrics serverside-applied
clusterrolebinding.rbac.authorization.k8s.io/keda-operator serverside-applied
clusterrolebinding.rbac.authorization.k8s.io/keda-system-auth-delegator serverside-applied
service/keda-operator serverside-applied
service/keda-metrics-apiserver serverside-applied
deployment.apps/keda-metrics-apiserver serverside-applied
deployment.apps/keda-operator serverside-applied
apiservice.apiregistration.k8s.io/v1beta1.external.metrics.k8s.io serverside-applied


For full details, see: KEDA Install Guide


✅ Wrapping Up

This guide helps you perform a clean uninstall and reinstall of KEDA, avoiding issues like lingering resources or stuck finalizers. A clean install ensures your Kubernetes environment remains stable and scalable.

If you found this helpful, bookmark it for future upgrades or troubleshooting!

Happy scaling! 🚀