






















Kubernetes is incredibly powerful because it provides a rich set of building blocks for running applications. We have Pods, Deployments, Services, Secrets, and more. Think of these as the standard vocabulary that Kubernetes understands right out of the box.
But what happens when this standard vocabulary isn't enough? What if you want to manage a concept that is unique to your application, like a DatabaseBackup, a MlTrainingJob, or a WebsiteCertificate, and treat it as a first-class citizen in your cluster? Shoving complex configuration into a generic ConfigMap feels messy and unintuitive. You want to speak your application's language.
This is exactly why Kubernetes provides Custom Resource Definitions (CRDs). A CRD is a powerful feature that allows you to teach Kubernetes new words, extending its API to understand and manage concepts that are specific to your domain.
In this guide, we'll explain what a CRD is, how it lets you create your own Kubernetes objects, and how it serves as the foundation for the powerful Operator pattern.
Let's start with what Kubernetes already knows. It's like a chef who has a set of well-known, standardized recipes. These are the built-in resources:
These resources are the generic, all-purpose tools that can build almost anything. However, a Deployment object doesn't understand what a "WordPress installation" is; it only understands how to manage a set of identical Pods. You, the human, have to maintain the mental model that connects a specific Deployment, Service, and PersistentVolumeClaim together to form "WordPress."
The Analogy: Imagine you're a building manager using a software system. The system understands Apartments, Tenants, and LeaseAgreements. If the tenants want to start a weekly book club, how do you manage that in the system? You could put a note in a LeaseAgreement's description field, but that's a hack. The system doesn't natively understand what a BookClub is, so it can't manage it intelligently.
A Custom Resource Definition (CRD) is a way to create a brand-new resource type in your Kubernetes cluster. It's the mechanism for extending the Kubernetes API with your own objects.
When you create a CRD, you are effectively telling your Kubernetes cluster's API server:
"Hey, from now on, I want you to recognize a new object
kindcalledBookClub. It should have aspecthat includes fields likemeetingDay,genre, andmemberCount."
Creating a CRD is like adding a new, custom recipe card to the chef's cookbook. The chef now has a formal, structured way to understand and prepare a new dish. In our building manager analogy, it's like adding a new module to the software that natively understands and manages BookClub objects.
Once a CRD is applied to a cluster, the Kubernetes API server dynamically creates a new RESTful API endpoint for that resource type. You can now interact with your new object using kubectl, just like you would with a built-in resource.
It's important to distinguish between two related terms:
So, first you create the BookClub CRD. Then, your tenants can create multiple CRs:
Now, you can manage these objects with familiar commands: kubectl get bookclubs.
So, you've taught Kubernetes a new word. Now what? By itself, a CRD only gives you a way to store and retrieve structured data in the Kubernetes API. This isn't very useful on its own.
The true power of CRDs is unleashed when you pair them with a custom controller. This is the heart of the Operator Pattern.
A custom controller is the active, logical component. It's a program that runs in your cluster and "watches" your custom resources. When you create, update, or delete a CR, the controller notices and takes action. This is the reconciliation loop.
BookClub object was created. I will now book the community room every Wednesday, send an email to the members, and update the building's event calendar."This combination allows you to create powerful, declarative APIs for your own applications, automating complex tasks that would otherwise require manual intervention.
While CRDs are the key to unlocking true cloud-native automation, building the custom controllers that bring them to life is a serious software engineering effort. How can you get the benefits of this powerful pattern without having to build it all yourself?
The Sealos platform and its App Store are built upon the most robust and mature CRDs and Operators in the Kubernetes ecosystem.
PostgresCluster to declaratively manage it.Prometheus and ServiceMonitor CRDs to automate configuration.Sealos provides a simple, graphical interface that allows you to create and manage these powerful Custom Resources without ever writing YAML or understanding the complex controller logic behind them. It effectively democratizes access to the most advanced automation patterns Kubernetes has to offer.
Custom Resource Definitions are a fundamental feature for extending Kubernetes beyond its initial design. They allow you to transform the Kubernetes API into one that understands the specific language of your applications. While a CRD defines the schema for a new object, it's the combination with a custom controller that unlocks true automation, forming the basis of the Operator pattern. This enables a declarative, self-managing system for even the most complex software.
Ready to harness the declarative power of Kubernetes for your own applications without the development overhead? Explore the Sealos App Store and see how custom resources simplify complex application management.
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。