Skip to content
Hands-on IT IT Drills

Day 12: CRDs, Operators and the Interfaces

Goal: You extend the Kubernetes API with your own types, install an operator and find your way around CRI, CNI and CSI on the node. · Duration: approx. 60 min · Prerequisite: Day 11

Briefing

CKA: “Understand CRDs, install and configure operators” and “Understand extension interfaces (CNI, CSI, CRI, etc.)” (part of the 25 %).

  kubelet --CRI--> containerd --> runc          (start containers)
  kubelet --CNI--> Calico                       (Pod network)
  kubelet --CSI--> nfs.csi.k8s.io               (volumes)
  API server + CRD --> new type; operator = controller that implements it
mkdir -p ~/cka/tag12 && cd ~/cka/tag12
k create ns tag12
k config set-context --current --namespace=tag12

Drill 1: A resource type of your own

cat <<'EOF' | k apply -f -
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: backups.lab.example.com
spec:
  group: lab.example.com
  scope: Namespaced
  names:
    plural: backups
    singular: backup
    kind: Backup
    shortNames: ["bk"]
  versions:
  - name: v1
    served: true
    storage: true
    additionalPrinterColumns:
    - name: Schedule
      type: string
      jsonPath: .spec.schedule
    - name: Retention
      type: integer
      jsonPath: .spec.retentionDays
    schema:
      openAPIV3Schema:
        type: object
        properties:
          spec:
            type: object
            required: ["schedule"]
            properties:
              schedule:
                type: string
              retentionDays:
                type: integer
                minimum: 1
                maximum: 365
EOF
k api-resources --api-group=lab.example.com

Expected:

customresourcedefinition.apiextensions.k8s.io/backups.lab.example.com created
NAME      SHORTNAMES   APIVERSION           NAMESPACED   KIND
backups   bk           lab.example.com/v1   true         Backup

The name of a CRD is always <plural>.<group>.

Save your progress? Sign up for free

Drill 2: Objects of the new type

cat <<'EOF' | k apply -f -
apiVersion: lab.example.com/v1
kind: Backup
metadata:
  name: nightly
spec:
  schedule: "0 2 * * *"
  retentionDays: 30
EOF
k get bk
k explain backup.spec

Expected (shortened):

backup.lab.example.com/nightly created
NAME      SCHEDULE    RETENTION
nightly   0 2 * * *   30
GROUP:      lab.example.com
KIND:       Backup
VERSION:    v1
...
FIELDS:
  retentionDays <integer>
  schedule  <string> -required-

The columns come from additionalPrinterColumns, explain from the schema.

Save your progress? Sign up for free

Drill 3: The schema protects you

cat <<'EOF' | k apply -f -
apiVersion: lab.example.com/v1
kind: Backup
metadata:
  name: broken
spec:
  retentionDays: 999
EOF

Expected:

The Backup "broken" is invalid:
* spec.retentionDays: Invalid value: 999: spec.retentionDays in body should be less than
or equal to 365
* spec.schedule: Required value

A CRD only stores data. For a Backup to actually back something up, you would need a controller that watches such objects – an operator.

Save your progress? Sign up for free

Drill 4: Install an operator

cert-manager is a widely used operator: it reads Certificate objects and creates Secrets with certificates from them.

helm install cert-manager oci://quay.io/jetstack/charts/cert-manager --version v1.21.3 \
  -n cert-manager --create-namespace --set crds.enabled=true
k wait -n cert-manager --for=condition=Available deploy --all --timeout=180s
k get crd | grep cert-manager.io

Expected (shortened):

Pulled: quay.io/jetstack/charts/cert-manager:v1.21.3
STATUS: deployed
deployment.apps/cert-manager condition met
deployment.apps/cert-manager-cainjector condition met
deployment.apps/cert-manager-webhook condition met
certificaterequests.cert-manager.io    2026-11-17T22:22:11Z
certificates.cert-manager.io           2026-11-17T22:22:11Z
...
issuers.cert-manager.io                2026-11-17T22:22:11Z

The chart comes from an OCI registry, so no helm repo add is needed.

Save your progress? Sign up for free

Drill 5: Use the operator

cat <<'EOF' | k apply -f -
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
  name: selfsigned
spec:
  selfSigned: {}
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: shop-cert
spec:
  secretName: shop-cert-tls
  dnsNames:
  - shop.lab
  issuerRef:
    name: selfsigned
    kind: Issuer
EOF
k get issuer,certificate
k get secret shop-cert-tls -o jsonpath='{.data.tls\.crt}' | base64 -d \
  | openssl x509 -noout -ext subjectAltName -enddate

Expected:

NAME                                READY   AGE
issuer.cert-manager.io/selfsigned   True    9s

NAME                                    READY   SECRET          AGE
certificate.cert-manager.io/shop-cert   True    shop-cert-tls   9s
X509v3 Subject Alternative Name: critical
    DNS:shop.lab
notAfter=Feb 15 22:22:40 2027 GMT

And the core of every operator – it restores the desired state:

k delete secret shop-cert-tls
k get secret shop-cert-tls

Expected (after a few seconds):

secret "shop-cert-tls" deleted from tag12 namespace
NAME            TYPE                DATA   AGE
shop-cert-tls   kubernetes.io/tls   3      8s

Save your progress? Sign up for free

Drill 6: CRI – containers without kubectl

On worker1. The kubelet talks to containerd over this socket:

