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
- Apply
crd.yaml- defines a new resource typeEscapeRoom. - Apply
escape-room-cr.yaml- creates an instance of the custom resource. - Query it:
kubectl get escaperooms. - Describe the custom resource to find the password field.
- 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 3
The password is crdmagic.