Skip to content
A simple kubernetes operator - using Operator SDK
Go Shell Dockerfile
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
build
cmd/manager
deploy
pkg 🎨 Use same style error handling Oct 17, 2019
version 🎉 Ran 'operator-sdk new podreplica-operator --repo github.com/wtfjoke… Sep 10, 2019
.gitignore 🎉 Ran 'operator-sdk new podreplica-operator --repo github.com/wtfjoke… Sep 10, 2019
README.md 📝 Add blogpost link Nov 4, 2019
go.mod ⬆️ Upgrade operator-sdk to v0.11.0 Oct 14, 2019
go.sum ⬆️ Upgrade operator-sdk to v0.11.0 Oct 14, 2019
tools.go

README.md

PodReplica Operator

This is a companion repository to the blog post "Kubernetes Operators: Operations-Wissen als Code". Please refer to the post for further information and instructions.

This k8 operator is created for demonstrating purpose using the operator-sdk in version v0.11.0. It introduces a new Custom Ressource Definition (CRD) "PodReplica". It works like a regular k8 deployment.

Run locally (instead of Build & Publish)

Register CRD:

kubectl create -f deploy/crds/app.example.com_podreplicas_crd.yaml

Set operator name as environment variable

export OPERATOR_NAME=podreplica

Start:

operator-sdk up local --namespace=default

Start with debugging:

operator-sdk up local --namespace=default --enable-delve

Create Custom Resource

After operator is running you can create a podreplica, for example with:

kubectl create -f deploy/crds/app_v1alpha1_podreplica_cr.yaml

Build & Publish Operator (on dockerhub)

# On Linux
operator-sdk build <user>/podreplica:v0.0.1
sed -i 's|REPLACE_IMAGE|<user>/podreplica:v0.0.1|g' deploy/operator.yaml
docker push <user>/podreplica:v0.0.1

# On OSX
sed -i "" 's|REPLACE_IMAGE|<user>/podreplica-operator:v0.0.1|g' deploy/operator.yaml
docker push <user>/podreplica-operator:v0.0.1

Create PodReplica Operator

Register CRD:

kubectl create -f deploy/crds/app.example.com_podreplicas_crd.yaml

Create RBAC and Operator:

kubectl create -f deploy/service_account.yaml
kubectl create -f deploy/role.yaml
kubectl create -f deploy/role_binding.yaml
kubectl create -f deploy/operator.yaml

Afterwards you can follow Create Custom Resource

Remove PodReplica Operator

kubectl delete -f deploy/crds/app.example.com_v1alpha1_podreplica_cr.yaml
kubectl delete -f deploy/crds/app.example.com_podreplicas_crd.yaml
kubectl delete -f deploy/operator.yaml
kubectl delete -f deploy/role_binding.yaml
kubectl delete -f deploy/role.yaml
kubectl delete -f deploy/service_account.yaml
You can’t perform that action at this time.