본문 바로가기
카테고리 없음

쿠버네티스 네임스페이스 삭제 후 Terminating으로 있을 경우 처리 방법

by Knowledge Store In Hyunsoft 2020. 9. 2.

쿠버네티스 네임스페이스 삭제 후 Terminating으로  있을 경우 처리 방법

kubectl proxy &
kubectl get ns <namespace> -o json > delete-ns.json
sed -i 's/"kubernetes"//g' delete-ns.json
curl -k -H "Content-Type: application/json" -X PUT --data-binary @delete-ns.json http://127.0.0.1:8001/api/v1/namespaces/<namespace>/finalize

 

 

#!/bin/bash

if [ $# -ne 1 ]; then
  echo "script need 1 parameter"
  echo "ex) ./force-delete-ns.sh kubeflow"
  exit 1
fi
kubectl proxy &
kubectl get ns
kubectl get ns $1 -o json > delete-ns.json
sed -i 's/"kubernetes"//g' delete-ns.json
curl -k -H "Content-Type: application/json" -X PUT --data-binary @delete-ns.json http://127.0.0.1:8001/api/v1/namespaces/$1/finalize
kubectl get ns

 

 

#2 kubectl edit ns  명령에서 finalizers 라인을 삭제하고 저장하면 namespace 삭제됨

 

kubectl get ns
NAME                                         STATUS        AGE
argocd                                        Terminating   2d19h
cicd                                             Terminating   8d
kubekey-system                         Terminating   15d
kubesphere-monitoring-system Terminating   15d

 

 

kubectl edit ns kubesphere-monitoring-system

 

apiVersion: v1
kind: Namespace
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","kind":"Namespace","metadata":{"annotations":{},"name":"kubesphere-monitoring-system"}}
  creationTimestamp: "2022-06-04T01:19:33Z"
  deletionGracePeriodSeconds: 0
  deletionTimestamp: "2022-06-16T08:15:03Z"
  finalizers:
  - finalizers.kubesphere.io/namespaces
  labels:
    kubernetes.io/metadata.name: kubesphere-monitoring-system
    kubesphere.io/namespace: kubesphere-monitoring-system
    kubesphere.io/workspace: system-workspace
  name: kubesphere-monitoring-system
  ownerReferences:
  - apiVersion: tenant.kubesphere.io/v1alpha1
    blockOwnerDeletion: true
    controller: true
    kind: Workspace
    name: system-workspace
    uid: e5aa9d54-dea7-4274-8fa5-b79fc18c337c
  resourceVersion: "562786"
  uid: f18b6f56-cf44-4212-85e1-560b859f5d39
spec: {}
status:
  conditions:
  - lastTransitionTime: "2022-06-16T08:15:12Z"
    message: All resources successfully discovered
    reason: ResourcesDiscovered
    status: "False"
    type: NamespaceDeletionDiscoveryFailure
  - lastTransitionTime: "2022-06-16T08:15:12Z"
    message: All legacy kube types successfully parsed
    reason: ParsedGroupVersions
    status: "False"
    type: NamespaceDeletionGroupVersionParsingFailure
  - lastTransitionTime: "2022-06-16T08:15:12Z"
    message: All content successfully deleted, may be waiting on finalization
    reason: ContentDeleted
    status: "False"
    type: NamespaceDeletionContentFailure
  - lastTransitionTime: "2022-06-16T08:16:31Z"
    message: All content successfully removed
    reason: ContentRemoved
    status: "False"
    type: NamespaceContentRemaining
  - lastTransitionTime: "2022-06-16T08:15:24Z"
    message: All content-preserving finalizers finished
    reason: ContentHasNoFinalizers
    status: "False"
    type: NamespaceFinalizersRemaining
  phase: Terminating
~

728x90

댓글