Lab: Custom Resource Definition
Introduction:
A custom resource is an extension of the Kubernetes API that is not necessarily available in a
default Kubernetes installation. It represents a customization of a particular Kubernetes
installation. However, many core Kubernetes functions are now built using custom resources,
making Kubernetes more modular.
In this lab, you will learn:
• Creating Custom Resource Definition (CRDs)
• Creating Object using CRDS
• Cleanup
Note: Ensure you have running cluster deployed
1. Ensure that you have logged-in as root user with password as linux on kube-master node.
a. Creating a custom resource definition
To create custom objects, you must first create a custom resource definition (CRD).
1.1 Let us clone the git repository which contains manifests required for this exercise, by executing the
below command.
# git clone [Link]
Output:
Student Material – Do Not Re-distribute. For any queries contact:
[Link]@[Link] or [Link]
1.2 Let us view the manifest, by executing the below command.
# cat -n ~/k8s-crds/[Link]
Output:
Student Material – Do Not Re-distribute. For any queries contact:
[Link]@[Link] or [Link]
1.3 Let us create new namespace called custom-objects, by executing the below command.
# kubectl create namespace custom-objects
Output:
1.4 Let create the CRD, by executing the below command.
# kubectl apply -f ~/k8s-crds/[Link] -n custom-objects
Output:
1.5 Let us verify the custom object in api-resources
# kubectl api-resources | grep -i crontabs
Output:
1.6 Let us view a custom object manifest, by executing the below command.
# cat -n ~/k8s-crds/[Link]
Output:
1.7 Let us create the custom object, by executing the below command.
# kubectl apply -f ~/k8s-crds/[Link] -n custom-objects
Output:
Student Material – Do Not Re-distribute. For any queries contact:
[Link]@[Link] or [Link]
1.8 Let us verify the newly created object, by executing the below command.
# kubectl get crontab -n custom-objects
Output:
1.9 You can also view the raw YAML data for a custom resource:
# kubectl get ct -o yaml -n custom-objects
Output:
Student Material – Do Not Re-distribute. For any queries contact:
[Link]@[Link] or [Link]
1.10 Let us describe the custom object, by executing the below command.
# kubectl describe ct -n custom-objects
Output:
1.11 Let us cleanup, by executing the below command.
# kubectl delete -f ~/k8s-crds/[Link]
Output:
1.12 Let us verify the custom object in api-resources
# kubectl api-resources | grep -i crontabs
Student Material – Do Not Re-distribute. For any queries contact:
[Link]@[Link] or [Link]