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

Monitoring your Kubernetes Cluster — Part II

How We Came to the Idea that We Need a DevXP Team at PicsArt

The Escape Button is a Feature

What are Database Migrations?

How I recreate the Jenius App

Monocle: How Chime creates a proactive security & engineering culture (Part 1)

This simple intercom email trick helped us double installations

This week in DevOps #22 — GitOps Issue #4

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

How to Install Mirantis Secure Registry on Rancher

Fixing “current release manifest contains removed kubernetes api(s)”

Otomi Quickstart

Kustomized Helm