Completely remove Kubernetes on debian machine

6/17/2020

I want to remove Kubernetes from a Debian machine (I didn't do the setup)

I followed the instructions from https://stackoverflow.com/questions/44698283/how-to-completely-uninstall-kubernetes

kubeadm reset
sudo apt-get purge kubeadm kubectl kubelet kubernetes-cni kube*   
sudo apt-get autoremove  
sudo rm -rf ~/.kube

But it seems to be still installed:

# which kubeadm
/usr/local/bin/kubeadm

# which kubectl
/usr/local/bin/kubectl

# which kubelet
/usr/local/bin/kubelet

Also, apt list --installed | grep kube* does not return anything, so it make me think it was not installed via apt

Do you know how to clean this machine ? Should I just rm /usr/local/bin/kubectl etc ? I don't really like this idea..

Thanks for help

-- iAmoric
kubernetes
linux

1 Answer

6/18/2020

The method suggested by Rib47 on the answer you indicated is correct to completely remove and clean Kubernetes installed with apt-get.

As mentioned by underscore_d, /usr/local/bin/ isn't the directory where the packages installed by apt-get are placed.

For example, when you install kubectl using apt-get, it's placed on /usr/bin/kubectl and that's what is going to be removed by apt-get purge.

I tested it on my kubeadm cluster lab and I don't have these files at /usr/local/bin/.

You have to revisit all the steps you followed during the install process to know how exactly these files got there.

If you run kubeadm reset, I would say it's safe to remove these files. I suggest you to check if they are being used before removing using the command fuser. This command might not be installed in your linux and you can install it by running sudo apt-get install psmisc. After installing you can run it as in this example:

 $ sudo fuser /usr/bin/kubelet 
/usr/bin/kubelet:    21167e

It means this file is being used by process number 21167.

Checking this process we can see what's using it:

$ ps -aux | grep 21167
root     21167  4.1  0.5 788164 88696 ?        Ssl  08:50   0:07 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --config=/var/lib/kubelet/config.yaml --cgroup-driver=cgroupfs --network-plugin=cni --pod-infra-container-image=k8s.gcr.io/pause:3.2

If the files related to kubernetes you have under /usr/local/bin/ are not in use, I would remove them with no worries.

-- Mark Watney
Source: StackOverflow