DEV Community

Cover image for Is Kubernetes a database? CRDs explained in five minutes

Is Kubernetes a database? CRDs explained in five minutes

Juraj on May 24, 2024

When you touch on containerized apps today, Kubernetes usually comes up as their orchestrator. Sure, Kubernetes is great for managing your containe...
Collapse
 
romale profile image
Roman

Is there a way to know if values in CRs changed when the controller analyzes them out-of-the-box? For example, do controllers get a list of diffs from the last applied CR or do I need to implement that logic myself?

Great article as always!

Collapse
 
petarcvit profile image
Petar Cvitanović

Controllers leverage the watch mechanism of K8s API and get the whole resource and its updated state. You can use tools like kubebuilder to develop controllers in golang

Collapse
 
romale profile image
Roman

Great, I'll look into that. Thanks!

Collapse
 
edrudo profile image
Edo Duras

Great summary, can you explain what needs to be done for our custom object to be schedulled on some worker node? For example if our apple is actually a service that does something like Cyclops

Collapse
 
petarcvit profile image
Petar Cvitanović

Nice question! But you can't say that an Apple is running on a node.
You can run a pod on a specific node since you will be running pod containers on a node, but, for example, if we are talking about a Kubernetes service, you are not scheduling it on a node. Service is just a resource living in clusters etcd, and other controllers are able to read its configuration and act upon it.
The same thing applies to Apples and other CRDs. You don't schedule a CR to a node, but you can implement a controller around a CRD, which will then create pods and other resources. Scheduling to nodes is specific to pods since they define containers that need to be run on worker nodes.
Another example are Deployments. Deployment configuration is just stored in the etcd and the controller manager will use that configuration to create pods from it, but Deployments are not directly running on worker nodes.

Collapse
 
edrudo profile image
Edo Duras • Edited

In my question a service is something like a API, database (something deployed through a pod)... Maybe I had poor choice of words. Anyway, I think you answered my question, in order to make use of our CRDs we need to have a controller that knows what to do with them

Thread Thread
 
petarcvit profile image
Petar Cvitanović

Exactly, you can store custom resources in your Kubernetes cluster, but you need to implement the logic around it through a controller

Thread Thread
 
edrudo profile image
Edo Duras

Thanks a lot 😄

Collapse
 
jmilic1 profile image
Jura Milić

Very nice observation on how to misuse a feature. I wish more tutorials would tell you outright what use cases to avoid when using a tool.

Can you give a concrete example what would be a good case for CRDs?

Collapse
 
karadza profile image
Juraj

Thanks Jura!

CRDs are great if you want the object to be an abstraction over a collection of resources.

Check out the CRDs we use at Cyclops to understand what it can look like!

Collapse
 
jakepage91 profile image
Jake Page

CRD's aren't that easy to explain, you did a great job here!

Collapse
 
karadza profile image
Juraj

Thanks Jake!
Tried my best 😁

Collapse
 
chorizzard profile image
Domagoj

Great read!

Collapse
 
karadza profile image
Juraj

Thanks Domagoj 🙌

Collapse
 
lmercep profile image
Luka

Very nice explanation of CRDs

Collapse
 
karadza profile image
Juraj

Thanks Luka 🫶

Collapse
 
fernandezbaptiste profile image
Bap

Great write-up! 🙂

Collapse
 
karadza profile image
Juraj

Thanks Bap 🙏

Collapse
 
matijasrbic profile image
MatijaSrbic

Another great blog from the Cyclops team. Keep them coming!

Collapse
 
karadza profile image
Juraj

Glad you enjoy them! 🙌