/rust-k8s-sample-controller

Primary LanguageRustApache License 2.0Apache-2.0

sample-controller

This repository implements a simple controller for watching Foo resources as defined with a CustomResourceDefinition (CRD) following the behavioural contract of kubernetes/sample-controller but written in Rust.

This particular example demonstrates how to perform basic operations such as:

  • How to register a new custom resource (custom resource type) of type Foo using a CustomResourceDefinition.

  • How to create/get/list instances of your new resource type Foo.

  • How to setup a controller on resource handling create/update/delete events.

Purpose

This is an example of how to build a kube-like controller with a single type.

Running

Note
Since the sample-controller uses apps/v1 deployments, the Kubernetes cluster version should be greater than 1.9. Only tested against 1.16
# create a CustomResourceDefinition
kubectl create -f artifacts/examples/crd.yaml

# assumes you have a working kubeconfig, not required if operating in-cluster
cargo run

# create a custom resource of type Foo
kubectl create -f artifacts/examples/example-foo.yaml

# check deployments created through the custom resource
kubectl get deployments

Cleanup

You can clean up the created CustomResourceDefinition with:

kubectl delete crd foos.samplecontroller.k8s.io