Steps to Reset and Rejoin Kubernetes Cluster Nodes (kubeadm)

1. Start Your EC2 Instances

  • Ensure both your master and worker nodes are running.

  • Verify network connectivity between the nodes (e.g., security group rules for Kubernetes ports like 6443).


2. Reset the Existing Kubernetes Configuration

Step 1: Identify the CRI Socket

Run the following command on both the master and worker nodes to check which container runtime interface (CRI) is in use:

ps -aux | grep containerd
ps -aux | grep crio

Step 2: Reset the Cluster with CRIO

Run the following command to reset Kubernetes on both the master and worker nodes, explicitly specifying the CRIO socket:

sudo kubeadm reset -f --cri-socket unix:///var/run/crio/crio.sock

This command will:

  • Remove the existing cluster configuration.

  • Clean up Kubernetes resources like certificates, configuration files, and more.

Note: If you encounter any issues with cleanup, verify permissions and manually remove residual Kubernetes files under /etc/kubernetes/ or /var/lib/kubelet/ as needed.


3. Reinitialize or Rejoin Nodes

When reinitializing the master node or rejoining the worker nodes, ensure you always specify the --cri-socket parameter to use CRIO.

For Master Node Reinitialization

Run the following command to reinitialize the master node:

sudo kubeadm init --cri-socket unix:///var/run/crio/crio.sock

This command will:

  • Reinitialize the master node.

  • Generate a new join command for the worker nodes.

Copy the output join command (e.g., kubeadm join ...) for use on the worker nodes.

Note: After reinitialization, you will need to reapply your network plugin (e.g., Flannel, Calico) for the cluster to function correctly.

For Worker Node Rejoining

Run the kubeadm join command on the worker node with the appropriate --cri-socket parameter. Replace <MASTER_IP>, <TOKEN>, and <HASH> with the values provided by the master node initialization output:

sudo kubeadm join <MASTER_IP>:6443 --token <TOKEN> \
    --discovery-token-ca-cert-hash sha256:<HASH> \
    --cri-socket unix:///var/run/crio/crio.sock

Example:

sudo kubeadm join 172.31.12.69:6443 --token 37axu2.gwxfhelf40i5c8yd \
    --discovery-token-ca-cert-hash sha256:647a51cad31e31dc300d3b90bcedc7211b54bc79e60106fdf8346bfefa6e5609 \
    --cri-socket unix:///var/run/crio/crio.sock

4. Verify Cluster Status

After rejoining the nodes, verify that they are successfully connected to the cluster:

  1. On the master node, run:

     kubectl get nodes
    

    Ensure all nodes show a Ready status.

  2. Check pod statuses:

     kubectl get pods -A