What is Kubernetes CRD?
CRD in Kubernetes stands for Custom Resource Definition, which allows us to create custom objects in the Kubernetes. By the help of this, we can easily create custom resource or object inside the Kubernetes cluster, and it can be used like normal or native Kubernetes object already available. This concept of CRD is introduced in Kubernetes 1.7, this is useful when we want to add our own created object inside the Kubernetes cluster to full fill or meet the requirement. This allows us to use all the features and functionality available in Kubernetes, in this article we will see how we can create a register our custom object in Kubernetes, with detailed explanation and its internal working as well for better clarity and understanding for beginners.
Use a custom resource
As we have already discussed that CRD is used to create the custom resource, which adds so many users to us, out of which few are mentioned below:
1) To run CRDs we do not require any additional server; it can be handle independently by the API.
2) Also it is written in any language, users or we do not need to worry about the programming.
3) Once the CRD is created then no ongoing support. I any big comes then it will be picked as the Kubernetes master upgrade.
4) By the use of this we do not require to maintain the multiple version for our API, it is easy to use.
5)It is the best to fit when we are using this resource within or inside our company, or as a part of a small open source project.
All considering all the above points we can decide when to for CRD in Kubernetes, all the points will help us to figure it out easily.
Adding Kubernetes CRD
In Kubernetes, we have two ways of creating custom resources. Let’s discuss each of them in detail for better clarity see below;
1) One way to make use of CRDs this can be created normally without programming.
2) Second way we have is API Aggregation, but to use this it requires programming and gives us more control over the API creation and behaviour, that how the data will be store, and how the conversion will happen among the different versions of the API, etc.
CRD: Custom Recourse Definition, this API allows us to create our custom resources. It will create the new custom resources for us based on the schema and name we have provided. As far as storage is concerned that is managed and handle by the Kubernetes servers. So this is one of the methods to create the custom resources, inside the Kubernetes cluster without much programming needed.
Types Kubernetes CRD
If we talk about the types there is no such type for specific CRD, but we have types of custom resources in Kubernetes. It provides us two ways by which we can easily create the custom resource in the Kubernetes cluster, let’s take a closer look at both of them in detail see below;
1) CRD that is custom resource definition: This is one of the forms of creating custom resources in Kubernetes, and to create this we don’t require to have programming knowledge. We can create the CRD, delete it, etc. To create it we follow the .yaml structure definition and few commands.
2) API Aggregation: this is also one of the forms of custom resource creation in Kubernetes, but this requires programming knowledge. It is a bit hard to manage etc.
These two points we have already seen in the previous section of the article and here we are talking more about eh custom resource definition, API aggregation we will see and discuss in the next article.
Creating an object Kubernetes CRD and Kubernetes CRD example
To create the Kubernetes CRD we have to follow the standard .yml file which will help us to create the CRD for us, this is standard and should be the same with few minor changes, let’s get started to create the CRD in Kubernetes see below;
- name: v1
Now we will have to look at each of the lines to understanding this .yml file definition in detail;
a) In the first 2 lines of the yml file we are trying to tell them we are creating a custom resource definition; ‘metadata’ is the key which helps to define the name for our CRD.
b) we have defined the name under ‘names’ and ‘plural’.
c) Now we can define the group name for the CRD, here we are using the ‘Spec’ property to define it. Under the ‘Spec’ we are using ‘group’ property to define it.
d) Now we can use the ‘version’ property to define the version for custom resource definition. ‘versions’ comes under ‘Spec’ property itself, and defining ‘v1’. Also made the ‘storage’ key as ‘true’ which means this version will be our storage version for this.
e) After this we have set the scope as well.
f) And then defined the ‘plural’ and ‘singular’ name for our custom resource definition as well.
g) It also gives us the provision to define the ‘shortNames’ and ‘kind’ names for our CRD, then we can use the below command to create it,
kubectl create -f crd.yaml
f) After this all we can now found the API endpoint for our CRD at the below syntax followed by the name and configuration as per your CRD file see below for better clarity:
/group name / version/namespaced/*/crd_name
Now to use the above CRD we have to manifest it using the below .yml file definition ;
apiVersion: "we can give api version"
kind: ann=me of crd
name: this name
uri: "your uri"
Command: “command if any”
In this way, we can create and use the CRD in Kubernetes, follow both these .yml files to start with it.
So far we have learned the creation of Custom Resource Definition, and add them inside the Kubernetes cluster and use all the functionality provided by them. all this can be done vis command-line interface or google client. It is easy to use, handle, and maintained by the developers. o to the full article to understand it better.
This is a guide to Kubernetes CRD. Here we discuss What is Kubernetes CRD, Use a custom resource, type with command. You may also have a look at the following articles to learn more –