Code Monkey home page Code Monkey logo

k8s-nodeselector-ensurer's Introduction

☸️ Kubernetes NodeSelector ensurer

k8s-nodeselector-ensurer is a watcher whose role is to ensure that all the pods running on the kubernetes cluster adhere to their nodeSelector label list.

That is, when a node stops offering a particular label (e.g. foo=bar) that a pod needs, k8s-nodeselector-ensurer will detect this and thus kill the aforementionned pod.

Example

$ kubectl apply -f nodeselector-ensurer.yml
deployment.apps/nodeselector-ensurer created

$ kubectl apply -f example.yml 
deployment.apps/test-nodeselector created

$ kl get pod -l name=test-nodeselector
NAME                                 READY   STATUS    RESTARTS   AGE
test-nodeselector-5c68758d5f-9dhlw   0/1     Pending   0          3s

$ kl label node node-c24v-2 foo=bar
node/node-c24v-2 labeled

$ kl get pod -l name=test-nodeselector
NAME                                 READY   STATUS    RESTARTS   AGE
test-nodeselector-5c68758d5f-9dhlw   1/1     Running   0          28s

$ kl label node node-c24v-2 foo=notbar --overwrite
node/node-c24v-2 labeled

$ kl get pod -l name=test-nodeselector
NAME                                 READY   STATUS    RESTARTS   AGE
test-nodeselector-5c68758d5f-287sj   0/1     Pending   0          88s

How to use it ❓

First of all, this is a POC, so don't use it. But if you still want to, follow these steps:

Installation

To install this watcher, simply kubectl apply -f nodeselector-ensurer.yml

Pod usage

By default, this watcher does not change the existing nodeSelector logic.

In order to mark pods as being killable when their nodeSelector no longer matches their node's, just annote the pods with frankkkkk.nodeSelectorDuringExecution: "true"

Why this watcher ⁉️

Kubernetes plans on offering the extra requiredDuringSchedulingRequiredDuringExecution affinity type. However it is still (as of k8s 1.18) still not implemented in the node scheduler 😞.

At first I wanted the watcher to implement this feature, however the Pod resource definition is not customizable.

k8s-nodeselector-ensurer's People

Contributors

dependabot[bot] avatar frankkkkk avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

chaitushiva

k8s-nodeselector-ensurer's Issues

Be event based

We should be event-based instead of sleeping and calculating everything every minute.
stream of node changes and stream of new pods. Beware on concurrency issues.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.