Profile picture
Sidharth R
  • Home
  • Posts
  • Journal
  • Labs
  • Home
  • Posts
  • Journal
  • Search
  1. Home
  2. Labs
  3. Kubernetes labs
  4. Custom Resource Definition

Custom Resource Definition

Task 1

CRD objects can be either namespaced or cluster-scoped.

Is this statement true or false?

Answer: True

Task 2

What is a custom resource?

Answer: A custom resource is an extension of the Kubernetes API that is not necessarily available in a default Kubernetes installation.

Task 3

We have provided an incomplete Custom Resource Definition (CRD) manifest located at /root/crd.yaml. Complete the file to define a namespaced CRD named internals.datasets.kodekloud.com.

Requirements:

  • Group: datasets.kodekloud.com
  • Scope: Namespaced
  • Version: v1
  • served: true
  • storage: true

Include the following OpenAPI v3 schema fields under spec:

FieldType
internalLoadstring
rangeinteger
percentagestring

After creating the CRD, use the provided /root/custom.yaml file to create a custom resource.

Solution

Step 1: Complete the CRD Manifest

crd.yaml
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: internals.datasets.kodekloud.com
spec:
  group: datasets.kodekloud.com
  versions:
    - name: v1
      served: true
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                internalLoad:
                  type: string
                range:
                  type: integer
                percentage:
                  type: string
  scope: Namespaced
  names:
    plural: internals
    singular: internal
    kind: Internal
    shortNames:
      - int

Step 2: Create the CRD

Create CRD
$ k apply -f crd.yaml

customresourcedefinition.apiextensions.k8s.io/internals.datasets.kodekloud.com created

Step 3: Create the Custom Resource

Show custom.yaml
custom.yaml
kind: Internal
apiVersion: datasets.kodekloud.com/v1
metadata:
  name: internal-space
  namespace: default
spec:
  internalLoad: "high"
  range: 80
  percentage: "50"

Create custom resource using k create -f custom.yaml.

Task 4

What are the properties defined in the CRD collectors.monitoring.controller?

Inspect the CRD using k describe crd collectors.monitoring.controller.

Relevant section:

YAML
Spec:
  ...
  Versions:
    Name: v1
    Schema:
      openAPIV3Schema:
        Properties:
          Spec:
            Properties:
              Image:
                Type: string
              Name:
                Type: string
              Replicas:
                Type: integer

Answer: image, name, replicas

Task 5

Create a custom resource instance named datacenter using the existing CRD with:

  • apiVersion: traffic.controller/v1
  • kind: Global

Set the following values under spec:

YAML
dataField: 2
access: true

Solution

datacenter-cr.yaml
kind: Global
apiVersion: traffic.controller/v1
metadata:
  name: datacenter
spec:
  dataField: 2
  access: true

To create the resource you can use k apply -f datacenter-cr.yaml.

Task 6

What is the short name assigned to the CRD globals.traffic.controller?

To inspect CRD, you can run: k describe crd globals.traffic.controller.

Relevant section:

YAML
Names:
  Kind: Global
  List Kind: GlobalList
  Plural: globals
  Short Names:
    gb
  Singular: global

Answer: gb

Nerdsid.com

Links
  • Home
  • Contact
  • About
  • Posts
  • Journal
  • Quotes
  • Links worth your time
  • Notes
  • Style guide
© 2026 Sidharth R.
All content on this website is licensed under CC BY-NC-SA 4.0.