GithubHelp home page GithubHelp logo

devopstoday11 / opa-kube-scheduler Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tsandall/rego-scheduler

0.0 2.0 0.0 21.84 MB

A policy-enabled container scheduler for Kubernetes.

License: Apache License 2.0

Go 97.92% Makefile 2.08%

opa-kube-scheduler's Introduction

opa-kube-scheduler

This project shows how OPA can policy-enable container scheduling in Kubernetes.

Build

To build the scheduler binary:

make

To build the Docker image:

make image

Usage

Kubernetes allows users to run multiple independent schedulers in the cluster. Once an additional scheduler is deployed, pod scheduling can be delegated to it by annotating the pods with the name of the scheduler.

In opa-kube-scheduler, the name of the scheduler is part of the scheduling policy. If annotation does not match the policy, opa-kube-scheduler will ignore the pod:

package io.k8s.scheduler

import requested_pod as req

scheduler_name_match :-
	req.metadata.annotations[k8s_scheduler_annotation] = "experimental"

k8s_scheduler_annotation = "scheduler.alpha.kubernetes.io/name"

fit[node] = weight :-
	scheduler_name_match,
	...

Kubernetes

The scheduler can be deployed on Kubernetes. For example, assuming you are using kubernetes/minikube for test purposes, you can try the scheduler as follows:

  1. Create a deployment for the scheduler:

    kubectl create -f ./examples/deployment.yaml
  2. Expose the scheduler's server as as service:

    kubectl expose deployment opa-kube-scheduler \
    	--port 8181 --target-port 8181 --type NodePort
  3. Obtain the scheduler's URL:

    SCHEDULER_URL=$(minikube service opa-kube-scheduler --url)
  4. Push the scheduling policy to the scheduler:

    curl -X PUT --data-binary \
    	@./examples/policy.rego $SCHEDULER_URL/v1/policies/example
  5. At this point, the scheduler is deployed and the scheduling policy has been installed. Create a replication controller for nginx as a test:

    kubectl create -f ./examples/nginx.yaml
  6. If you tail the scheduler's log, you will see that it has scheduled the nginx pods:

    kubectl logs $(kubectl get pod | grep opa-kube-scheduler | cut -f 1 -d ' ')

Development

If you have built the scheduler, you can run it in the development with:

./opa-kube-scheduler -kubeconfig ~/.kube/config --v 2 --logtostderr 1

opa-kube-scheduler's People

Contributors

tsandall avatar

Watchers

James Cloos avatar  avatar

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.