preface
Starting with V2.5, Rancher supports Rancher HA installation on any CNCF certified standard K8s distribution. This cluster can use either upstream Kubernetes or one of Rancher’s Kubernetes distributions. It can also be a managed Kubernetes cluster from a provider such as Amazon EKS. Rancher recommends using a separate K8S/K3S cluster as a Local cluster for Rancher HA, regardless of which cluster it is installed on, so that Rancher HA does not interact with the business cluster.
If the Rancher HA is uninstalled on an independent Local cluster, it is usually deleted from the Local cluster to achieve the purpose of uninstalling Rancher HA. In this way, it is relatively simple and data cleaning is more thorough.
However, some users have Rancher HA installed on certain business or production clusters, so they cannot uninstall Rancher HA by removing the Local cluster. We need to find a way to uninstall the Rancher HA without affecting the Local cluster.
Rancher provides a tool for uninstalling Rancher HA: system-tools. We can use system-tools to remove namespaces and other resources generated by Rancher HA. Executing the remove command removes the following resources:
- The namespace deployed by Rancher, with the default name cattle-system.
- ServiceAccount, clusterRoles and clusterRoleBindings tagged by Rancher via cattle. IO/Creator: Norman tag.
- All and resources created using Rancher V2.1.0 or later are labeled cattle. IO/Creator: Norman.
- Labels, Annotations, and finalizers.
- The Rancher Deployment.
- Cluster, project, and user-specific CRDS.
- Management. Cattle. IO ALL resources created within the API Group.
All CRDS created using Rancher v2.x. However, system-Tools has fallen into disrepair (it was last updated on April 11, 2019), and some namespace and other resources added for subsequent Rancher releases have not been removed, As a result, there is no way to completely uninstall Rancher HA on the Local cluster.
Uninstall the Rancher HA
To completely uninstall Rancher HA on a Local cluster, we can first filter out which namesaces are created by Rancher HA. System-tools remove –kubeconfig <$kubeconfig > –namespace to remove the namespace and related resources. After system-tools is used to remove a namespace, the namespace will always be in Terminating state. You also need to remove the namespace manually. Then you can delete the namespace completely.
To this end, I prepared a shell script to complete the above deletion process:
Note:
- This script is only tested on Rancher V2.5.8 and is theoretically supported by all v2.5.x series versions. For other versions (for example, 2.4.x), you need to modify NS parameters in Step 4 to set the namespace to be deleted
- This script has been verified on the Local k3S and RKE clusters. For example, if the Local cluster is another K8s cluster, confirm NS parameters in Step 4 to set the namespace to be deleted
- Rancher HA will create namespaces starting with C -, p-, and user-, which do not need users’ attention. When removing the cattle-system through system-tools, these namespaces will be automatically removed
1. Download the script
root@ip-172-31-22-79:~# wget https://raw.githubusercontent.com/kingsd041/some_script/master/remove-rancher-ha/remove_r_ha.sh
Copy the code
2. Install Kubectl, JQ, and system-tools on the host, and create kubeconFig files.
3. Edit the script and set the KUBE_CONFIG directory
KUBE_CONFIG='/root/.kube/config'
Copy the code
4. Edit the script to check whether the namespace where the NS variable is set is the namespace to be deleted.
NS="cattle-system|*fleet*|rancher-operator-system|cattle-global-nt|cattle-global-data"
Copy the code
5. Run the script to uninstall Rancher HA
root@ip-172-31-22-79:~# ./remove_r_ha.sh cattle-system cattle-global-data cattle-global-nt rancher-operator-system fleet-clusters-system fleet-local cluster-fleet-local-local-1a3d67d0a899 fleet-system fleet-default cluster-fleet-default-c-9zwzq-dd029f17f988 Are you sure to remove the above namespace? [y/n] y INFO[0000] Removing Rancher management plane in namespace: [cattle-system] INFO[0000] Getting connection configuration INFO[0000] Removing Cattle deployment INFO[0000] Removed Cattle deployment succuessfully INFO[0000] Removing ClusterRoleBindings ... .Copy the code
The script is executed in about 5 minutes. Kubectl get ns to check whether Rancher HA is uninstalled:
root@ip-172-31-22-79:~# kubectl get ns
NAME STATUS AGE
kube-public Active 65m
default Active 65m
kube-node-lease Active 65m
kube-system Active 65m
Copy the code
Afterword.
Although Rancher HA can be installed on any CNCF-certified K8s cluster starting with Rancher V2.5, it is recommended that you install Rancher HA on a separate Local cluster in your production environment. This prevents the Rancher HA from interacting with the business cluster. If you have Rancher HA installed on a business K8s cluster, you can use this method to uninstall Rancher HA flawlessly without affecting the original cluster.
thanks
Thank IT old boys blog: mandatory delete the Terminating condition the namespace (the original link: www.xtplayer.cn/kubernetes/…