Skip to content

Room 44

CUSTOM RESOURCES (CRDS)


The API Smith

  • CRDs let you extend Kubernetes with your own resource types.
  • Create a custom resource and use it to store the escape password.

📜 Mission Briefing

  1. Apply crd.yaml - defines a new resource type EscapeRoom.
  2. Apply escape-room-cr.yaml - creates an instance of the custom resource.
  3. Query it: kubectl get escaperooms.
  4. Describe the custom resource to find the password field.
  5. The password is crdmagic.

Key Commands
Command Purpose
kubectl get crd List all CRDs
kubectl get RESOURCE List custom resources
kubectl describe crd NAME CRD schema
kubectl api-resources See new resource types

How CRDs Work
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: escaperooms.game.k8s.io
spec:
  group: game.k8s.io
  versions:
    - name: v1
      served: true
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                difficulty:
                  type: string
                  enum: ["easy", "medium", "hard"]
                password:
                  type: string
                rooms:
                  type: integer
      additionalPrinterColumns:
        - name: Difficulty
          type: string
          jsonPath: .spec.difficulty
        - name: Rooms
          type: integer
          jsonPath: .spec.rooms
  scope: Namespaced
  names:
    plural: escaperooms
    singular: escaperoom
    kind: EscapeRoom
    shortNames:
      - er
# Custom Resource instance
apiVersion: game.k8s.io/v1
kind: EscapeRoom
metadata:
  name: k8s-challenge
spec:
  difficulty: hard
  password: crdmagic
  rooms: 56
# CRD lifecycle:
# 1. Define the CRD (schema, validation, versions)
# 2. Apply the CRD → new API endpoint registered
# 3. Create instances (custom resources)
# 4. Use kubectl just like built-in resources

# Query custom resources
kubectl get escaperooms
kubectl get er                    # Using shortName
kubectl describe er k8s-challenge
kubectl get er k8s-challenge -o yaml

# CRDs + Controllers = Operators
# CRD defines the "what" (API)
# Controller implements the "how" (reconciliation logic)

Hints

Hint 1

kubectl apply -f crd.yaml
kubectl apply -f escape-room-cr.yaml
kubectl get escaperooms

Hint 2

kubectl get er k8s-challenge -o jsonpath='{.spec.password}'

Hint 3

The password is crdmagic.


🔓 Unlock Room 45

openssl enc -aes-256-cbc -d -a -pbkdf2 \
        -in ../room_45/README -out ../room_45/README.txt -pass pass:PASSWORD
cat ../room_45/README.txt