Skip to content

Remove Operator

Simply Deleting/Removing an imported cluster in the Web Console (i.e. Controller) does not automatically remove all artifacts associated with the Kubernetes Mgmt Operator on imported clusters. We provide a tool that can be used to force remove/delete all remaining resources provisioned on imported clusters.

Important

This utility will not delete user deployed resources because these are managed by the customer. This utility uses kubectl, helm cli to remove the operator on the cluster.


Usage

Run the utility provided below with the imported cluster's "bootstrap yaml" that was generated by the controller during the import process.

./import-cluster-cleanup.sh my-cluster-bootstrap.yaml

Force Remove Script

#!/bin/bash
if [ $# -lt 1 ]; then
    echo "please specify the cluster bootstrap file location as an argument"
    echo  "Usage: ./import-cluster-cleanup.sh my-cluster-bootstrap.yaml" && exit -1
fi
kubectl delete ValidatingWebhookConfiguration rafay-drift-validate
kubectl delete ValidatingWebhookConfiguration rafay-drift-validate-v3
kubectl scale deployment rafay-connector -n rafay-system --replicas=0
kubectl scale deployment rafay-connector-v3 -n rafay-system --replicas=0
kubectl delete rt v1-debug-infra -n rafay-system --timeout=10s
kubectl delete rt v1-logging-infra -n rafay-infra --timeout=10s
kubectl delete rt v2-prometheus -n rafay-infra --timeout=10s
kubectl delete rt v2-alertmanager -n rafay-infra --timeout=10s
kubectl delete rt v1-edge-client -n rafay-system --timeout=10s
kubectl delete rt v2-ingress -n rafay-system --timeout=10s
kubectl delete rt v2-relay-agent -n rafay-system --timeout=10s
kubectl delete rt rafay-restricted-psp -n rafay-system --timeout=10s
kubectl delete rt rafay-privileged-psp -n rafay-system --timeout=10s
kubectl delete rt v2-infra -n rafay-system --timeout=10s
kubectl delete rtl v2-infra -n rafay-system --timeout=10s
helm delete rafay-prometheus -n rafay-infra
helm delete v2-ingress-infra -n rafay-system
helm delete v2-infra -n rafay-system
kubectl proxy &
for TASK in v1-logging-infra v2-alertmanager v2-prometheus
do
kubectl get rt $TASK -n rafay-infra -o json |jq '.metadata.finalizers = []' > temp.json
curl -ks -H "Content-Type: application/json" -X PUT --data-binary @temp.json 127.0.0.1:8001/apis/cluster.rafay.dev/v2/namespaces/rafay-infra/tasks/$TASK/ > /dev/null 2>&1
done
for TASK in v2-ingress v2-infra v2-relay-agent
do
kubectl get rt $TASK -n rafay-system -o json |jq '.metadata.finalizers = []' > temp.json
curl -ks -H "Content-Type: application/json" -X PUT --data-binary @temp.json 127.0.0.1:8001/apis/cluster.rafay.dev/v2/namespaces/rafay-system/tasks/$TASK/ > /dev/null 2>&1
done
for TASKLET in v1-logging-infra v2-alertmanager v2-prometheus
do
kubectl get rtl $TASKLET -n rafay-infra -o json |jq '.metadata.finalizers = []' > temp.json
curl -ks -H "Content-Type: application/json" -X PUT --data-binary @temp.json 127.0.0.1:8001/apis/cluster.rafay.dev/v2/namespaces/rafay-infra/tasklets/$TASKLET/ > /dev/null 2>&1
done
for TASKLET in v2-ingress v2-infra v2-relay-agent
do
kubectl get rtl $TASKLET -n rafay-system -o json |jq '.metadata.finalizers = []' > temp.json
curl -ks -H "Content-Type: application/json" -X PUT --data-binary @temp.json 127.0.0.1:8001/apis/cluster.rafay.dev/v2/namespaces/rafay-system/tasklets/$TASKLET/ > /dev/null 2>&1
done
echo "Waiting for 30 seconds"
sleep 30
kubectl delete rns rafay-infra --timeout=10s
kubectl delete rns rafay-system --timeout=10s
for NAMESPACE in rafay-system rafay-infra
do
kubectl get rns $NAMESPACE -o json |jq '.metadata.finalizers = []' > temp.json
curl -ks -H "Content-Type: application/json" -X PUT --data-binary @temp.json 127.0.0.1:8001/apis/cluster.rafay.dev/v2/namespaces/default/namespaces/$NAMESPACE/ > /dev/null 2>&1
done
kubectl delete namespace rafay-infra --timeout=10s
kubectl delete namespace rafay-system --timeout=10s
for NAMESPACE in rafay-system rafay-infra
do
kubectl get namespace $NAMESPACE -o json |jq '.spec = {"finalizers":[]}' > temp.json
curl -ks -H "Content-Type: application/json" -X PUT --data-binary @temp.json 127.0.0.1:8001/api/v1/namespaces/$NAMESPACE/finalize > /dev/null 2>&1
done
echo "Waiting for 30 seconds"
sleep 30
kubectl delete -f $1
killall -9 kubectl