Hi everyone! I'm back and I want to share some great news - Part 2 of the article series about k8s resource operators is now written and you'll start reading it in a few seconds. For those who landed directly on Part 2, I suggest you check out the first part, where, by the way, there's my plan that I'm trying to follow 😄

I want to mention that I didn't choose this topic by chance. Of course, it's related to my work, but really, it's about something more than just development. Over the last year, Platform Engineering has been gaining popularity, which involves designing and developing internal company systems for quick management of project infrastructure in clouds without extensive DevOps knowledge (Internal Developer Platform).

I believe that in 2-3 years, the market will need such narrowly-focused specialists, so take a closer look at this direction.

Introduction

In Part 1, we explored the theoretical aspects of working with Kubernetes operators and understood their importance in modern development. Now it's time to move on to the practical part and create our own operator using Operator SDK and the Go programming language. Let's go through the development process step by step, from setting up the development environment to the final deployment of our operator into the cluster. We won't focus too much on secondary actions. I expect you to have some background in Go and practical development in general.

We'll pay special attention to creating a Custom Resource Definition (CRD) and implementing a controller that will monitor and respond to changes in our custom resources. During development, we'll look at the main patterns and best practices used in creating operators. We'll also examine in detail the project structure and core components necessary for successful operator functioning. We'll learn how to properly handle cluster events and respond to them accordingly.

We'll separately cover testing our operator and debugging its operation in Part 3 of this series.

An important aspect will be reviewing error handling mechanisms and recovery after failures. Finally, we'll discuss possible use cases for the created operator and prospects for its further development. The entire process will be accompanied by practical examples and detailed explanations. This hands-on experience will help you better understand the internal workings of Kubernetes operators and prepare you for creating your own solutions for automating resource management in the cluster.

Source code

All code related to the practical part can be found on our Github:

https://github.com/uagolang/k8s-operator

So, let's finally try all this in practice. First, let's define the tasks that we need to solve using the CRD controller.

Example: Automating Valkey (Open-Source Redis) Management in Kubernetes

You might not know, but Redis has become paid. Valkey is its open-source alternative.

Problem

In many companies, developers face the challenge of manually configuring infrastructure when deploying new development or testing environments. Let's imagine we work in such a company and we've been tasked with automating this process. Based on our task, the following problems typically arise: