Open In App

How To Completely Uninstall Kubernetes?

Last Updated : 26 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Kubernetes is often referred to as K-8 It is an open-source container known as a perspiration platform that is designed to concentrate the deployment with scaling and other types of management tasks of containerized apps.

While Kubernetes itself offers a very large number of features and advantages for the management of complex infrastructure applications, there may sometimes be a need for you to uninstall or switch to a different tool. For this, you will have to uninstall Kubernetes and then complete the required tasks, such as installing some different orchestration tools or Kubernetes if you want, so in this article, we will understand how we can uninstall Kubernetes.

Uninstalling Kubernetes Components

There are various steps involved in the uninstallation of the components of Kubernetes, so let’s go one by one and understand how we can uninstall the Kubernetes components.

Step 1: Uninstall Kubeadm, Kubectl, and Kubelet

The first step is to uninstall all three packages that come with Kubernetes; these are the components that are primarily responsible for Kubernetes. To uninstall this, we run the following command:

sudo apt-get purge kubeadm kubectl kubelet kubernetes-cni kube*


This will give us the following output as a result:

sudo-aptget-purge-kubeadm-kubectl

Uninstall kubeadm, kubectl, kubelet.

Step 2: Remove Configuration & Data:

After uninstalling the components of the kubernetes we need to make sure that we remove the configuration as well as all the data present in the system, for this we will run the following command:

sudo rm -rf ~/.kube
sudo rm -rf /etc/cni
sudo rm -rf /etc/kubernetes
sudo rm -rf /var/lib/etcd
sudo rm -rf /var/lib/kubelet


Note: These commands are used for default directories, if you have installed the kubernetes components somewhere else then change the command accordingly.

Running these commands will result in deletion of all the configuration and data.

sudo-rm-rf

sudo rm rf.

Step 3: Resetting the iptables:

Once the above step is complete and all the configuration file as well as the data is deleted, we will need to reset the iptables.

In order to reset the iptables we will have to run the following command in the terminal:

sudo iptables -F && sudo iptables -t nat -F && sudo iptables -t mangle -F && sudo iptables -X


Once we run the above command we should not see anything or any error as output, if there is no error and the command is executed then we can say that the iptables are reset successfully, as you can see below:

Resetting-the-iptables

Resetting the iptables.

Removing Add-ons and Extensions

If there is any add on or extensions present in the kubernetes then you will have to remove the extension as well as the data for the extensions as well before you move forward. you can easily delete any extensions and add ons by mentioning the package name and purge command.

Note: There was no extension present hence deleting an add-on is not possible.

Cluster Configurations and Manifests

Now we will also need to delete any cluster configuration as well as manifests present, this is an easy step as well, we will simply have to use the following command in order to delete the cluster configurations and manifests:

kubectl-config-unset

kubectl config unset.

Use the above command and along with it provide an individual value in the kubeconfig file for unsetting it.

Custom Resource Definitions (CRDs)

Custom resources are another part of the kubernetes that we will have to get rid of, for deleting the custom resource definitions we will have to use the following command:

kubectl delete all --all-namespaces --all


You can replace the –all with the names of custom resources that you want to delete, in this case we want to delete all the custom resource as we are uninstalling the kubernetes we have given the –all command that will delete all the custom resource definitions.

Output:

custom-resources

Deleting custom resources.

Post-Uninstallation Verification

This is the final step, in this step we will test whether the kubernetes have been uninstalled or not, for this we will run the following command:

uninstall-verification

uninstall verification.

If you also see an error similar to this then the kubernetes is uninstalled in your system as well.

How to completely uninstall kubernetes – FAQ’s

Is it really safe to delete all of the Kubernetes resources?

Deleting the kubernetes is safe but it is only advisable to delete these resources when you’re no longer in need of the kubernetes and uninstalling it completely.

Why kubectl is used in Kubernetes?

The kubectl as the name suggests is a command line tool which is used for the purpose of managing the kubernetes clusters using the command line.

Will I have to remove configuration files manually, after uninstalling Kubernetes?

Yes, it is very highly advised that you remove the configuration files manually after the uninstallation of the kubernetes to make sure there are no left over files.

Is it really important to reset iptables after uninstalling the Kubernetes?

Yes, it is really important for you to reset the iptables after the uninstallation of the kubernetes, this makes sure that the system’s network configuration settings are back to their default settings.



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads