Skip to content

antonmisa/dummy-operator

Repository files navigation

dummy-operator

The goal is to use the Operator SDK to write a small Kubernetes Custom Controller in Go and then deploy it on a Kubernetes cluster.

Description

Example of Customer Resource:

apiVersion: interview.com/v1alpha1
kind: Dummy
metadata:
    name: dummy1
    namespace: default
spec:
    message: "I'm just a dummy"
status:
    specEcho: "I'm just a dummy"
    podStatus: "Pending"

Where

  1. specEcho - copy the value of spec.message into status.specEcho by custom controller
  2. podStatus - track of the status of the Pod (Phase) associated to the Dummy by custom controller

At a high-level, this is the flow sequence of the operator's functionality:

  1. User creates a custom resource (CR) via kubectl command under a Kubernetes namespace.
  2. Operator is running on the cluster under the operator's namespace and it watches for these specific custom resources (CR) object.
  3. Operator takes action: create or delete Pods (not scaled).

Getting Started

You’ll need a Kubernetes cluster to run against. You can use KIND or minikube to get a local cluster for testing, or run against a remote cluster. Note: Your controller will automatically use the current context in your kubeconfig file (i.e. whatever cluster kubectl cluster-info shows).

Developer Software

Install all the following:

Running on the cluster

  1. Getting image from hub.docker.com
docker pull savelievant/dummy-operator

or dowload sources from current repo github.com

git clone https://github.com/antonmisa/dummy-operator
  1. To start a minikube cluster on your local machine, run the following command, setting as an arbitrarily name for your cluster (this name will be used for kubectl context):
minikube start

Or using kind cluster on your local machine, run the following command, setting as an arbitrarily name for your cluster (this name will be used for kubectl context):

kind create cluster --name operator-dev
  1. Install Instances of Custom Resources:
kubectl apply -f config/samples/_v1alpha1_dummy2.yaml
  1. Build and push your image to the location specified by IMG:
make docker-build docker-push IMG=interview.com/dummy-operator:v0.0.1
  1. Deploy the controller to the cluster with the image specified by IMG:
make deploy IMG=interview.com/dummy-operator:v0.0.1

Uninstall CRDs

To delete the CRDs from the cluster:

make uninstall

Undeploy controller

UnDeploy the controller from the cluster:

make undeploy

How it works

This project aims to follow the Kubernetes Operator pattern.

It uses Controllers, which provide a reconcile function responsible for synchronizing resources until the desired state is reached on the cluster.

Test It Out

  1. Run unit tests
make test
  1. Run e2e tests:
make test-e2e
  1. Install the CRDs into the cluster:
make install
  1. Run your controller (this will run in the foreground, so switch to a new terminal if you want to leave it running):
make run

NOTE: You can also run this in one step by running: make install run

Modifying the API definitions

If you are editing the API definitions, generate the manifests such as CRs or CRDs using:

make manifests

NOTE: Run make --help for more information on all potential make targets

More information can be found via the Kubebuilder Documentation

About

Simple operator = controller + CR which controls it's Pod

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published