In Kubernetes, Custom Resource Definitions (CRDs) extend the API by allowing you to define custom object kinds beyond the built-in Pods, Services, or Deployments. A CRD acts as a schema that tells the API Server how to handle valid data for this new resource type, storing its state in etcd. However…In Kubernetes, Custom Resource Definitions (CRDs) extend the API by allowing you to define custom object kinds beyond the built-in Pods, Services, or Deployments. A CRD acts as a schema that tells the API Server how to handle valid data for this new resource type, storing its state in etcd. However, the CRD is just data; it possesses no logic to modify the system state.
To manage these custom resources, we use Operators. An Operator is a pattern that combines CRDs with a custom Controller. The Controller watches the CRD objects and executes the 'operational logic' (reconciliation loop) to ensure the actual state of the cluster matches the desired state defined in the resource. This effectively codifies human operational knowledge—such as how to back up a database or upgrade a cluster—into software.
To install an Operator, you typically follow two steps:
1. Apply the CRD manifest (`kubectl apply -f crd.yaml`) to register the new API endpoints.
2. Deploy the Operator logic, usually as a Pod via a Deployment, along with the necessary ServiceAccount and RBAC ClusterRoles to allow it to modify resources.
For the CKA exam, you generally do not need to write an operator from scratch. However, you must know how to inspect existing ones using `kubectl get crds`, `kubectl describe crd <name>`, and `kubectl get <custom-resource-name>`. You should understand that deleting a CRD will delete all instances of that custom resource, and if an Operator pod fails, the custom resources remain in the database but will stop reconciling until the Operator is fixed.
Understand CRDs, Install and Configure Operators
Why is it Important? Kubernetes is designed to be highly extensible. While standard resources like Pods, Deployments, and Services cover many use cases, complex stateful applications (like databases or monitoring stacks) often require domain-specific logic to manage their lifecycle. Custom Resource Definitions (CRDs) allow you to extend the Kubernetes API to store custom data, while Operators use that data to automate complex tasks—effectively putting the skills of a human administrator into software.
What is it? There are two main components: 1. Custom Resource Definition (CRD): This defines the schema of a new object type. It tells the API server: "I want to create a new type of resource called Database." It does not do anything by itself; it simply allows the cluster to accept and store the YAML for that new resource. 2. Operator (Custom Controller): This is a program (usually running as a Pod) that watches for the creation or modification of Custom Resources. When it sees a CR, it acts to bring the cluster state into alignment with the user's intent (e.g., spinning up Pods, configuring replication, or performing backups).
How it Works The workflow follows the standard Kubernetes control loop: 1. An administrator applies a CRD YAML file to the cluster. The API Server now recognizes the new resource type. 2. An Operator (Controller) is deployed (usually via a Deployment) and starts watching the API for specific resource events. 3. A user creates a Custom Resource (CR) instance (e.g., kind: Prometheus). 4. The Operator detects the new CR and executes logic (reconciliation) to create the necessary native resources (Pods, ConfigMaps, Services) required to fulfill the request.
How to Answer Questions in the Exam In the Certified Kubernetes Administrator (CKA) exam, you are not expected to write Operator code (Go/Python). However, you must understand how to interact with them: 1. Inspecting CRDs: You may be asked to identify existing custom resources. Use kubectl get crd to list them and kubectl get <crd-name> to list instances of that resource. 2. Creating Resources: You might be provided with a CRD and asked to create a Custom Resource object based on it. You will usually need to look at a provided sample or use kubectl explain to find the correct fields. 3. Troubleshooting: If a Custom Resource is created but nothing happens (e.g., no Pods appear), you must know to check the logs of the Operator/Controller Pod to find errors.
Exam Tips: Answering Questions on Understand CRDs, install and configure operators Tip 1: Discovery. If you see a resource type in a question that you don't recognize (e.g., EtcdCluster or BackupTask), run kubectl get crd immediately to confirm it is a custom extension. Tip 2: Structure. Use kubectl explain <resource_name> --recursive to view the nested structure of a Custom Resource. This helps when writing the YAML manifest if the documentation is sparse. Tip 3: Namespaces. CRDs themselves are cluster-scoped (global), but the Custom Resource instances you create are usually namespaced. Ensure you create the CR in the requested namespace. Tip 4: Cleanup. If asked to remove an operator, remember that deleting the CRD will usually delete all instances (CRs) of that resource automatically. Be careful not to delete a CRD unless explicitly instructed.