2

I am trying to delete the entire kubernetes that created for my CI/CD pipeline R&D. So for deleting the cluster and everything I run the following command,

kubectl config delete-cluster <cluster-name> 

kubectl config delete-context <Cluster-context>  

For making sure that the clustee is deleted, I build the jenkins pipeline job again. So I found that it is deploying with updated changes.

When I run the command "kubectl config view", I found the following result,

docker@mildevdcr01:~$ kubectl config view
apiVersion: v1
clusters: []
contexts: []
current-context: kubernetes-admin@cluster.local
kind: Config
preferences: {}
users: []
docker@mildevdcr01:~$

Still my Spring Boot micro service is deploying in cluster with updated changes.

I created the Kubernetes cluster using kubespray tool that I got reference from Github:

https://github.com/kubernetes-incubator/kubespray.git

What do I need to do for the deletion of everything that I created for this Kubernetes cluster? I need to remove everything including master node.

halfer
  • 19,824
  • 17
  • 99
  • 186
Mr.DevEng
  • 2,651
  • 14
  • 57
  • 115
  • little more details on where the cluster is created, please. – Tummala Dhanvi Aug 27 '19 at 11:25
  • @TummalaDhanvi - I did not understood when you are saying where. I created these cluster on VMs onpremise. Is that you need to know ? Let me know sir. And thank you for your response sir. – Mr.DevEng Aug 27 '19 at 11:32
  • The command `kubectl config delete-cluster ` only remove the config that was used to connect to the cluster,The cluster will keep running. (Just like you clear the browser cookie in google.com, but your account still exists in google). You can remove the cluster by remove vms or follow the instructions here to remove k8s cluster https://stackoverflow.com/questions/44698283/how-to-completely-uninstall-kubernetes – hoozecn Aug 28 '19 at 05:27
  • you can try like `kubectl delete all -l app=` – subhashis Jul 23 '22 at 16:09

2 Answers2

6

If you setup your cluster using Kubespray, you ran whole installation using ansible, so to delete cluster you have to use it too.

But you can also reset the entire cluster for fresh installation:

$  ansible-playbook -i inventory/mycluster/hosts.ini reset.yml

Remember to keep the “hosts.ini” updated properly.

You can remove node by node from your cluster simply adding specific node do section [kube-node] in inventory/mycluster/hosts.ini file (your hosts file) and run command:

 $ ansible-playbook -i inventory/mycluster/hosts.ini remove-node.yml

KubeSpray documentation: kubespray.

Useful articles: kubespray-steps, kubespray-ansible.

Malgorzata
  • 6,409
  • 1
  • 10
  • 27
0

Okay so for a kubespray CI/CD pipeline it's a little more complicated then just deleting the cluster context. You have to actively delete other items on each node and perform a reset.yml for ETCD.

Sometimes just running the reset.yml is enough for your pipeline so it resets the cluster back to the initial state but if this is not enough then you have to delete docker, kubelet, repositories, /etc/kubernetes and many other directories on the nodes to get a clean deployment. In this case it's almost always easier to just provision new nodes in your pipeline using terraform and vsphere(vra) API.

Raja
  • 305
  • 2
  • 15