• 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

How to Cordon Kubernetes Nodes with kubectl cordon

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

The kubectl cordon command in Kubernetes is used to mark a node as unschedulable. This prevents new pods from being scheduled onto the node, although existing pods continue to run on it. This can be useful during maintenance or when you want to prevent new deployments on a node temporarily.

Example 1: Cordon a specific node named “node-1”:

kubectl cordon node-1
    

This command will mark the node “node-1” as unschedulable. To verify, you can check the node’s status using:

kubectl get nodes node-1 -o jsonpath='{.spec.taints}'
    

If the node is cordoned, the output will include a taint indicating it’s unschedulable.

Example 2: Cordon all nodes labeled with a specific label, such as “environment=production”:

kubectl cordon $(kubectl get nodes -l environment=production -o jsonpath='{.items[*].metadata.name}')
    

This command uses a label selector to cordon all nodes matching the label “environment=production”.

Example 3: Cordon nodes based on a node condition, for instance, nodes with disk pressure:

kubectl get nodes --field-selector='status.conditions[?type==DiskPressure].status==True' -o jsonpath='{.items[*].metadata.name}' | xargs kubectl cordon
    

This command finds nodes with disk pressure conditions and cordon them. Verification can be done by checking the taints on those nodes.

Example 4: Cordon a node with an eviction grace period (e.g., 30 seconds):

kubectl cordon --grace-period=30 node-1
    

This command marks “node-1” as unschedulable with a specific eviction grace period.

Example 5: Cordon all nodes except those labeled with “critical=false”:

kubectl get nodes -l 'critical!=false' -o jsonpath='{.items[*].metadata.name}' | xargs -I {} kubectl cordon {}
    

This command cordon all nodes except those labeled with “critical=false”.

Example 6: Cordon nodes in a specific availability zone, for instance, “us-west-1a”:

kubectl get nodes -o jsonpath='{.items[?(@.metadata.labels.failure-domain\.beta\.kubernetes\.io/zone=="us-west-1a")].metadata.name}' | xargs -I {} kubectl cordon {}
    

This command targets nodes in the specified availability zone for cordoning.

Example 7: Cordon nodes based on specific resource utilization thresholds:

kubectl top nodes | awk '$2 > 80 {print $1}' | xargs -I {} kubectl cordon {}
    

This command uses the Kubernetes metrics server to identify nodes with CPU or memory utilization over 80% and cordon them accordingly.

Example 8: Cordon nodes during node draining to prevent new pods from being scheduled:

kubectl drain --ignore-daemonsets node-1 && kubectl cordon node-1
    

This sequence drains “node-1” and then marks it as unschedulable to ensure no new pods are scheduled during the drain operation.

Example 9: Cordon nodes with specific hardware configurations, such as GPU nodes:

kubectl get nodes -l 'accelerator=nvidia-tesla-v100' -o jsonpath='{.items[*].metadata.name}' | xargs -I {} kubectl cordon {}
    

This command targets nodes equipped with NVIDIA Tesla V100 GPUs for cordoning.

Example 10: Cordon nodes based on network conditions or issues:

kubectl get nodes --field-selector='status.conditions[?type==NetworkUnavailable].status==True' -o jsonpath='{.items[*].metadata.name}' | xargs -I {} kubectl cordon {}
    

This command identifies nodes with network issues and marks them as unschedulable.

Also check similar articles.

Monitor Resource Usage with kubectl top
Access Cluster Information Using kubectl cluster-info
Managing Kubernetes Certificates with kubectl certificate
Implement Auto-Scaling in Kubernetes with kubectl autoscale
Scaling Kubernetes Deployments with kubectl scale

Tags: KubernetesKubernetes Commands ExamplesKubernetes Commands TutorialKubernetes Tutorial
Previous Post

Monitor Resource Usage with kubectl top

Next Post

Scheduling Nodes in Kubernetes with kubectl uncordon

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

Scheduling Nodes in Kubernetes with kubectl uncordon

howto

Prepare Nodes for Maintenance with kubectl drain

howto

Update Node Taints with kubectl taint

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.