What if you could teach Kubernetes to understand and manage anything you want, just like its built-in parts?
Why Custom resources concept in Kubernetes? - Purpose & Use Cases
Start learning this pattern below
Jump into concepts and practice - no test required
Imagine you want to manage a new type of application setting in Kubernetes that is not supported by default. You try to track these settings outside Kubernetes, using spreadsheets or separate scripts.
This manual tracking is slow and error-prone. You must constantly update external files and run scripts, risking mismatches and forgotten changes. It's hard to keep everything in sync with your cluster state.
Custom resources let you extend Kubernetes with your own resource types. You can define and manage your new settings directly inside Kubernetes, just like built-in resources, making everything consistent and automated.
Track settings in a spreadsheet and run separate scripts to apply changes.
kubectl apply -f my-custom-resource.yaml
It enables you to manage any kind of configuration or application state natively within Kubernetes, making automation and scaling much easier.
A team creates a custom resource to manage database backup schedules, so they can control backups declaratively and monitor them with Kubernetes tools.
Manual tracking outside Kubernetes is slow and risky.
Custom resources let you add new resource types inside Kubernetes.
This makes management consistent, automated, and scalable.
Practice
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 DQuick Check:
Custom Resources extend Kubernetes = A [OK]
- Thinking Custom Resources replace built-in objects
- Believing Custom Resources update Kubernetes itself
- Confusing Custom Resources with deleting resources
Solution
Step 1: Identify the YAML kind for custom types
Custom Resource types are defined by a special Kubernetes object called CustomResourceDefinition.Step 2: Differentiate from common kinds
Pod, Deployment, and Service are built-in kinds, not for defining new types.Final Answer:
CustomResourceDefinition -> Option AQuick Check:
CustomResourceDefinition defines new types [OK]
- Choosing Pod or Deployment as custom type definition
- Confusing Service with CustomResourceDefinition
- Using incorrect kind names in YAML
spec.names.kind used for?
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: widgets.example.com
spec:
group: example.com
versions:
- name: v1
served: true
storage: true
scope: Namespaced
names:
plural: widgets
singular: widget
kind: Widget
shortNames:
- wdg
Solution
Step 1: Understand
This field sets the kind name you use in YAML when creating instances of this custom resource.spec.names.kindroleStep 2: Differentiate from other fields
API version is underversions.name, scope is separate, storage backend is not set here.Final Answer:
It defines the kind name used when creating custom resource objects -> Option BQuick Check:
spec.names.kind= kind name for objects [OK]
spec.names.kind is the object kind name in YAML [OK]- Confusing kind with API version
- Thinking it sets namespace or storage
- Mixing plural and kind meanings
error: unable to recognize "crd.yaml": no matches for kind "CustomResourceDefinition" in version "v1beta1". What is the likely cause?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 CQuick Check:
Deprecated API version causes no match error [OK]
- Ignoring API version deprecation
- Assuming missing metadata causes this error
- Blaming YAML indentation without checking version
Gadget with group devices.example.com and version v1. Which is the correct minimal spec section of the CustomResourceDefinition YAML?Solution
Step 1: Check group and version correctness
The group must be devices.example.com and version v1 served and storage true.Step 2: Validate scope and names
Scope should be Namespaced (common default), and names must include plural, singular, and kind Gadget.Step 3: Eliminate wrong options
group: devices.example.com version: v1 scope: Cluster names: plural: gadgets kind: Gadget uses singular version field and Cluster scope, apiVersion: v1 group: devices.example.com versions: - name: v1 served: false storage: true scope: Namespaced names: plural: gadgets kind: Gadget has served false, group: devices.example.com versions: - name: v2 served: true storage: true scope: Namespaced names: plural: gadgets singular: gadget kind: Gadget uses version v2 instead of v1.Final Answer:
group: devices.example.com versions: - name: v1 served: true storage: true scope: Namespaced names: plural: gadgets singular: gadget kind: Gadget -> Option AQuick Check:
Correct group, version, scope, and names = A [OK]
- Using version instead of versions list
- Setting served: false disables API
- Mismatching version name or group
- Omitting singular name
