• About Us
  • Privacy & Policy
HowTo's
  • Home
  • Commands
  • Linux
  • SCM
  • Git
  • Database
  • MySQL
  • Kubernetes
  • Docker
No Result
View All Result
  • Home
  • Commands
  • Linux
  • SCM
  • Git
  • Database
  • MySQL
  • Kubernetes
  • Docker
No Result
View All Result
HowTo's
No Result
View All Result
Home Kubernetes

Prepare Nodes for Maintenance with kubectl drain

June 26, 2024
in Kubernetes, Kubernetes Commands Examples, Kubernetes Commands Tutorial, Kubernetes Tutorial
A A
0
12
SHARES
111
VIEWS
Share on FacebookShare on Twitter

The kubectl drain command in Kubernetes is used to gracefully evacuate a node from the cluster, preparing it for maintenance or other purposes. When a node is drained, Kubernetes attempts to gracefully evict all the pods running on the node onto other nodes in the cluster, ensuring minimal disruption to applications.

Here are several examples illustrating the usage of kubectl drain:

Example 1: Drain a specific node named node-1:
kubectl drain node-1
This command will trigger the eviction of all pods from node-1 and mark it unschedulable.

Example 2: Drain a node with additional flags for force draining and ignoring local pods:
kubectl drain node-2 --force --ignore-daemonsets
Adding --force ensures immediate eviction of pods that are not terminating, while --ignore-daemonsets ignores pods managed by DaemonSets.

Example 3: Drain a node with a specified timeout (in seconds):
kubectl drain node-3 --timeout=3600s
This specifies a timeout of 3600 seconds (1 hour) for the eviction of pods from node-3.

Example 4: Drain a node and skip waiting for graceful termination of pods:
kubectl drain node-4 --force --delete-local-data
Using --delete-local-data ensures deletion of local data on the node and forces immediate eviction of pods.

Example 5: Drain a node, allowing pods to be rescheduled on other nodes:
kubectl drain node-5 --ignore-daemonsets --delete-emptydir-data
This command ignores DaemonSet-managed pods and deletes emptyDir volumes from pods being evicted.

Example 6: Drain a node and prevent new pods from being scheduled on it:
kubectl drain node-6 --ignore-daemonsets --disable-eviction
Adding --disable-eviction prevents the node from being evicted, useful when the node cannot be safely drained.

Example 7: Drain a node with graceful period adjustment for pod termination:
kubectl drain node-7 --grace-period=120
Adjusting the --grace-period to 120 seconds allows pods more time to gracefully terminate.

Example 8: Drain a node and reschedule evicted pods onto other nodes:
kubectl drain node-8 --ignore-daemonsets --pod-selector=app=nginx
Using --pod-selector ensures only pods matching the specified label selector (app=nginx) are evicted and rescheduled.

Example 9: Drain a node and handle errors more strictly:
kubectl drain node-9 --ignore-daemonsets --force --delete-local-data --grace-period=30 --skip-wait-for-delete-timeout
This command combines multiple flags to handle different scenarios, ensuring pods are evicted forcefully and local data is deleted.

Example 10: Drain a node interactively, allowing confirmation before eviction:
kubectl drain node-10 --ignore-daemonsets --interactive
Using --interactive prompts for user confirmation before initiating the drain operation on node-10.

To verify whether the kubectl drain command executed successfully, you can check the status of the node using:
kubectl get nodes
Ensure that the node you drained is marked as Ready=False and has no pods scheduled on it anymore.

Also check similar articles.

Scheduling Nodes in Kubernetes with kubectl uncordon
How to Cordon Kubernetes Nodes with kubectl cordon
Monitor Resource Usage with kubectl top
Access Cluster Information Using kubectl cluster-info
Managing Kubernetes Certificates with kubectl certificate

Tags: KubernetesKubernetes Commands ExamplesKubernetes Commands TutorialKubernetes Tutorial
Previous Post

Scheduling Nodes in Kubernetes with kubectl uncordon

Next Post

Update Node Taints with kubectl taint

Related You may like!

howto

Interacting with Kubernetes Plugins using kubectl plugin

June 26, 2024
howto

Configuring kubectl and kubeconfig Files

June 26, 2024

Exploring Kubernetes API Versions with kubectl api-versions

June 26, 2024

Understanding Kubernetes API Resources with kubectl api-resources

June 26, 2024

Generating Shell Completion Code with kubectl completion

June 26, 2024

Managing Kubernetes Annotations with kubectl annotate

June 26, 2024
Next Post
howto

Update Node Taints with kubectl taint

howto

Detailed Resource Inspection with kubectl describe

howto

Retrieve Container Logs Using kubectl logs

Discussion about this post

Latest Updated

howto

How to Use -iname for Case-Insensitive Filename Searches in find

August 21, 2024
howto

Search for Files with Case-Insensitive Pattern Matching Using -ilname in find

August 21, 2024
howto

Find Files by Group Name with -group in find Command

August 21, 2024
howto

Locate Files by Group ID Using -gid in find Command

August 21, 2024
howto

How to Search for Filesystems with -fstype in find Command

August 21, 2024

Trending in Week

  • howto

    Using BTRFS Subvolume for User Home Directory in Linux

    22 shares
    Share 9 Tweet 6
  • Downloading Docker Images from a Registry

    13 shares
    Share 5 Tweet 3
  • Configuring SSL Connection Mode in mysqldump

    17 shares
    Share 7 Tweet 4
  • Omit Tablespace Information in mysqldump Output

    13 shares
    Share 5 Tweet 3
  • Setting MySQL Dump Compatibility Mode

    18 shares
    Share 7 Tweet 5
  • Setting Network Buffer Length in mysqldump

    13 shares
    Share 5 Tweet 3
  • Logging out from Docker Registries

    13 shares
    Share 5 Tweet 3
  • Scheduling Nodes in Kubernetes with kubectl uncordon

    12 shares
    Share 5 Tweet 3
  • Managing Default User Creation Settings in Linux

    15 shares
    Share 6 Tweet 4
  • Using Extended INSERT Syntax in mysqldump

    12 shares
    Share 5 Tweet 3
  • About Us
  • Privacy & Policy

© 2024 All Rights Reserved. Howto.swebtools.com.

No Result
View All Result

© 2024 All Rights Reserved. Howto.swebtools.com.