Your Guide to Kubernetes Operators

Extending the Kubernetes API

$ kubectl get DaemonSet myDS -o yaml
apiVersion: apps/v1
kind: DaemonSet
$ tree -L 2...├── apps
│ ├── OWNERS
│ ├── v1
│ ├── v1beta1
│ └── v1beta2
...
type DaemonSet struct {
metav1.TypeMeta `json:",inline"`
// Standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
// +optional
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`

// The desired behavior of this daemon set.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
// +optional
Spec DaemonSetSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`

// The current status of this daemon set. This data may be
// out of date by some window of time.
// Populated by the system.
// Read-only.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
// +optional
Status DaemonSetStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
}

Controllers: Making it Kubernetes Native

Operator SDK: Bootstrapping and Building

$ mkdir myproject
$ cd myproject
$ operator-sdk init --domain mydomain.com --group myapp --kind MyApp --version v1alpha1
.
├── Dockerfile
├── Makefile
├── PROJECT
├── bin
├── config
├── go.mod
├── go.sum
├── hack
└── main.go
$ operator-sdk create api \
--group=myapp \
--version=v1alpha1 \
--kind=MyApp \
--resource \
--controller
.
├── Dockerfile
├── Makefile
├── PROJECT
├── api
├── bin
├── config
├── controllers
├── go.mod
├── go.sum
├── hack
└── main.go
$ tree -L 2 apiapi
└── v1alpha1
├── groupversion_info.go
├── myapp_types.go
└── zz_generated.deepcopy.go
$ tree -L 2 controllers
controllers
├── myapp_controller.go
└── suite_test.go
func (r *MyAppReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
_ = context.Background()
_ = r.Log.WithValues("myapp", req.NamespacedName)

// your logic here

return ctrl.Result{}, nil
}

Operator Lifecycle Manager: Publishing Operators

Conclusion

Alexandre Menezes

--

--

--

Leader in #cloud solutions, focused on open source, cloud platforms, networking, and DevOps. Experts in Kubernetes, OpenStack, CloudStack, and more.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Part 5: Hashing with SHA-256

Oracle Virtual Cloud Network — Remote Peering

Real Work vs. Imaginary Work

We are on Medium! 🎉

Object instantiation and permanence in Ruby

1 Page Technical Analysis

The forgotten value of Value Objects

A look at the Optional datatype in Java and some anti-patterns when using it

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
CloudOps

CloudOps

Leader in #cloud solutions, focused on open source, cloud platforms, networking, and DevOps. Experts in Kubernetes, OpenStack, CloudStack, and more.

More from Medium

Kubernetes Job or CronJob: Which One to Use and When?

My Favorite Learning Resources on Docker Container and Kubernetes

Kubernetes State Of The Union — KubeCon 2019, San Diego

Full setup of a Kubernetes K3D cluster managed by Flux on a local Git server

Youtube recording of the live session on the interactive mode