0
0
Kubernetesdevops~30 mins

Custom Resource Definitions (CRDs) in Kubernetes - Mini Project: Build & Apply

Choose your learning style9 modes available
Custom Resource Definitions (CRDs) in Kubernetes
📖 Scenario: You are working with Kubernetes and want to extend its capabilities by creating your own custom resource type. This allows you to manage new kinds of objects just like built-in Kubernetes resources.
🎯 Goal: Build a simple Custom Resource Definition (CRD) YAML manifest step-by-step. You will define a new resource called Book with fields for title and author. Then, you will create an instance of this resource and finally display its details using kubectl.
📋 What You'll Learn
Create a CRD YAML manifest with apiVersion, kind, metadata, and spec
Define the Book resource with title and author fields
Create a YAML manifest for a Book instance with specific values
Use kubectl commands to apply and display the custom resource
💡 Why This Matters
🌍 Real World
Custom Resource Definitions let you extend Kubernetes with your own resource types. This is useful when you want Kubernetes to manage new kinds of objects specific to your applications or infrastructure.
💼 Career
Understanding CRDs is important for Kubernetes administrators and DevOps engineers who build custom automation and extend Kubernetes capabilities in real-world cloud environments.
Progress0 / 4 steps
1
Create the Custom Resource Definition (CRD) YAML
Create a YAML manifest called book-crd.yaml that defines a Custom Resource Definition with apiVersion: apiextensions.k8s.io/v1, kind: CustomResourceDefinition, and metadata name books.example.com. In the spec, set group to example.com, versions with name v1, served and storage set to true, and a schema defining title and author as string properties under spec. Set scope to Namespaced and names with plural: books, singular: book, kind: Book, and shortNames: [bk].
Kubernetes
Need a hint?

Remember to follow the Kubernetes CRD structure carefully. Use openAPIV3Schema to define the fields title and author under spec.

2
Create a Book custom resource instance YAML
Create a YAML manifest called mybook.yaml for a Book resource with apiVersion: example.com/v1, kind: Book, metadata name my-first-book, and spec with title: "The DevOps Journey" and author: "Alex Dev".
Kubernetes
Need a hint?

Use three dashes --- to separate the CRD and the resource instance in the same YAML file or create a separate file. Make sure the apiVersion matches the group and version defined in the CRD.

3
Apply the CRD and create the Book resource
Use the kubectl apply -f book-crd.yaml command to create the Custom Resource Definition in your Kubernetes cluster. Then use kubectl apply -f mybook.yaml to create the Book resource instance.
Kubernetes
Need a hint?

Use kubectl apply -f to create or update resources from YAML files.

4
Display the Book resource details
Use the command kubectl get book my-first-book -o yaml to display the details of the Book resource you created.
Kubernetes
Need a hint?

The output should show the full YAML of your Book resource including the spec fields.