Disconnect your cluster
Remove Cast AI resources from your cluster
Depending on how you used and managed Cast in a cluster, you can remove it in two distinct ways.
Terraform-managed clusters
Run the terraform destroy command to remove the resources. Terraform will destroy all remote objects managed by a particular configuration.
Clusters managed in the console
Read-only clusters
To disconnect your cluster from Cast AI:
Step 1
Click the Disconnect cluster button on the list of clusters and follow the on-screen instructions.
Alternatively, run the following command in your terminal to access the cluster:
kubectl delete namespace castai-agentStep 2
Additionally, delete the following Kubernetes objects related to the Cast AI agent:
kubectl delete clusterrole.rbac.authorization.k8s.io/castai-agent
kubectl delete clusterrolebinding.rbac.authorization.k8s.io/castai-agentOnce the cluster is disconnected, its status will update to Disconnected.
Step 3
Remove the cluster from the console by pressing the Remove cluster button.

NoteThe cluster will continue to run as normal, as deleting the cluster in Cast AI only removes it from the console.
Managed service clusters
Step 1
In the console, choose the Disconnect cluster option.

Step 2
Enter the cluster name in the form and check the box to delete all nodes Cast AI created. Due to reduced cluster capacity, this might cause downtime.

When the cluster disconnects from Cast AI, its status label changes from Disconnecting to Disconnected.

Step 3
Press the Remove cluster button to get a script that cleans up cloud resources like Roles, Bindings, and ServiceAccounts. Run the provided script in your cloud shell or terminal.

NoteThe cleanup script removes cloud-level resources but does not remove in-cluster Kubernetes objects. See Step 4 — Remove in-cluster resources below.
How to remove Cast AI credentials and other resources
Follow these steps to ensure that you remove Cast AI from your cluster altogether:
Step 1
In the Cast AI console, go to the Autoscaler page and switch the toggle to OFF to disable all policies.

Step 2
Go back to the cluster list and disconnect the cluster by clicking the Disconnect cluster button and following the instructions on the screen.

Once disconnecting has finished and the cluster status has changed to Disconnected, move on to the next step.
Step 3
Click the Remove cluster button and execute the provided offboarding script in your cloud shell or terminal to remove Cast AI-created resources from your cloud account.

Step 4 — Remove in-cluster resources
The cleanup script from Step 3 removes cloud-level resources (IAM roles, service accounts) but does not remove Kubernetes objects that Cast AI installed in your cluster. Run the following commands to remove them.
Delete Cast AI namespaces and all resources inside them:
kubectl delete ns castai-agent castai-omni liqo-storage --ignore-not-foundWait for the namespaces to fully terminate before proceeding. Controllers running inside these namespaces will recreate cluster-scoped resources if you delete them too early.
kubectl wait --for=delete ns/castai-agent ns/castai-omni ns/liqo-storage --timeout=300s 2>/dev/null; echo "Done"
WarningIf a namespace becomes stuck in the
Terminatingstate, see Removing finalizers from a namespace stuck in the terminating state below.
Delete webhook configurations:
kubectl delete mutatingwebhookconfigurations castai-mutate-endpointslice castai-pod-mutator castai-pod-pinner castai-workload-autoscaler liqo-webhook --ignore-not-found
kubectl delete validatingwebhookconfigurations castai-validate-migration vpodmutation.cast.ai liqo-webhook --ignore-not-foundDelete ClusterRoleBindings and ClusterRoles:
kubectl get clusterrolebindings -o name | grep -iE "castai|liqo" | xargs kubectl delete --ignore-not-found
kubectl get clusterroles -o name | grep -iE "castai|liqo" | xargs kubectl delete --ignore-not-foundDelete CRDs. Remove their finalizers first, otherwise the deletion can hang indefinitely:
kubectl get crds -o name | grep -E '\.cast\.ai|\.liqo\.io' | xargs -I{} kubectl patch {} -p '{"metadata":{"finalizers":[]}}' --type=merge
kubectl get crds -o name | grep -E '\.cast\.ai|\.liqo\.io' | xargs kubectl delete --ignore-not-foundTroubleshooting
Removing finalizers from a namespace stuck in the terminating state
terminating stateWhen disconnecting your cluster or re-onboarding to Cast AI, you may encounter a situation where a namespace becomes stuck in the Terminating state. If this occurs, follow these steps to forcefully delete the namespace:
-
Verify the namespace status:
kubectl get ns <namespace-name> -
Remove the finalizers:
a. Start the proxy in one terminal:kubectl proxyb. In another terminal, execute:
kubectl get namespace castai-agent -o json | jq '.spec.finalizers = []' > tmp.json && curl -k -H "Content-Type: application/json" -X PUT --data-binary @tmp.json http://127.0.0.1:8001/api/v1/namespaces/castai-agent/finalize -
Confirm namespace deletion:
kubectl get ns <namespace-name>
NoticeThis process forcefully removes finalizers, allowing namespace deletion. Be aware that this method may leave orphaned resources.
By following these steps, you can successfully disconnect your cluster from Cast AI and remove all associated resources.
Updated about 7 hours ago
