Emoji is a sample application to demonstrate how to build a Kubernetes Operator. The operator monitor the Emoji Custom Resources and publish them in an API. To know more about this application, check Programmez #237 on programmez.com
The application design looks like below:
- An Emoji CRD allow to declare Emojis in Kubernetes
- A controller get all the Emojis from Kubernetes and synchronize them with the application. Once done, it publishes the status back to the resource.
To build the application, you must have make, go, kustomize and docker installed
on your instance. Set the REGISTRY variable and run make build-docker like
in the example below:
cd app
export REGISTRY=registry:5000
make build-dockerTo install the application, set the REGISTRY variable, run change the image
settings in the kustomization.yaml file and run a kubectl apply command:
export REGISTRY=registry:5000
kustomize edit set image emojis-app=${REGISTRY}/emojis-app:latest
kubectl apply -k .To test the application, connect to port 8080 and run a curl command like
below; It should return an empty JSON and an HTTP-200 status code:
kubectl port-forward svc/emojis 8080:8080
curl -v 127.0.0.1:8080This project contains a step by step example of how to build a controller. Each
branch contains a step. To work with it, go to master which has no operator
at all, only the application. The main steps are:
operator/01-initializationcontains the code scaffoldoperator/02-namespace-operatorchanges the operator so that it monitors a single namespaceoperator/03-crd-and-controllercreates en empty emoji CRD and controlleroperator/04-specify-emoji-typeadd expected types to the CRDoperator/05-implement-supportimplements a status.supported properties that tells if the Emoji is supportedoperator/06-implement-finalizerimplements a finalizer to manage resource deletionoperator/07-implement-applogicadds the logic to interact with the apioperator/08-deploymentperform the last changes to deploy the controller
