본문 바로가기

리눅스

CentOS 7에서 Kubernetes를 제거하는 방법

728x90

CentOS 7에서 Kubernetes를 제거하는 방법

  • Docker Container, Images, Volumes 제거
    • Kubernetes로 생성한 Docker 컨테이너, 이미지, 볼륨들을 제거합니다.
    • 주의: 이 단계를 수행하면 모든 Docker 컨테이너, 이미지, 볼륨이 삭제되므로, 다른 서비스에 영향을 줄 수 있습니다
docker rm -f -v $(docker ps -q)
더보기
sudo docker stop $(sudo docker ps -aq)
sudo docker rm $(sudo docker ps -aq)
sudo docker rmi $(sudo docker images -q)
sudo docker volume rm $(sudo docker volume ls -q)
  • Kubernetes와 Docker 서비스 중지 및 제거
    • Kubernetes와 Docker 서비스를 중지하고, 부팅 시 자동으로 시작되는 서비스 설정을 제거합니다.
sudo systemctl stop kubelet
sudo systemctl disable kubelet
sudo systemctl stop docker
sudo systemctl disable docker
  • 모든 클러스터 데이터 제거
    • 이전에 생성한 클러스터 데이터를 제거합니다.
rm -rf /etc/kubernetes /var/lib/kubelet /var/lib/etcd
  • Kubernetes 초기화
    • Kubernetes 클러스터를 제거하는 명령어입니다. 클러스터를 제거할 때 사용합니다.
kubeadm reset
$ kubeadm reset
[reset] Reading configuration from the cluster...
[reset] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
[reset] WARNING: Changes made to this host by 'kubeadm init' or 'kubeadm join' will be reverted.
[reset] Are you sure you want to proceed? [y/N]: y
...
The reset process does not clean your kubeconfig files and you must remove them manually.
Please, check the contents of the $HOME/.kube/config file.
728x90

 

  • kubelet, kubeadm, kubernetes-cni, kubectl 패키지 제거
yum remove -y kubeadm kubectl kubernetes-cni kubelet kube*
$ yum remove -y kubeadm kubectl kubernetes-cni kubelet kube*
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package kubeadm.x86_64 0:1.22.3-0 will be erased
---> Package kubectl.x86_64 0:1.22.3-0 will be erased
---> Package kubelet.x86_64 0:1.22.3-0 will be erased
---> Package kubernetes-cni.x86_64 0:0.8.7-0 will be erased
--> Finished Dependency Resolution
...
Removed:
  kubeadm.x86_64 0:1.22.3-0 kubectl.x86_64 0:1.22.3-0 kubelet.x86_64 0:1.22.3-0 kubernetes-cni.x86_64 0:0.8.7-0

Complete!
  • 사용되지 않는 패키지 자동 삭제
    • 더 이상 필요하지 않은 패키지들을 자동으로 제거합니다.
yum autoremove -y
$ yum autoremove -y
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package conntrack-tools.x86_64 0:1.4.4-7.el7 will be erased
---> Package cri-tools.x86_64 0:1.19.0-0 will be erased
---> Package libdnet.x86_64 0:1.12-13.1.el7 will be erased
---> Package libicu.x86_64 0:50.2-4.el7_7 will be erased
---> Package socat.x86_64 0:1.7.3.2-2.el7 will be erased
--> Finished Dependency Resolution
--> Finding unneeded leftover dependencies
---> Marking libnetfilter_cthelper to be removed - no longer needed by conntrack-tools
---> Marking libnetfilter_cttimeout to be removed - no longer needed by conntrack-tools
---> Marking libnetfilter_queue to be removed - no longer needed by conntrack-tools
Found and removing 3 unneeded dependencies
--> Running transaction check
---> Package libnetfilter_cthelper.x86_64 0:1.0.0-11.el7 will be erased
---> Package libnetfilter_cttimeout.x86_64 0:1.0.0-7.el7 will be erased
---> Package libnetfilter_queue.x86_64 0:1.0.2-2.el7_2 will be erased
--> Finished Dependency Resolution
...
Removed:
  conntrack-tools.x86_64 0:1.4.4-7.el7 cri-tools.x86_64 0:1.19.0-0 libdnet.x86_64 0:1.12-13.1.el7 libicu.x86_64 0:50.2-4.el7_7 socat.x86_64 0:1.7.3.2-2.el7

Dependency Removed:
  libnetfilter_cthelper.x86_64 0:1.0.0-11.el7 libnetfilter_cttimeout.x86_64 0:1.0.0-7.el7 libnetfilter_queue.x86_64 0:1.0.2-2.el7_2

Complete!
  • 환경 변수 설정 제거
sudo sed -i '/KUBELET_KUBEADM_EXTRA_ARGS/d' /etc/sysconfig/kubelet
sudo sed -i '/KUBELET_EXTRA_ARGS/d' /etc/sysconfig/kubelet
  • 사용자의 홈 디렉토리에서 .kube 디렉토리 삭제
rm -rf ~/.kube

 

728x90