An example of a Kubernetes operator implemented in Rust

Overview

Rust Kubernetes operator example

A Kubernetes operator built on top of kube-rs project. There is an explanatory article available.

Steps to run on Linux:

  1. Install Rust
  2. Install Kubernetes, K3S.io is an excellent choice, installed simply with curl -sfL https://get.k3s.io | sh -. Make sure to sudo chown $USER /etc/rancher/k3s/k3s.yaml if you're accessing the Kubernetes cluster using the kubeconfig at /etc/rancher/k3s/k3s.yaml as non-root user. Also, export KUBECONFIG=/etc/rancher/k3s/k3s.yaml, so the operator can find the kubeconfig.
  3. Use kubectl apply -f echoes.example.com.yaml to create the CustomResourceDefinition inside Kubernetes.
  4. Build the project with cargo build. If the build fails, make sure libssl-dev is available.
  5. Run the operator using cargo run. It will run outside of the Kubernetes cluster and connect to the Kubernetes REST API using the account inside the KUBECONFIG automatically.

Finally, a custom Echo resource can be created with kubectl apply -f echo-example.yaml. A new deployment of two pods with Echo REST API service will be created. This can be checked with the kubectl get pods or kubectl get deployments command.

Usage showcase

You might also like...
Simple autoclicker written in Rust, to learn the Rust language.

RClicker is an autoclicker written in Rust, written to learn more about the Rust programming language. RClicker was was written by me to learn more ab

Rust programs written entirely in Rust

mustang Programs written entirely in Rust Mustang is a system for building programs built entirely in Rust, meaning they do not depend on any part of

Rust 核心库和标准库的源码级中文翻译,可作为 IDE 工具的智能提示 (Rust core library and standard library translation. can be used as IntelliSense for IDE tools)

Rust 标准库中文版 这是翻译 Rust 库 的地方, 相关源代码来自于 https://github.com/rust-lang/rust。 如果您不会说英语,那么拥有使用中文的文档至关重要,即使您会说英语,使用母语也仍然能让您感到愉快。Rust 标准库是高质量的,不管是新手还是老手,都可以从中

A library for extracting #[no_mangle] pub extern "C" functions (https://docs.rust-embedded.org/book/interoperability/rust-with-c.html#no_mangle)

A library for extracting #[no_mangle] pub extern "C" functions In order to expose a function with C binary interface for interoperability with other p

clone of grep cli written in Rust. From Chapter 12 of the Rust Programming Language book

minigrep is a clone of the grep cli in rust Minigrep will find a query string in a file. To test it out, clone the project and run cargo run body poem

Rust-blog - Educational blog posts for Rust beginners

pretzelhammer's Rust blog 🦀 I write educational content for Rust beginners and Rust advanced beginners. My posts are listed below in reverse chronolo

The ray tracer challenge in rust - Repository to follow my development of
The ray tracer challenge in rust - Repository to follow my development of "The Raytracer Challenge" book by Jamis Buck in the language Rust

The Ray Tracer Challenge This repository contains all the code written, while step by implementing Ray Tracer, based on the book "The Ray Tracer Chall

Learn-rust-the-hard-way - "Learn C The Hard Way" by Zed Shaw Converted to Rust

Learn Rust The Hard Way This is an implementation of Zed Shaw's Learn X The Hard Way for the Rust Programming Language. Installing Rust TODO: Instruct

Learn to write Rust procedural macros [Rust Latam conference, Montevideo Uruguay, March 2019]
Learn to write Rust procedural macros [Rust Latam conference, Montevideo Uruguay, March 2019]

Rust Latam: procedural macros workshop This repo contains a selection of projects designed to learn to write Rust procedural macros — Rust code that g

