https://github.com/stackzoo/k8s-rust-operator-poc
Kubernetes rust operator proof of concept đĻ â¸
https://github.com/stackzoo/k8s-rust-operator-poc
kind kubernetes kubernetes-operator rust
Last synced: 10 months ago
JSON representation
Kubernetes rust operator proof of concept đĻ â¸
- Host: GitHub
- URL: https://github.com/stackzoo/k8s-rust-operator-poc
- Owner: stackzoo
- Created: 2023-11-22T10:19:27.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-11-22T10:24:14.000Z (about 2 years ago)
- Last Synced: 2025-01-15T15:08:30.164Z (11 months ago)
- Topics: kind, kubernetes, kubernetes-operator, rust
- Language: Rust
- Homepage:
- Size: 15.6 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# KUBERNETES RUST OPERATOR POC đĻ â¸
## Abstract
This repo contains a straightforward *proof of concept* of a simple Kubernetes operator made with [kube-rs](https://github.com/kube-rs/kube).
This operator does nothing but define a CRD called `inventories.stackzoo.io` that basically gather nodes information (names) via the kubernetes api.
> **Warning**
> This is just a PoC, do not use in production!
## Prerequisites
- [KinD](https://kind.sigs.k8s.io/)
- [Rust](https://www.rust-lang.org/it)
## Instructions to Test
Spin up a 4 node local cluster with `KinD`:
```console
kind create cluster --config kind-cluster-config.yaml
```
Output:
```console
Creating cluster "operator-cluster" ...
â Ensuring node image (kindest/node:v1.27.3) đŧ
â Preparing nodes đĻ đĻ đĻ đĻ
â Writing configuration đ
â Starting control-plane đšī¸
â Installing CNI đ
â Installing StorageClass đž
â Joining worker nodes đ
Set kubectl context to "kind-operator-cluster"
You can now use your cluster with:
kubectl cluster-info --context kind-operator-cluster
Thanks for using kind! đ
```
Now launch the operator with the *cargo run* command:
```console
cargo run
2023-11-22T09:37:48.187293Z INFO k8s_rust_operator_poc: Creating crd: ---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: inventories.stackzoo.io
spec:
group: stackzoo.io
names:
categories: []
kind: Inventory
plural: inventories
shortNames: []
singular: inventory
scope: Namespaced
versions:
- additionalPrinterColumns: []
name: v1
schema:
openAPIV3Schema:
description: "Auto-generated derived type for InventorySpec via `CustomResource`"
properties:
spec:
properties:
name:
type: string
nodes:
items:
type: string
type: array
required:
- name
- nodes
type: object
status:
nullable: true
properties:
is_bad:
type: boolean
required:
- is_bad
type: object
required:
- spec
title: Inventory
type: object
served: true
storage: true
subresources:
scale:
specReplicasPath: ".spec.replicas"
statusReplicasPath: ".status.replicas"
status: {}
2023-11-22T09:37:48.253748Z INFO k8s_rust_operator_poc: Waiting for the api-server to accept the CRD
2023-11-22T09:37:48.353980Z INFO k8s_rust_operator_poc: Applied 1 default: InventorySpec { name: "default", nodes: ["operator-cluster-control-plane", "operator-cluster-worker", "operator-cluster-worker2", "operator-cluster-worker3"] }
```
Open a new terminal session and check your cluster CRDs:
```console
kubectl get crds
NAME CREATED AT
inventories.stackzoo.io 2023-11-22T09:37:48Z
```
Let's see what instances of inventories.stackzoo.io we have on our cluster:
```console
kubectl get inventories.stackzoo.io
NAME AGE
default 2m59s
```
Now let's retrieve that CR with the `kubectl get inventories.stackzoo.io default -o yaml` command :
```yaml
apiVersion: stackzoo.io/v1
kind: Inventory
metadata:
creationTimestamp: "2023-11-22T09:37:48Z"
generation: 1
name: default
namespace: default
resourceVersion: "836"
uid: 6add7ef4-fb3b-49ed-b8df-de704abbf923
spec:
name: default
nodes:
- operator-cluster-control-plane
- operator-cluster-worker
- operator-cluster-worker2
- operator-cluster-worker3
```
As we can see we find our cluster nodes listed under the `spec/nodes` property.
## Next Steps
For a slightly more intricate example, please refer to [this](https://github.com/Pscheidl/rust-kubernetes-operator-example) repository.