Practice Test - Custom Resource Definition -Solutions

Hi
Im trying to complete practice test for Custom Resource Definition in the CKAD course. Im getting an error. Please help details below

Modified CRD definition

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: internals.datasets.kodekloud.com
spec:
  group: datasets.kodekloud.com
  versions:
    - name: v1
      served: false
      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

I created the resource successfully.
controlplane ~ âžś k apply -f crd.yaml
customresourcedefinition.apiextensions.k8s.io/internals.datasets.kodekloud.com created

when I do “k api-resources” command I dont see a CRD internal created in the list. But when I do “k get crds” - I can see

controlplane ~ :heavy_multiplication_x: k get crd
NAME CREATED AT
collectors.monitoring.controller 2024-10-05T13:10:45Z
globals.traffic.controller 2024-10-05T13:10:46Z
internals.datasets.kodekloud.com 2024-10-05T13:38:12Z

When I ran the provided custom.yaml file (in root dir) I get this below error

controlplane ~ âžś k apply -f custom.yaml
error: resource mapping not found for name: “internal-space” namespace: “default” from “custom.yaml”: no matches for kind “Internal” in version “datasets.kodekloud.com/v1”
ensure CRDs are installed first

Thanks

controlplane $ k explain crd.spec.versions.served
GROUP:      apiextensions.k8s.io
KIND:       CustomResourceDefinition
VERSION:    v1

FIELD: served <boolean>


DESCRIPTION:
    served is a flag enabling/disabling this version from being served via REST
    APIs

When you enable it to be served then it will show up in kubectl api-resources, and you will be able to create things with it.

1 Like

Thanks a lot Alistair