Giter Site home page Giter Site logo

k8s-python-operator's Introduction

exampleoperatorpy

This repository implements an example Kubernetes operator in Python 3, called "ImmortalContainers". This operator enables the user to define, using custom resources, containers that must run and if terminated must be restarted.

The following diagram shows the main components of this operator controller:

components diagram

Venv and project dependencies

To create a virtual env and install the project dependencies follow these steps:

python3 -m venv venv
. ./venv/bin/activate
make dep

Install CRD and RBAC permissions

To install CRDs and RBAC configurations to your currently set cluster use:

make install

Running the operator outside the cluster

. ./venv/bin/activate
python src/main.py --kubeconfig ~/.kube/config

Running inside the cluster

You must first generate the image using make docker-build and push it to your repo.

If using minikube follow these steps:

eval $(minikube docker-env)
make docker-build

Then create the system namespace

kubectl apply -f config/namespace.yaml

And then run make deploy.

After this you should check that everything is running, ex:

$ kubectl get pods --namespace system                     
NAME                                          READY   STATUS    RESTARTS   AGE
exampleoperatorpy-controller-7cb7f99658-97zjs   1/1     Running   0          24m

$ kubectl logs exampleoperatorpy-controller-7cb7f99658-97zjs --namespace=system

INFO:controller:Controller starting

Using the operator

Once the operator is running you can create immortal containers using a custom resource like this one:

apiVersion: immortalcontainer.flugel.it/v1alpha1
kind: ImmortalContainer
metadata:
  name: example-immortal-container
spec:
  image: nginx:latest

Run kubectl apply -f config/example-use.yaml to try it.

Then run kubectl get pods and check the pod is created. If you kill the pod it will be recreated.

Remove the operator

To remove the operator, CDR and RBAC use make undeploy

Pods created by the operator will not be deleted, but will not be restarted if deleted later.

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.