How to drain node from local node using docker command
This document (000020373) is provided subject to the disclaimer at the end of this document.
Environment
Rancher v2.4.x , v2.5.x
Situation
Resolution
docker exec kubelet bash -c 'kubectl --kubeconfig <(kubectl --kubeconfig /etc/kubernetes/ssl/kubecfg-kube-node.yaml get configmap -n kube-system full-cluster-state -o json | jq -r .data.\"full-cluster-state\" | jq -r .currentState.certificatesBundle.\"kube-admin\".config | sed -e "/^[[:space:]]*server:/ s_:.*_: \"https://127.0.0.1:6443\"_") drain $(hostname -s) --delete-local-data=true --force=true --grace-period=60 --ignore-daemonsets=true --timeout=120s'Please note that the below flags need to be changed according to your requirements.
--delete-local-data=true --force=true --grace-period=60 --ignore-daemonsets=true --timeout=120s
Cause
cannot delete daemonsets.apps "nginx-ingress-controller" is forbidden: User "system:node" cannot get resource "daemonsets" in API group "apps" in the namespace "ingress-nginx"But this kubeconfig file can access the config map "full-cluster-state" in namespace "kube-system" contains the kubeconfig file, which has the privilege to do the drain operation.
Disclaimer
This Support Knowledgebase provides a valuable tool for SUSE customers and parties interested in our products and solutions to acquire information, ideas and learn from one another. Materials are provided for informational, personal or non-commercial use within your organization and are presented "AS IS" WITHOUT WARRANTY OF ANY KIND.
- Document ID:000020373
- Creation Date: 01-Sep-2021
- Modified Date:05-Aug-2022
-
- SUSE Rancher
For questions or concerns with the SUSE Knowledgebase please contact: tidfeedback[at]suse.com