• Stars
    star
    320
  • Rank 131,126 (Top 3 %)
  • Language
    Elixir
  • License
    MIT License
  • Created almost 6 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The Elixir based Kubernetes Development Framework

Bonny

Module Version Coverage Status Last Updated

Build Status CI Build Status Elixir Build Status K8s

Hex Docs Total Download License

Bonny: Kubernetes Development Framework

Extend the Kubernetes API with Elixir.

Bonny make it easy to create Kubernetes Operators, Controllers, and Custom Schedulers.

If Kubernetes CRDs and controllers are new to you, read up on the terminology.

Getting Started

Kickstarting your first controller with bonny is very straight-forward. Bonny comes with some handy mix tasks to help you.

mix new your_operator

Now add bonny to your dependencies in mix.exs

def deps do
  [
    {:bonny, "~> 1.0"}
  ]
end

Install dependencies and initialize bonny. This task will ask you to answer a few questions about your operator.

Refer to the kubernetes docs for API group and API version.

mix deps.get
mix bonny.init

Don't forget to add the generated operator module to your application supervisor.

Configuration

mix bonny.init creates a configuration file config/bonny.exs and imports it to config/config.exs for you.

Configuring Bonny

Configuring bonny is necessary for the manifest generation through mix bonny.gen.manifest.

config :bonny,
  # Function to call to get a K8s.Conn object.
  # The function should return a %K8s.Conn{} struct or a {:ok, %K8s.Conn{}} tuple
  get_conn: {K8s.Conn, :from_file, ["~/.kube/config", [context: "docker-for-desktop"]]},

  # Set the Kubernetes API group for this operator.
  # This can be overwritten using the @group attribute of a controller
  group: "your-operator.example.com",

  # Name must only consist of only lowercase letters and hyphens.
  # Defaults to hyphenated mix app name
  operator_name: "your-operator",

  # Name must only consist of only lowercase letters and hyphens.
  # Defaults to hyphenated mix app name
  service_account_name: "your-operator",

  # Labels to apply to the operator's resources.
  labels: %{
    "kewl": "true"
  },

  # Operator deployment resources. These are the defaults.
  resources: %{
    limits: %{cpu: "200m", memory: "200Mi"},
    requests: %{cpu: "200m", memory: "200Mi"}
  }

Running outside of a cluster

Running an operator outside of Kubernetes is not recommended for production use, but can be very useful when testing.

To start your operator and connect it to an existing cluster, one must first:

  1. Have configured your operator. The above example is a good place to start.
  2. Have some way of connecting to your cluster. The most common is to connect using your kubeconfig as in the example:
# config.exs
config :bonny,
  get_conn: {K8s.Conn, :from_file, ["~/.kube/config", [context: "optional-alternate-context"]]}

If you've used mix bonny.init to generate your config, it created a YourOperator.Conn module for you. You can edit that instead.

  1. If RBAC is enabled, you must have permissions for creating and modifying CustomResourceDefinition, ClusterRole, ClusterRoleBinding and ServiceAccount.
  2. Generate a manifest mix bonny.gen.manifest and install it using kubectl kubectl apply -f manifest.yaml

Now you are ready to run your operator

iex -S mix

Guides

Have a look at the guides that come with this repository. Some can even be opened as a livebook.

Talks

Example Operators built with this version of Bonny

  • Kompost - Providing self-service management of resources for devs

Example Operators built with an older version of Bonny

Telemetry

Bonny uses the telemetry to emit event metrics.

Events: Bonny.Sys.Telemetry.events()

[
    [:reconciler, :reconcile, :start],
    [:reconciler, :reconcile, :stop],
    [:reconciler, :reconcile, :exception],
    [:watcher, :watch, :start],
    [:watcher, :watch, :stop],
    [:watcher, :watch, :exception],
    [:scheduler, :binding, :start],
    [:scheduler, :binding, :stop],
    [:scheduler, :binding, :exception],
    [:task, :execution, :start],
    [:task, :execution, :stop],
    [:task, :execution, :exception],
]

Terminology

Custom Resource:

A custom resource is an extension of the Kubernetes API that is not necessarily available on every Kubernetes cluster. In other words, it represents a customization of a particular Kubernetes installation.

CRD Custom Resource Definition:

The CustomResourceDefinition API resource allows you to define custom resources. Defining a CRD object creates a new custom resource with a name and schema that you specify. The Kubernetes API serves and handles the storage of your custom resource.

Controller:

