Giter VIP home page Giter VIP logo

k8s-operator-socialbook's Introduction

Kubernetes Operator

Description

This operator is used to set up this application. The application includes a Nodejs server and a MongoDB database. Docker image of the server can be found here.
When a new SocialBook custom resource is created the custom controller will create a MongoDB deployment, a corresponding service for it, Persistent Volume and Persistent Volume Claim. It will also create a SocialBook deployment and an external service so that it can be accessed outside the cluster.
Apart from this it will also create a Config Map and Network policies for both MongoDB and SocialBook pods. The number of replicas and other information can be passed in the spec of the custom resource.

Note: For the network policies to work, a network plugin should already be installed on the cluster.

Usage

Outside the cluster

  1. Clone the repo - git clone https://github.com/Ashwin901/K8s-Operator-SocialBook.git
  2. Run kubectl apply -f manifests/operators_socialbooks.yaml to install the CRD.
  3. Run go build from the parent directory.
  4. Run ./social-book-operator --config <kube config file path> (In linux systems usually kube config file path is /home/username/.kube/config).

Inside the cluster

  1. To install the operator inside the cluster we can use the docker image of the operator.
  2. Install the CRD by using the following file.
  3. Copy the files from this directory.
  4. rbac.yml file conists of a service account, cluster role and cluster role binding. This basically gives the operator permissions to access Kubernetes resources. Run kubectl apply -f rbac.yml.
  5. deployment.yml creates a deployment for the operator docker image. Run kubectl apply -f deployment.yml

Now you can test the operator by creating a new SocialBook custom resource. You can use this example. Run kubectl apply -f example1.yml. Once the custom resource is created check the dev namespace(in the above example dev namespace is used but you can use any namespace) if all the resources are created.

Accessing the app

If you are using minikube use the following command: minikube service -n dev socialbook1 (socialbook1 - name used in the above example)

Components

  1. Custom Resource
  2. Controller

Custom Resource

  1. CRD
  2. Group: ashwin901.operators Version: v1alpha1 Kind: SocialBook
  3. Example for the Custom Resource can be found here

Controller

  1. Controller code can be found here.

  2. When a SocialBook CR is created the custom controller sets up the following resources:
    1. Config Map
    2. Persistent Volume
    3. Persistent Volume Claim
    4. Deployment - MongoDB and SocialBook
    5. Services
    6. Network Policy - Ensures that the MongoDB pod only accepts requests from SocialBook pods(ingress) and SocialBook pods can only make requests to MongoDB pods(egress).

  3. If any of the above mentioned resource is updated/deleted then the custom controller will detect the change and try to get it back to the desired state.

  4. If a particular SocialBook resource is deleted then all the resources setup for it will also be deleted. This is done with the help of owner reference.

Tools

  1. Code Generator - To generate code for clientset, informers and lister
  2. Controller Gen - To generate manifests for CRD

k8s-operator-socialbook's People

Contributors

ashwin901 avatar

Watchers

 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.