SUSE Support

Here When You Need Us

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

RKE1
Rancher v2.4.x , v2.5.x

Situation

Need a way to cordon or drain node when OS patching is automated, and the automation doesn't have access to Rancher API.
 

Resolution

Integrate the below command in the automation to drain the node in the OS patching workflow.
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

Draining operation using kubeconfig file "/etc/kubernetes/ssl/kubecfg-kube-node.yaml" will result in errors like below since the "system:node" role is not authorized to access needed API groups.
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

< Back to Support Search

For questions or concerns with the SUSE Knowledgebase please contact: tidfeedback[at]suse.com

tick icon

SUSE Support Forums

Get your questions answered by experienced Sys Ops or interact with other SUSE community experts.

tick icon

Support Resources

Learn how to get the most from the technical support you receive with your SUSE Subscription, Premium Support, Academic Program, or Partner Program.

tick icon

Open an Incident

Open an incident with SUSE Technical Support, manage your subscriptions, download patches, or manage user access.