https://github.com/mmontes11/echoperator
🤖 Simple Kubernetes operator built from scratch with client-go
https://github.com/mmontes11/echoperator
client-go crd custom-resource-definition go golang high-availability kubernetes kubernetes-operator leader-election operator
Last synced: 7 months ago
JSON representation
🤖 Simple Kubernetes operator built from scratch with client-go
- Host: GitHub
- URL: https://github.com/mmontes11/echoperator
- Owner: mmontes11
- License: mit
- Created: 2021-07-12T18:28:05.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-03-16T18:18:02.000Z (over 2 years ago)
- Last Synced: 2024-10-12T02:50:29.073Z (12 months ago)
- Topics: client-go, crd, custom-resource-definition, go, golang, high-availability, kubernetes, kubernetes-operator, leader-election, operator
- Language: Go
- Homepage:
- Size: 101 KB
- Stars: 42
- Watchers: 3
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 🤖 echoperator
[](https://github.com/mmontes11/echoperator/actions/workflows/ci.yml)
[](https://github.com/mmontes11/echoperator/actions/workflows/release.yml)
[](https://goreportcard.com/report/github.com/mmontes11/echoperator)
[](https://pkg.go.dev/github.com/mmontes11/echoperator)
[](https://artifacthub.io/packages/helm/mmontes/echoperator)
[](https://opensource.org/licenses/MIT)Simple Kubernetes operator built from scratch with [client-go](https://github.com/kubernetes/client-go).
[Kubernetes operator pattern](https://kubernetes.io/docs/concepts/extend-kubernetes/operator/) implementation using the [client-go](https://github.com/kubernetes/client-go) library. Altough there are a bunch of frameworks for doing this ([kubebuilder](https://book.kubebuilder.io/), [operator framework](https://operatorframework.io/) ...), this example operator uses the tools provided by [client-go](https://github.com/kubernetes/client-go) for simplicity and flexibility reasons.
[Medium article](https://betterprogramming.pub/building-a-highly-available-kubernetes-operator-using-golang-fe4a44c395c2) that explains how to build this operator step by step.
### Features
- Simple example to understand how a Kubernetes operator works.
- Manages [Echo CRDs](https://github.com/mmontes11/charts/blob/main/charts/echoperator/crds/echo.yml) for executing an `echo` inside a pod.
- Manages [ScheduledEcho CRDs](https://github.com/mmontes11/charts/blob/main/charts/echoperator/crds/scheduledecho.yml) for scheduling the execution of an `echo` inside a pod.
- High Availability operator using Kubernetes [lease](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#lease-v1-coordination-k8s-io) objects.
- Prometheus metrics.
- [Helm chart](https://github.com/mmontes11/charts/tree/main/charts/echoperator).### Versioning
|Echo|ScheduledEcho|Job|CronJob|Lease|Kubernetes|
|----|-------------|---|-------|-----|----------|
|v1alpha1|v1alpha1|v1|v1|v1|v1.21.x|### Installation
```bash
helm repo add mmontes https://mmontes11.github.io/charts
helm install echoperator mmontes/echoperator
```### Custom Resource Definitions (CRDs)
The helm chart installs automatically the [Custom Resource Definitions](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/) needed for this operator to work. However, if you wanted to install them manually, you can find them in the [helm chart repo](https://github.com/mmontes11/charts/tree/main/charts/echoperator/crds).
### Example use cases
###### Hello world
- Client creates a [hello world Echo CRD](./manifests/examples/hello-world.yml).
- Operator receives a `Echo` added event.
- Operator reads the `message` property from the `Echo` and creates a `Job` resource.
- The `Job` resource creates a `Pod` that performs a `echo` command with the `message` property.###### Scheduled hello world
- Client creates a [hello world ScheduledEcho CRD](./manifests/examples/hello-world-scheduled.yml).
- Operator receives a `ScheduledEcho` added event.
- Operator reads the `message` and `schedule` property from the `ScheduledEcho` and creates a `CronJob`.
- The `CronJob` schedules a `Job` creation using the `schedule` property.
- When scheduled, the `Job` resource creates a `Pod` that performs a `echo` command with the `message` property.