Writing your own Kubernetes operator and CRD in Python with kopf to enhance and harden your Kubernetes clusters

Yashvardhan Kukreja (~yashvardhan)


Kubernetes and Operators

Kubernetes is an extremely mature container orchestration technology which helps you schedule and automate your containerized workloads/applications with reliability and convenience. One of the strongest points fuelling its prevalence is the pluggability it gives to its users meaning that it is flexible enough to allow the users to install or even develop these add-ons, called operators and CRDs (Custom Resource Definitions), over their clusters which can provide a limitlessly wide range of custom functionalities which might not be available to native Kubernetes itself.

Why being able to write your own Kubernetes Operators is so cool

As per my experience with dealing with Kubernetes clusters in contexts of extremely large-scale applications (serving 10 million+ users), I have come to realise that the Kubernetes's support to write your own operators and resources (CRDs) is an extremely useful utility to exist. That's clearly because of the fact that no matter what organization you are in, if you are operating at large scale with Kubernetes, you would end up requiring some custom functionality out of Kubernetes which is not natively present in it.

That even proves why Kubernetes Operator/CRD development is one of the most sought-after skill majorly for any company making use of Kubernetes as a part of their infrastructure.

Motivation behind making use of kopf to write your own Kubernetes Operators

Unfortunately, writing Kubernetes operators in GoLang is a little complex despite having projects like kubebuilder which are meant to save time from writing the boilerplate code involved.

But well, as usual, Python comes to the rescue to ease our lives with another great framework called kopf to help us write our own Kubernetes Operators with utter ease. No massive chunks of boiler plate code, no package/module hell inside your project, just a simple Python file to write, run and deploy your Kubernetes Operator and make use of it.

Structure of the talk

  • My introduction and a basic primer on Containers and Kubernetes ~ 3-4 minutes
  • What operators and CRDs are, how do they work and why are they so cool ~ 5 minutes
  • Writing and running a toy operator using kopf ~ 15 minutes
  • End note ~ 1-2 minutes


The pre-requisites expected out of the viewers are straightforward and simple instead of possessing any advanced knowledge.

The viewers should have:

  • A basic theoretical idea about Docker and containers.
  • A simple idea about what Kubernetes is and basic terminologies around it like Pod, Deployment, Control Plane, etc.
  • An idea about how to write "Hello, World!" in Python :)

Speaker Info:

I am Yashvardhan and I am currently working as a Software Engineer at Grofers as part of the Infrastructure and DevOps team. I am also a Linux Foundation's CNCF Mentee for Kyverno which is a Kubernetes-native policy management engine and a CNCF Sandbox project. I love to contribute to cloud-native and Kubernetes-native OSS projects. And well, as you can sense it by now, my passion lies in the field of Distributed systems and Cloud. Apart from that, I love to impart knowledge by writing tech blogs (on medium :)) whenever I encounter a cool piece of tech or a project as sharing knowledge is one of my favourite things to do.

And well, to break the monotony around the entire space of programming, I love to run, do long-distance cycle rides (probably Randonneuring someday :') ) and read about Astrophysics.

Speaker Links:

You can catch up with me on any of these platforms:

  • Github - https://github.com/yashvardhan-kukreja
  • Twitter - https://twitter.com/yashkukreja98
  • Medium - https://yash-kukreja-98.medium.com/
  • LinkedIn - https://www.linkedin.com/in/yashvardhan-kukreja

Personal website - https://www.yashkukreja.com

Section: Developer tools and automation
Type: Talks
Target Audience: Intermediate
Last Updated: