Deleting/Resetting a K8S cluster

In short
  • When a kubeadm installation fails, start from a clean base without redeploying the servers.
  • Procedure on all nodes: kubeadm reset, deletion of the etcd database.
  • Cleaning up the interfaces of the network add-on.
  • Optional package removal.

Introduction

During your initial Kubernetes experiments, it is not uncommon to fail your deployment.

With the use of kubeadm, it can sometimes happen that the installation fails in the middle of a step, leaving servers partially configured.

In these cases, it is best to ensure that all traces of settings are removed so that you can try again from a clean configuration

Ideally, you should not have to redeploy your servers, but simply erase what might have been achieved during the installation attempt with kubeadm.

Here is the procedure to follow to restart a deployment from scratch and remove all traces of a previous cluster or an incomplete installation.

Procedure

All commands must be executed as root. Be careful; this procedure is associated with the use of kubeadm. If you have used other deployment solutions, the procedure may differ.

On all nodes

Reset the cluster using the following command:

kubeadm reset
kubeadm reset command

Click the image to enlarge.

Delete your configuration in your standard user profile:

rm -rf /home/mon_user/.kube/

Delete your global Kubernetes configurations:

rm -rf /etc/kubernetes/

Delete your network settings:

rm -rf /etc/cni/net.d

On all control plane (master) nodes

Remove your ETCD database:

rm -rf /var/lib/etcd

Network add-on (optional)

Depending on your network add-on, it may be necessary to remove the associated interfaces on all your nodes.

ip link set cni0 down
ifconfig cni0 down
brctl delbr cni0
rm -rf /opt/cni/bin

Package removal (optional)

You can go as far as removing packages associated with Kubernetes. In this case, it depends on your distribution. For example, on Debian-based systems,

apt-get remove --purge kubelet kubeadm kubectl