Skip to content
A kubernetes example controller
Rust Makefile Dockerfile
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
src more updates Dec 13, 2019
yaml 0.4.0 Jul 23, 2019
.gitignore 0.4.0 Jul 23, 2019
Cargo.lock more updates Dec 13, 2019
Cargo.toml
Dockerfile
LICENSE
Makefile 0.4.0 Jul 23, 2019
README.md comments Dec 12, 2019

README.md

controller-rs

CircleCI docker pulls docker image info docker tag

A kubernetes controller for a Foo resource using informers in rust.

Requirements

A kube cluster / minikube. Install the CRD and an instance of it into the cluster:

kubectl apply -f yaml/examplecrd.yaml
kubectl apply -f yaml/crd-qux.yaml

Running

Local Config

You need a valid local kube config with sufficient access (foobar service account has sufficient access if you want to impersonate the one in yaml/access.yaml).

Start the server with cargo run:

export NAMESPACE=default
cargo run

In-cluster Config

Deploy as a deployment with scoped access via a service account. See yaml/deployment.yaml as an example.

kubectl apply -f yaml/deployment.yaml
sleep 10 # wait for docker pull and start on kube side
export FOO_POD="$(kubectl get pods -n default -lapp=foo-controller --no-headers | awk '{print $1}')"
kubectl port-forward ${FOO_POD} -n default 8080:8080 # keep this running

Usage

Once the app is running, you can see that it observes foo events.

You can try to remove a foo:

kubectl delete foo qux -n default

then the app will soon print:

[2019-04-28T22:03:08Z INFO  controller::state] Deleted Foo: qux

ditto if you try to apply one:

kubectl apply -f yaml/crd-baz.yaml -n default
[2019-04-28T22:07:01Z INFO  controller::state] Adding Foo: baz (this is baz)

If you edit, and then apply, baz, you'll get:

[2019-04-28T22:08:21Z INFO  controller::state] Modifyied Foo: baz (edit str)

Webapp output

The sample web server exposes some example metrics and debug information you can inspect with curl.

$ kubectl apply -f yaml/crd-qux.yaml -n default
$ curl localhost:8080/metrics
# HELP handled_events handled events
# TYPE handled_events counter
handled_events 1
$ curl localhost:8080/
{"last_event":"2019-07-17T22:31:37.591320068Z"}

Events

The event handler in controller.rs currently does not mutate anything in kubernetes based on any events here as this is an example.

You can perform arbitrary kube actions using the client. See kube-rs/examples and the api docs for kube::api::Api for ideas.

You can’t perform that action at this time.