Simple Kubernetes operator built from scratch with client-go.
Kubernetes operator pattern implementation using the client-go library. Altough there are a bunch of frameworks for doing this (kubebuilder, operator framework ...), this example operator uses the tools provided by client-go for simplicity and flexibility reasons.
Medium article that explains how to build this operator step by step.
- Simple example to understand how a Kubernetes operator works.
- Manages Echo CRDs for executing an
echoinside a pod. - Manages ScheduledEcho CRDs for scheduling the execution of an
echoinside a pod. - High Availability operator using Kubernetes lease objects.
- Prometheus metrics.
- Helm chart.
| Echo | ScheduledEcho | Job | CronJob | Lease | Kubernetes |
|---|---|---|---|---|---|
| v1alpha1 | v1alpha1 | v1 | v1 | v1 | v1.21.x |
helm repo add mmontes https://mmontes11.github.io/charts
helm install echoperator mmontes/echoperatorThe helm chart installs automatically the Custom Resource Definitions needed for this operator to work. However, if you wanted to install them manually, you can find them in the helm chart repo.
- Client creates a hello world Echo CRD.
- Operator receives a
Echoadded event. - Operator reads the
messageproperty from theEchoand creates aJobresource. - The
Jobresource creates aPodthat performs aechocommand with themessageproperty.
- Client creates a hello world ScheduledEcho CRD.
- Operator receives a
ScheduledEchoadded event. - Operator reads the
messageandscheduleproperty from theScheduledEchoand creates aCronJob. - The
CronJobschedules aJobcreation using thescheduleproperty. - When scheduled, the
Jobresource creates aPodthat performs aechocommand with themessageproperty.