Comments
  • Example doesn't create a deployment on Minikube

    Example doesn't create a deployment on Minikube

    Hi,

    Thanks for sharing this great idea. I tried replicating the result on Minikube (which is what we're using), but the steps from the readme do not produce a deployment at my end. I didn't change a single line in the checkout, but this is the result when I run the build and apply the echo resource:

    ...
    /home/reinv/.cargo/bin/cargo run --color=always
       Compiling k8s-openapi v0.13.0
       Compiling kube-core v0.60.0
       Compiling kube v0.60.0
       Compiling kube-runtime v0.60.0
       Compiling operator v0.1.0 (/home/reinv/Documents/Git/rust-kubernetes-operator-example)
        Finished dev [unoptimized + debuginfo] target(s) in 17.45s
         Running `target/debug/operator`
    Reconciliation successful. Resource: (ObjectRef { dyntype: (), name: "test-echo", namespace: Some("default") }, ReconcilerAction { requeue_after: Some(10s) })
    Reconciliation successful. Resource: (ObjectRef { dyntype: (), name: "test-echo", namespace: Some("default") }, ReconcilerAction { requeue_after: Some(10s) })
    Reconciliation successful. Resource: (ObjectRef { dyntype: (), name: "test-echo", namespace: Some("default") }, ReconcilerAction { requeue_after: Some(10s) })
    Reconciliation successful. Resource: (ObjectRef { dyntype: (), name: "test-echo", namespace: Some("default") }, ReconcilerAction { requeue_after: Some(10s) })
    ...
    

    But when I look in my Minikube dashboard, there's no deployment and no pods being deployed. Any ideas?

    Thanks in advance!

    bug 
    opened by reinvantveer 3
  • Few small improvements

    Few small improvements

    1. Use a fully qualified finalizer name. Because of the way the finalizer code is written (clears all finalizers before delete), this will work with existing deployed echos, which isn't super important for an example app, but kind of neat. I discovered this when getting an error using this finalizer name on a deployment, and the kube builder book recommended adding a /finalizer suffix. https://book.kubebuilder.io/reference/using-finalizers.html
    2. Make echo::delete a no-op if the deployment was manually deleted. Currently it just fails. Again, example app, but gives an example for doing it.
    3. Check for existence of a deployment in the reconciliation path. If the deployment was manually deleted, recreate it. This one could certainly be removed from this PR for now. In the future I'd like to follow up with a PR that updates the replica count as the CRD changes.

    A few small improvements. Wanted to offer them up. Feel free to close this PR if you're 👎 . Thanks!

    opened by film42 2
  • Use a full qualified finalizer name

    Use a full qualified finalizer name

    Continuation of https://github.com/Pscheidl/rust-kubernetes-operator-example/pull/9

    Use a fully qualified finalizer name. Because of the way the finalizer code is written (clears all finalizers before delete), this will work with existing deployed echos, which isn't super important for an example app, but kind of neat. I discovered this when getting an error using this finalizer name on a deployment, and the kube builder book recommended adding a /finalizer suffix. https://book.kubebuilder.io/reference/using-finalizers.html

    @Pscheidl I'm so sorry for not responding to the other PR before. I completely missed the notification. Here's just the first commit from #9 .

    opened by film42 1
Owner
Pavel Pscheidl
Software engineer | Rustacean
Pavel Pscheidl
A minimal version of 'grep' implemented in Rust. Exercise in the "The Rust Programming Language" book.

Minigrep - A simple grep-like tool implemented in Rust This simple CLI tool searches for a given pattern in a specified file and as a result, it print

Filip Szutkowski 3 Mar 15, 2024
Take your first step in writing a compiler. Implemented in Rust.

first-step-rust Take your first step in writing a compiler, using Rust. Building from Source Make sure the Rust toolchain is installed on your compute

PKU Compiler Course 13 Aug 28, 2022
An API for getting questions from http://either.io implemented fully in Rust, using reqwest and some regex magic. Provides asynchronous and blocking clients respectively.

eithers_rust An API for getting questions from http://either.io implemented fully in Rust, using reqwest and some regex magic. Provides asynchronous a

null 2 Oct 24, 2021
A pretty simple VM implemented with C++. Just one of my practices.

Bailan VM Overview Bailan VM is a simple VM implemented in C++. It just one of my little practices, but my friend, Zihao Qu encouraged me to open its

27Onion Nebell 3 Oct 6, 2022
ARM TrustZone-M example application in Rust, both secure world side and non-secure world side

ARM TrustZone-M example application in Rust, both secure world side and non-secure world side; projects are modified from generated result of cortex-m-quickstart.

null 44 Dec 4, 2022
A Domain Driven Design example application in Rust.

Rust Domain Driven Design Example rust-ddd Rust Domain-Driven-Design (DDD) Summery This repository is used to present how I find implementing DDD in R

Behrouz R.Farsi 6 Nov 15, 2022
Example (with solution) for the Rust Fundamentals Workshop

Workshop Repo: Rust Fundamentals NOTE: This is Work-In-Progress! Please check for updates a day before the workshop. This Github repository contains a

Stefan Baumgartner 5 Jan 31, 2023
Complete code for the larger example programs from the book.

Code Examples for Programming Rust This repository contains complete code for the larger example programs from the book “Programming Rust”, by Jim Bla

Programming Rust 670 Jan 1, 2023
example codes for CIS198 https://cis198-2016s.github.io/

CIS198: RUST 编程语言 学习背景 rust 和 c/c++/Java/Python/golang 不太一样 rust 学习曲线比较陡峭 rust 有很多颠覆认知的特性: 所有权,生命周期,借用检测 cargo 工具 函数式+命令式支持 视频讲解见 B站 课程大纲 Timeline Lec

Jinghui Hu 3 Apr 9, 2024
Leetcode Solutions in Rust, Advent of Code Solutions in Rust and more

RUST GYM Rust Solutions Leetcode Solutions in Rust AdventOfCode Solutions in Rust This project demostrates how to create Data Structures and to implem

Larry Fantasy 635 Jan 3, 2023