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: truestorage: true
Include the following OpenAPI v3 schema fields under spec:
| Field | Type |
|---|---|
| internalLoad | string |
| range | integer |
| percentage | string |
After creating the CRD, use the provided /root/custom.yaml file to create a custom resource.
Solution
Step 1: Complete the CRD Manifest
---
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:
- intStep 2: Create the CRD
$ k apply -f crd.yaml
customresourcedefinition.apiextensions.k8s.io/internals.datasets.kodekloud.com createdStep 3: Create the Custom Resource
Show 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:
Spec:
...
Versions:
Name: v1
Schema:
openAPIV3Schema:
Properties:
Spec:
Properties:
Image:
Type: string
Name:
Type: string
Replicas:
Type: integerAnswer: image, name, replicas
Task 5
Create a custom resource instance named datacenter using the existing CRD with:
apiVersion: traffic.controller/v1kind: Global
Set the following values under spec:
dataField: 2
access: trueSolution
kind: Global
apiVersion: traffic.controller/v1
metadata:
name: datacenter
spec:
dataField: 2
access: trueTo 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:
Names:
Kind: Global
List Kind: GlobalList
Plural: globals
Short Names:
gb
Singular: globalAnswer: gb
