Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
October 24, 2021 08:31 am GMT

How to evict specific pods on the Kubernetes cluster

Introduction

Kubernetes is a very popular and the most widely used container orchestration. It has a sophisticated and flexible scheduling system to deploy your application on production. The administrators would use a kubectl CLI to manage the cluster and deployed pods. The kubectl CLI provides enough features to manage the cluster, but the developer can customize CLI with a kubectl plugin. This article will present what pod eviction is and introduce a kubectl plugin to do that, kubectl-evict.

Pod Eviction

Kubernetes provides pod eviction, which stops pods and removes them from the node. The pod eviction is usually used when the node is shutting down, or the cluster performs a rolling restart of nodes to minimize the downtime of the service. The kubectl CLI has a sub-command kubectl drain to evict pods from the specified node and, the command makes the node as unschedulable:

$ kubectl drain your-node

kubectl-evict: evicts specific pods

The kubectl CLI does not provide a feature to evict specific pods. I sometimes need this feature to safely remove pods from the node or test a PodDisruptionBudget. The kubectl-evict is a kubectl plugin that allows evicting certain pods from the node.

GitHub logo ueokande / kubectl-evict

A kubectl plugin to evict pods

Although there are already plugins to evict pods such as dwradcliffe/kubectl-evict and kubectl-evict-pod, the above plugin has a high compatibility interface with kubectl logs or kubectl exec and provides the following features:

  • Allows evicting pods by a label selector
  • Evicts pods created by Deployment or DaemonSet
  • Supports --dry-run and --grace-period flags

You can get the plugin by the following:

$ go install github.com/ueokande/kubectl-evict@latest

Usage

To evict a specific pod:

$ kubectl evict nginx-abcd-1234

It also allows evicting pods by label selector. The following shows to evict pods which has a label app=nginx:

$ kubectl evict -l app=nginx

Evict pods created by Deployment:

$ kubectl evict deployment/nginx

You can of course evict pods from the node:

$ kubectl evict node/worker-1

Note that kubectl evict does NOT make the node as unschedulable (cordon), so use kubectl cordon or kubectl drain if you need to do this.


Original Link: https://dev.to/ueokande/how-to-evict-specific-pods-on-the-kubernetes-cluster-1p44

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To