A custom controller is a controller that users can deploy and update on a running cluster, independently of the cluster’s own lifecycle. Custom controllers can work with any kind of resource, but they are especially effective when combined with custom resources. The Operator pattern is one example of such a combination. It allows developers to encode domain knowledge for specific applications into an extension of the Kubernetes API.

Operator:

A set of application specific controllers deployed on Kubernetes and managed via kubectl and the Kubernetes API.

Contributing

I'm thankful for any contribution to this project. Check out the contribution guide

Operator Blog Posts

More Repositories

1

k8s

Kubernetes API Client for Elixir
Elixir
283
star
2

arbor

Ecto elixir adjacency list and tree traversal. Supports Ecto versions 2 and 3.
Elixir
233
star
3

speakeasy

Middleware based authorization for Absinthe GraphQL powered by Bodyguard
Elixir
81
star
4

klepto

A mean little DSL'd poltergeist (capybara) based web crawler that stuffs data into your Rails app.
Ruby
21
star
5

terraform-aws-cloudwatch_widget

Terraform AWS Cloudwatch Alarm with Dashboard Widget JSON Outputs
HCL
18
star
6

munson

JSON API Spec client for Ruby
Ruby
17
star
7

apocryphal

Swagger based document driven development for ExUnit
Elixir
17
star
8

ballast

Ballast manages kubernetes node pools to give you the cost of preemptible nodes with the confidence of on demand nodes.
Elixir
16
star
9

regulator

Controller-based minimal authorization through OO design and pure Ruby classes
Ruby
15
star
10

ruby-yui

Ruby wrapper for the YUI Compressor.
JavaScript
12
star
11

notion

Notion is a thin wrapper around telemetry that defines functions that dispatch telemetry events, documentation, and specs for your applications events.
Elixir
9
star
12

warningshot

Dependency Resolution Framework
Ruby
8
star
13

talks

Elixir
8
star
14

docker-kinesis-agent

AWS Kinesis Agent on Debian Slim 9
Makefile
7
star
15

dm-property-manager

Model ancestry and property management
Ruby
5
star
16

jquery.babysteps

A simple tool for turning long forms into baby steps.
5
star
17

federated-absinthe

Federating absinthe graphql with GraphQL Mesh.
Elixir
5
star
18

hello_operator

A greeting-server operator created with Bonny
Elixir
5
star
19

k8s-psp-rbac

Assigning kubernetes pod security policies with RBAC
4
star
20

k8s-elixir-schedulers

This is an example app used to illustrate how online schedulers are configured post OTP23 running in kubernetes.
Elixir
4
star
21

ingestor

Tool for ingesting plain text files in ActiveRecord
Ruby
3
star
22

activity_pub

ActivityPub is a decentralized social networking protocol
Elixir
3
star
23

k8s_conf

Parse Kubernetes' config files and generate HTTP headers/options for authenticating to the k8s API.
Elixir
3
star
24

merb_threshold

Access thresholding for controllers and actions. Set reasonable limits and stop constantly captchaing your users.
Ruby
3
star
25

k8s_client

Experimental kubernetes client in elixir
Elixir
3
star
26

petz

Phoenix app using Apocryphal / Swagger for testing
JavaScript
2
star
27

collectively

Add methods to ActiveRecord relations and collections.
Ruby
2
star
28

MerbMax

A collection of plugins for merb. Get your SEO on with meta, configure your instances with roles.
Ruby
2
star
29

res

Elixir state machine demo
Elixir
2
star
30

activity_streams

ActivityStreams 2.0 Validator
Elixir
2
star
31

merb_meta

SEO your merb, easy access to meta tags on a controller-by-controller or action-by-action basis, wee.
Ruby
2
star
32

try_git

1
star
33

images

Some of the best images on the planet.
1
star
34

metrics-mock

A simple prometheus metrics mock service
Go
1
star
35

kinesis-parser

Parse kinesis events
JavaScript
1
star
36

tf_modules

Terraform modules
HCL
1
star
37

yodeler

A generic instrumentation library with a multiple pluggable backend adapters.
Ruby
1
star
38

sacred

A CLI to sync markdown to the Confluence REST API
Go
1
star
39

json-schema-rails-rspec-demo

JSON Schema demo with Rails, RSpec, prmd, committee and active model serializers
Ruby
1
star
40

drinks

A boozy app to teach JSONAPI and some other stuff on Nerd Nights.
Ruby
1
star
41

phoenix-demo-project

Just a demo project for Phoenix
JavaScript
1
star
42

greeting-server

A greeting server for demoing the Bonny SDK
Go
1
star