kubernetes 에서 namespace를 삭제를 하게 되면 정상적으로 진행이 되지 않는 경우
아래와 같이 Terminating 상태로 표시가 된다
1 2 3 4 5 6 7 8 |
[root@k8smaster ~]# kubectl get ns NAME STATUS AGE default Active 4d3h kube-node-lease Active 4d3h kube-public Active 4d3h kube-system Active 4d3h kubernetes-dashboard Terminating 59m orange Active 4d1h |
그럼 정상적으로 삭제를 하기 위해서 상태를 확인한다
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
[root@k8smaster ~]# kubectl get namespaces kubernetes-dashboard -o yaml apiVersion: v1 kind: Namespace metadata: annotations: kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"v1","kind":"Namespace","metadata":{"annotations":{},"name":"kubernetes-dashboard"}} creationTimestamp: "2023-08-21T05:39:50Z" deletionTimestamp: "2023-08-21T06:08:21Z" labels: kubernetes.io/metadata.name: kubernetes-dashboard name: kubernetes-dashboard resourceVersion: "542859" uid: 6ceb5ca5-2ac2-4c3e-b762-3ea87c3799ef spec: finalizers: - kubernetes status: conditions: - lastTransitionTime: "2023-08-21T06:08:26Z" message: 'Discovery failed for some groups, 1 failing: unable to retrieve the complete list of server APIs: metrics.k8s.io/v1beta1: stale GroupVersion discovery: metrics.k8s.io/v1beta1' reason: DiscoveryFailed status: "True" type: NamespaceDeletionDiscoveryFailure - lastTransitionTime: "2023-08-21T06:08:26Z" message: All legacy kube types successfully parsed reason: ParsedGroupVersions status: "False" type: NamespaceDeletionGroupVersionParsingFailure - lastTransitionTime: "2023-08-21T06:08:28Z" message: All content successfully deleted, may be waiting on finalization reason: ContentDeleted status: "False" type: NamespaceDeletionContentFailure - lastTransitionTime: "2023-08-21T06:08:28Z" message: All content successfully removed reason: ContentRemoved status: "False" type: NamespaceContentRemaining - lastTransitionTime: "2023-08-21T06:08:26Z" message: All content-preserving finalizers finished reason: ContentHasNoFinalizers status: "False" type: NamespaceFinalizersRemaining phase: Terminating |
json 파일로 추출
1 |
[root@k8smaster ~]# kubectl get namespaces kubernetes-dashboard -o json > kubernetes-dashboard.json |
kubernetes 내용을 삭제
1 |
[root@k8smaster ~]# sed -i '/"kubernetes"/d' kubernetes-dashboard.json |
kubectl proxy 백그라운드 실행
1 |
[root@k8smaster ~]# kubectl proxy & |
curl 호출하여 정상진행
1 |
[root@k8smaster ~]# curl -k -H "Content-Type: application/json" -X PUT --data-binary @kubernetes-dashboard.json http://127.0.0.1:8001/api/v1/namespaces/kubernetes-dashboard/finalize |
1 |
여기에서 수정할 항목은 @ 부분에 namespace 이름
finalize 부분 앞 부분에 namespace 이름
namespace 상태 확인
1 2 3 4 5 6 7 |
[root@k8smaster ~]#kubectl get ns NAME STATUS AGE default Active 4d3h kube-node-lease Active 4d3h kube-public Active 4d3h kube-system Active 4d3h orange Active 4d1h |
정상적으로 삭제된것을 확인 할 수 있다