GithubHelp home page GithubHelp logo

zhutony / controller-rs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kube-rs/controller-rs

0.0 2.0 0.0 116 KB

A kubernetes example controller

License: Apache License 2.0

Rust 84.37% Makefile 13.99% Dockerfile 1.64%

controller-rs's Introduction

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.

controller-rs's People

Contributors

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