Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Working with Kubernetes Custom Resources
📖 Scenario: You are managing a Kubernetes cluster and want to extend its functionality by creating a custom resource to track application versions.
🎯 Goal: Learn how to define a Custom Resource Definition (CRD), create a custom resource, and view its details using kubectl commands.
📋 What You'll Learn
Create a Custom Resource Definition YAML file named appversion-crd.yaml with specified fields
Create a custom resource YAML file named myapp-v1.yaml using the CRD
Use kubectl commands to apply and view the custom resource
💡 Why This Matters
🌍 Real World
Kubernetes Custom Resources let you add your own resource types to the cluster. This is useful for managing specialized application data or configurations beyond built-in Kubernetes objects.
💼 Career
Understanding custom resources is important for Kubernetes administrators and DevOps engineers who want to extend Kubernetes capabilities or build operators.
Progress0 / 4 steps
1
Create the Custom Resource Definition YAML
Create a file named appversion-crd.yaml with a CustomResourceDefinition named appversions.example.com in the apiextensions.k8s.io/v1 API group. The CRD should define a spec with group as example.com, versions with a single version named v1 that is served and stored, and a scope of Namespaced. The names section should specify plural as appversions, singular as appversion, kind as AppVersion, and shortNames as av. Include an openAPIV3Schema with a spec containing a version field of type string.
Kubernetes
Hint
Remember to follow the Kubernetes CRD structure carefully and indent YAML properly.
2
Create a Custom Resource YAML
Create a file named myapp-v1.yaml that defines a custom resource of kind AppVersion in the example.com/v1 API version. Set the metadata.name to myapp-v1 and the spec.version to 1.0.0.
Kubernetes
Hint
Use the correct API version and kind matching the CRD you created.
3
Apply the CRD and Custom Resource
Use kubectl apply -f appversion-crd.yaml to create the CustomResourceDefinition, then use kubectl apply -f myapp-v1.yaml to create the custom resource.
Kubernetes
Hint
Use the exact kubectl commands to apply both YAML files.
4
View the Custom Resource Details
Run kubectl get appversions to list the custom resources, then run kubectl get appversion myapp-v1 -o yaml to see the details of the myapp-v1 resource.
Kubernetes
Hint
First list all appversions, then describe the specific one in YAML format.
Practice
(1/5)
1. What is the main purpose of a Custom Resource in Kubernetes?
easy
A. To delete all existing Kubernetes resources
B. To replace built-in Kubernetes objects like Pods
C. To automatically update Kubernetes itself
D. To add new object types to Kubernetes for custom app needs
Solution
Step 1: Understand Kubernetes object types
Kubernetes has built-in objects like Pods and Services, but sometimes you need new types for your apps.
Step 2: Role of Custom Resources
Custom Resources let you define new object types to extend Kubernetes capabilities without changing its core.
Final Answer:
To add new object types to Kubernetes for custom app needs -> Option D
Quick Check:
Custom Resources extend Kubernetes = A [OK]
Hint: Custom Resources add new types, not replace or delete [OK]
A. It controls the storage backend for the resource
B. It defines the kind name used when creating custom resource objects
C. It sets the namespace where the resource lives
D. It specifies the API version of the custom resource
Solution
Step 1: Understand spec.names.kind role
This field sets the kind name you use in YAML when creating instances of this custom resource.
Step 2: Differentiate from other fields
API version is under versions.name, scope is separate, storage backend is not set here.
Final Answer:
It defines the kind name used when creating custom resource objects -> Option B
Quick Check:
spec.names.kind = kind name for objects [OK]
Hint: spec.names.kind is the object kind name in YAML [OK]
Common Mistakes:
Confusing kind with API version
Thinking it sets namespace or storage
Mixing plural and kind meanings
4. You applied a CustomResourceDefinition YAML but get an error: error: unable to recognize "crd.yaml": no matches for kind "CustomResourceDefinition" in version "v1beta1". What is the likely cause?
medium
A. Missing metadata.name field in the YAML
B. Trying to create a Pod instead of a CustomResourceDefinition
C. Using deprecated API version v1beta1 instead of apiextensions.k8s.io/v1
D. Incorrect indentation in the YAML file
Solution
Step 1: Analyze the error message
The error says no matches for kind "CustomResourceDefinition" in version "v1beta1" which means the API version is not supported.
Step 2: Check Kubernetes API version support
Since Kubernetes 1.22+, the v1beta1 version for CustomResourceDefinition is removed; use apiextensions.k8s.io/v1 instead.
Final Answer:
Using deprecated API version v1beta1 instead of apiextensions.k8s.io/v1 -> Option C
Quick Check:
Deprecated API version causes no match error [OK]
Hint: Use apiextensions.k8s.io/v1 for CRD, not v1beta1 [OK]
Common Mistakes:
Ignoring API version deprecation
Assuming missing metadata causes this error
Blaming YAML indentation without checking version
5. You want to create a custom resource named Gadget with group devices.example.com and version v1. Which is the correct minimal spec section of the CustomResourceDefinition YAML?