首先要安装jq:
wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -ivh epel-release-latest-7.noarch.rpm
yum install jq
设置要删除命名空间的名称:
NAMESPACE=test
接着执行如下操作:
RANCHER_SERVER_URL=$( kubectl config view -o json|jq -r .clusters[0].cluster.server )
CLUSTER_TOKEN=$( kubectl config view -o json|jq -r .users[0].user.token )
kubectl get ns ${NAMESPACE} -ojson| \
jq 'del(.spec.finalizers[])'| \
jq 'del(.metadata.finalizers)' > ${NAMESPACE}.json
curl -k \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${CLUSTER_TOKEN}" \
-X PUT \
--data-binary @${NAMESPACE}.json \
${RANCHER_SERVER_URL}/api/v1/namespaces/${NAMESPACE}/finalize