zoukankan      html  css  js  c++  java
  • kuberenetes 上使用helm部署rancher如何卸载干净

    在已有的kuberenetes上用helm(部署文档)部署过rancher卸载之后在也别想再次部署rancher了。。。会出现无法登陆 资源正在删除中诸如此类问题,导致这个现象的原因是rancher创建的crd资源大部分都有finalizers字段,这会导致crd下的一系列资源一直在Terminating 下次安装rancher的时候不会初始化这部分资源,比如nodes.management.cattle.io这个crd是映射k8s的node节点的,下次安装rancher看到nodes.management.cattle.io正在Terminating 会“帮忙”把node节点从k8s集群中移除

    如果还想在卸载过的环境再次部署rancher如需完整的清理一下rancher生成的所有资源

    #!/bin/bash
    
    # k8s=1.18 rchaner=2.5.5
    
    
    api_server="https://192.168.10.229:6443"
    token=`cat .kube/admin-token`
    
    echo "处理删除中断"
    curl -k $api_server/api/v1/namespaces/local/finalize 
     -H "Authorization: Bearer $token" 
     -H "Content-Type: application/json" 
     -XPUT 
     -d '{"apiVersion":"v1","kind":"Namespace","metadata":{"name":"local"},"spec":{"finalizers":[]}}'
    
    
    
    kubectl patch --type='json' -p='[{"op": "remove", "path": "/metadata/finalizers"}]' ns $(kubectl get ns |egrep 'cattle|fleet|rancher|local|^p-|^user-' |awk '{print $1}')
    project_ns=`kubectl get ns |egrep '^p-|local' |awk '{print $1}'`
    project_crd=(clusterroletemplatebindings.management.cattle.io clusteralertgroups.management.cattle.io projects.management.cattle.io projectalertgroups.management.cattle.io projectalertrules.management.cattle.io projectroletemplatebindings.management.cattle.io nodes.management.cattle.io)
    
    
    for ns in ${project_ns[@]}
    do
      for crd in ${project_crd[@]}
      do
        kubectl patch --type='json' -p='[{"op": "remove", "path": "/metadata/finalizers"}]' $crd -n $ns $(kubectl get $crd -n $ns|grep -v NAME|awk '{print $1}')
      done
    done
    
    
    crd_list=`kubectl get crd |grep cattle.io |awk '{print $1}'`
    
    for crd in $crd_list
    do
    
    kubectl patch --type='json' -p='[{"op": "remove", "path": "/metadata/finalizers"}]' $crd $(kubectl get $crd |grep -v NAME|awk '{print $1}')
    
    done
    
    echo "使用rancher清理工具 https://docs.rancher.cn/docs/rancher2/system-tools/_index/"
    ./system-tools remove -c .kube/config
    
    kubectl get crd
    
    echo "理论上所有rancher的crd都会被删除,如果还有说明有异常,继续会强制删除"
    echo "按任意键继续"
    read anykey
    
    
    echo "helm卸载"
    helm uninstall rancher -n cattle-system
    helm uninstall rancher-operator -n rancher-operator-system
    helm uninstall rancher-operator-crd -n rancher-operator-system
    helm uninstall fleet -n fleet-system
    helm uninstall fleet-crd -n fleet-system
    
    echo "清理剩余资源"
    sleep 5
    
    for ns in $(kubectl get ns |grep -v NAME|awk '{print $1}')
    do
      kubectl delete rolebinding $(kubectl get rolebinding -n $ns --selector='cattle.io/creator=norman' |grep -v NAME|awk '{print $1}') -n $ns
    done
    
    
    ns_list=`kubectl get ns |egrep 'cattle|fleet|rancher|local' |awk '{print $1}'`
    
    kubectl delete ns $ns_list
    
    kubectl patch --type='json' -p='[{"op": "remove", "path": "/metadata/finalizers"}]' crd $(kubectl get crd |grep 'cattle.io' |awk '{print $1}')
    kubectl get crd |grep 'cattle.io' |awk '{print $1}' |xargs kubectl delete crd
    kubectl get clusterrolebinding |egrep 'default-admin|fleet|pod-impersonation-helm-op|rancher' |awk '{print $1}' |xargs kubectl delete clusterrolebinding
    kubectl get clusterrole |egrep 'fleet|pod-impersonation-helm-op' |awk '{print $1}' |xargs kubectl delete clusterrole
    
    kubectl label ns $(kubectl get ns |egrep -v 'NAME' |awk '{print $1}') field.cattle.io/projectId-
  • 相关阅读:
    C++——string转char[]
    Ackerman的非递归算法(未解决)
    单链表——递归求最大整数、节点个数、平均值
    队列——以数组Q[m]存放循环队列元素,设置一个标志tag,以tag=0和tag=1来区别在头指针和尾指针相等时,队列为空或满
    队列——假设以带头结点的循环链表表示队列,并且只设一个指针指向队尾元素结点(注意:不设头指针), * 试编写相应的置空队列、判断队列是否为空、入队和出队等算法。
    栈——判断回文
    栈——表达式求值
    栈——匹配()[]
    栈——十进制转八进制
    动态获取导航栏
  • 原文地址:https://www.cnblogs.com/37yan/p/14275214.html
Copyright © 2011-2022 走看看