sudo grep containerRuntimeEndpoint /var/lib/kubelet/config.yaml
sudo crictl pods --namespace calico-system | head -3
sudo crictl ps --name calico-node
sudo crictl images | grep -E 'pause|nginx'

Expected (shortened):

containerRuntimeEndpoint: unix:///var/run/containerd/containerd.sock
POD ID          CREATED             STATE   NAME                            NAMESPACE
5e0527d980ee1   40 minutes ago      Ready   calico-typha-7d4f7659c4-xbf9k   calico-sy...
2beaedfdaae8f   About an hour ago   Ready   whisker-86cb858779-qmvbx        calico-sy...
CONTAINER           IMAGE               CREATED             STATE     NAME          ...
663954e153291       b424ff80b1e98       About an hour ago   Running   calico-node   ...
docker.io/library/nginx     1.28     fda7399e81045       62.9MB
docker.io/library/nginx     1.29     5dfe511714e1f       63MB
registry.k8s.io/pause       3.10.2   4a83b15d3ecfe       321kB

A container’s logs straight from the runtime – your tool when the API server is dead (Day 14):

sudo crictl logs --tail 2 $(sudo crictl ps --name calico-node -q)

Expected: two log lines from Calico. Kubernetes containers live in containerd in the namespace k8s.io – sudo ctr -n k8s.io containers list shows them as well.

Save your progress? Sign up for free

Drill 7: CNI and CSI on the node

Still on worker1:

sudo ls /etc/cni/net.d
ls /opt/cni/bin | head -8
sudo grep -o '"type":"[a-z-]*"' /etc/cni/net.d/10-calico.conflist | sort -u

Expected:

10-calico.conflist
calico-kubeconfig
LICENSE
README.md
bandwidth
bridge
calico
calico-ipam
dhcp
dummy
"type":"calico"
"type":"calico-ipam"
"type":"portmap"

/etc/cni/net.d says which plugin; /opt/cni/bin holds the programs. If the file is missing, the node stays NotReady.

Back on cp1 – which CSI drivers exist, and which are registered on worker1?

k get csidrivers
k get csinode worker1 -o jsonpath='{.spec.drivers[*].name}{"\n"}'

Expected (shortened):

NAME             ATTACHREQUIRED   PODINFOONMOUNT   ...   MODES        AGE
csi.tigera.io    true             true             ...   Ephemeral    69m
nfs.csi.k8s.io   false            false            ...   Persistent   8m41s
csi.tigera.io nfs.csi.k8s.io

Save your progress? Sign up for free

Exercise: Speed Drills

  1. List all CRDs of the group cert-manager.io. Target time: 15 s
  2. Show which container runtime, including version, each node uses. Target time: 30 s
  3. On worker1, find the ID of the running kube-proxy container. Target time: 30 s

Solution

k get crd -o name | grep cert-manager.io
k get nodes \
  -o custom-columns=NAME:.metadata.name,RUNTIME:.status.nodeInfo.containerRuntimeVersion

On worker1:

sudo crictl ps --name kube-proxy -q

Expected (excerpt):

customresourcedefinition.apiextensions.k8s.io/certificaterequests.cert-manager.io
...
NAME      RUNTIME
cp1       containerd://2.4.2
worker1   containerd://2.4.2
worker2   containerd://2.4.2

Save your progress? Sign up for free

Checkpoint

k get bk nightly -o jsonpath='{.spec.retentionDays}{"\n"}'

Expected: 30

k get certificate shop-cert -o jsonpath='{.status.conditions[0].status}{"\n"}'

Expected: True

Challenge

Use cert-manager to create your own small CA: a self-signed CA certificate lab-ca, on top of it an Issuer of type CA, and with that a certificate for api.lab.

Hint: The CA certificate needs isCA: true; the CA issuer points to its Secret with ca.secretName.

Solution

cat <<'EOF' | k apply -f -
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: lab-ca
spec:
  isCA: true
  commonName: lab-ca
  secretName: lab-ca-tls
  issuerRef:
    name: selfsigned
    kind: Issuer
---
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
  name: lab-ca
spec:
  ca:
    secretName: lab-ca-tls
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: api-cert
spec:
  secretName: api-cert-tls
  dnsNames:
  - api.lab
  issuerRef:
    name: lab-ca
    kind: Issuer
EOF
k get certificate
k get secret api-cert-tls -o jsonpath='{.data.tls\.crt}' | base64 -d \
  | openssl x509 -noout -issuer

Expected:

NAME        READY   SECRET          AGE
api-cert    True    api-cert-tls    5s
lab-ca      True    lab-ca-tls      5s
shop-cert   True    shop-cert-tls   3m
issuer=CN = lab-ca

Clean up (cert-manager stays):

k config set-context --current --namespace=default
k delete ns tag12
k delete crd backups.lab.example.com

Save your progress? Sign up for free

Exam Tip

  • “Install the operator X” usually means: a Helm chart with a given version, then check the CRDs with k get crd and create a sample object.
  • k api-resources --api-group=… and k explain <kind>.spec show how to write an unfamiliar object – faster than any docs.
  • crictl is available on every node: ps, pods, logs, inspect.

Enterprise Note

  • Operators run with broad permissions – read their ClusterRoles before installing.
  • CRDs with multiple versions need conversion webhooks; a CRD upgrade belongs in the maintenance plan.
  • Container runtime, CNI and CSI rarely change, but check the compatibility matrix with every Kubernetes upgrade.