Split View: Raspberry PI 4 k3s 쿠버네티스 delete namespace 가 되지 않을 때.
Raspberry PI 4 k3s 쿠버네티스 delete namespace 가 되지 않을 때.
Overview
Raspberry PI 4 k3s 쿠버네티스에서 delete namespace가 되지 않을 때 해결 방법을 알아본다.
Kubernetes Namespace에는 Finalizer가 있고 이는 resource가 hard delete 되지 않도록 막아둔 기능이다.
예를 들어 실행중인 Namespac인 monitoring을 kubectl delete ns monitoring와 같이 hard하게 지우려 했을 때 발생하며, 지우려고 시도했던 Namespace는 Terminating 상태로 멈춰있게된다.
$ sudo kubectl get namespace
NAME STATUS AGE
default Active 2d22h
kube-system Active 2d22h
kube-public Active 2d22h
kube-node-lease Active 2d22h
kubernetes-dashboard Active 2d21h
monitoring Terminating 6m51s
How?
NameSpace Edit
아래 명령어로 monitoring namespace에 대한 정보를 tmp.json으로 추출한다.
$ sudo kubectl get ns monitoring -o json > tmp.json
그리고 tmp.json을 열어 spec 하위의 finalizers의 빈 배열 값으로 아래와 같이 수정한다.
"spec": {
"finalizers": []
}
apply
터미널을 새로 열어서 kubectl proxy 서버를 띄운다.
$ sudo kubectl proxy
아래 curl 명령어로 수정한 tmp.json를 해당 namespace에 적용한다.
$ curl -k -H "Content-Type: application/json" -X PUT --data-binary @tmp.json http://127.0.0.1:8001/api/v1/namespaces/monitoring/finalize
Result
아래 명령어로 namespace를 확인해보면, monitoring namespace가 정상적으로 삭제된 것을 확인할 수 있다.
$ sudo kubectl get ns
NAME STATUS AGE
default Active 2d22h
kube-system Active 2d22h
kube-public Active 2d22h
kube-node-lease Active 2d22h
kubernetes-dashboard Active 2d21hgit
Reference
When Raspberry PI 4 k3s Kubernetes delete namespace gets stuck
Overview
Learn how to resolve the issue when delete namespace gets stuck in Raspberry PI 4 k3s Kubernetes.
Kubernetes Namespaces have Finalizers, which is a feature that prevents resources from being hard deleted.
For example, this occurs when you try to hard delete a running Namespace such as monitoring with kubectl delete ns monitoring, and the Namespace you attempted to delete will remain stuck in a Terminating state.
$ sudo kubectl get namespace
NAME STATUS AGE
default Active 2d22h
kube-system Active 2d22h
kube-public Active 2d22h
kube-node-lease Active 2d22h
kubernetes-dashboard Active 2d21h
monitoring Terminating 6m51s
How?
NameSpace Edit
Extract the information about the monitoring namespace to tmp.json using the command below.
$ sudo kubectl get ns monitoring -o json > tmp.json
Then open tmp.json and modify the finalizers under spec to an empty array as shown below.
"spec": {
"finalizers": []
}
apply
Open a new terminal and start a kubectl proxy server.
$ sudo kubectl proxy
Apply the modified tmp.json to the namespace using the curl command below.
$ curl -k -H "Content-Type: application/json" -X PUT --data-binary @tmp.json http://127.0.0.1:8001/api/v1/namespaces/monitoring/finalize
Result
If you check the namespaces with the command below, you can confirm that the monitoring namespace has been successfully deleted.
$ sudo kubectl get ns
NAME STATUS AGE
default Active 2d22h
kube-system Active 2d22h
kube-public Active 2d22h
kube-node-lease Active 2d22h
kubernetes-dashboard Active 2d21hgit
Reference
Quiz
Q1: What is the main topic covered in "When Raspberry PI 4 k3s Kubernetes delete namespace gets
stuck"?
Learn how to resolve the issue when delete namespace gets stuck in Raspberry PI 4 k3s Kubernetes.
Q2: What is NameSpace Edit?
Extract the information about the monitoring namespace to tmp.json using the command below. Then
open tmp.json and modify the finalizers under spec to an empty array as shown below.
Q3: Explain the core concept of apply.
Open a new terminal and start a kubectl proxy server. Apply the modified tmp.json to the namespace
using the curl command below. Result If you check the namespaces with the command below, you can
confirm that the monitoring namespace has been successfully deleted.