GithubHelp home page GithubHelp logo

dotnet-operator-sdk's Introduction

Build NuGet

.NET operator SDK

Build Kubernetes Operators in C# (or whatever .NET language) without hassle.

Inspired by this post I thought the .NET community should also have an easy way of creating a Kubernetes Operator with their favorite language. ;)

So, here it is... (you can also find it at NuGet)

I am pretty new on the internals of Kubernetes and this was a fun way to discover how the API and other resources work. I am I'm not saying this is a great/production-ready solution.

Also based on the post from above I thought of doing a simple example, and created a CustomResourceDefinition to create Microsoft SQL Server databases. You can take a look at the sample here, maybe more examples will eventually develop, it depends on the traction of the project.

Usage

The .NET operator SDK is a thin wrapper around the KubernetesClient providing a few classes and interfaces specifically for creating an operator controller.

Reference in your project

First of all, include the NuGet package of the SDK into your project (normally a .NET Core Class Library).

$ dotnet add package ContainerSolutions.Kubernetes.OperatorSDK

Create you CustomResourceDefinition (CRD)

This is important because your CRD will describe the name, group, version, and properties of your operator. There's a base class in the SDK called ContainerSolutions.OperatorSDK.BaseCRD from which you have to inherit your own CRD class and add the appropriate Spec(properties).

Note: In the near(?) future and want to add a CRDToCsharp generator. Given your yaml file, create the appropriate classes for the operator.

Implement your actions

You need to define what will happen when one of your newly defined objects get created, and deleted, what about modified?

There's an interface called ContainerSolutions.OperatorSDK.IOperationHandler<T> which contains all the needed methods that the operator will call when one of these events gets raised.

Don't forget the reconciliation loop!

The methods described above will be called when someone explicitly creates (deletes or modifies) one of your objects in the cluster. But what happens if for some reason the defined resource fails.

Think about the Deployment controller. When a deployment gets created it spins up a Pod (actually, as many Pods as the replica stated) and if one of the Pods crashes or deletes it, the Deployment controller will realize that the desired state does not equal to the actual/real state, so, it'll try to spin up another Pod.

The same thing could (should?) happen when your controller. Your resource can fail or be modified and you need to realize that there was a change and proceed accordingly.

That's what the CheckCurrentState of the IOperationHandler is for. Your CRD will have a ReconciliationCheckIntervalproperty which defaults to 5 (seconds). This interval will be used to call your function (CheckCurrentState) where you'll have to check on the existing and desired resources.

Samples

There's one example included with the SDK which I believe it's the easiest way of understanding how to use it.

Take a look a the MSSQLDB sample to see how it works.

dotnet-operator-sdk's People

Contributors

sebagomez 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.