Bonny: Extending Kubernetes with Elixir — Part 2

Cory O'Daniel
Dec 30, 2018 · 4 min read
Arrrr, step away from the helm, gopher.
  • You have a docker/quay.io account.
  • You have a running Kubernetes cluster. Start here if you don’t.

Hello Operator

We are going to create a “Hello Operator.” This operator will have a single custom resource definition named Greeting that will be composed of a Kubernetes Deployment and Service running this greeting-server

mix new hello_operator
mix deps.get
mix bonny.gen.controller Greeting greetings* creating lib/hello_operator/controllers/v1/greeting.ex
* creating test/hello_operator/controllers/v1/greeting_test.exs
For a full list of options, see the README.
You’re the best.
# We need to compile our app so that the mix task can pick up our controller implementations
mix compile
# Generate a manifest. If you were deploying to production supply the --image flag
mix bonny.gen.manifest
# Deploy RBAC and CRDs
kubectl apply -f ./manifest.yaml
# Start our operator
iex -S mix
kubectl apply -f https://raw.githubusercontent.com/coryodaniel/hello_operator/master/greetings.yaml
An example Greeting resource
@moduledoc removed for conciseness
  • plural: The plural name will be prepended to the group to identify this CRD in the group. You can also use this name with kubectl kubectl get greetings.
  • singular: The name of the resource. Used as the singular form in kubectl kubectl get greeting/hello-server.
  • short_names: List of “short names” that kubectl will recognize for this resource. E.g.: kubectl get gre and kubectl get greet
@rule {"apps", ["deployments"], ["*"]}@rule {"", ["services"], ["*"]}
  • modify/1 called when a CRD resource is updated.
  • delete/1 called when a CRD resource is deleted.
  1. Did I write an Elixir Kubernetes framework, then make an example app in Go?! Yes, I’m a complicated person.

CoryODaniel

Notes on SQL, ruby, elixir, tacos, and whiskey

Cory O'Daniel

Written by

SQL, kubernetes, elixir, ruby, node, tacos, whiskey, repeat.

CoryODaniel

Notes on SQL, ruby, elixir, tacos, and whiskey