kubectl get washowed only NAME and AGE.kubectl scale wafailed.- A regular
kubectl applycould overwrite.statusbecause the API server wasn’t preventing writes to it.
- Enable the
statussubresource so only the/statusendpoint (typically controllers) can update.status. - Enable the
scalesubresource sokubectl scaleand HPAs can target the CR. - Add
additionalPrinterColumnssokubectl get washows meaningful columns. - Add
categories: [all]so tools that honor categories treat your CR as a top-level workload.
Quick overview: What each CRD field does
Step 1 — Teach the schema about .status and tighten .spec validation
Add a status object to the OpenAPI schema so the API server does not prune it. Also make spec validation explicit (required fields, types and ranges):
- The API server preserves
.status(it won’t be removed by pruning). - Clients get clear validation errors for missing or invalid
specfields.
Step 2 — Enable /status and add the scale subresource
Turn on the /status endpoint by adding an empty status: {} under subresources. Add the scale block and point it to the JSONPaths for desired and observed replicas and for the label selector:
kubectl scale wa <name> --replicas=<n>is routed to the scale subresource and updates.spec.replicas.- HorizontalPodAutoscalers (HPAs) that target this resource can read replicas and update the scale endpoint.
Enabling the
status subresource prevents ordinary apply/update requests from modifying .status. Only the /status endpoint (used by controllers) may change status fields.Step 3 — Add additional printer columns for kubectl get
Define columns so kubectl get wa displays useful information. Each column needs name, type, and a jsonPath. Use priority: 1 to hide less important columns unless -o wide is requested:
kubectl get wa feel like a native resource listing (Image, Replicas, Ready, Port, Age).
Step 4 — Add categories: [all]
Add categories: [all] under spec.names so tools that respect categories (and kubectl api-resources --categories=all) include the resource among top-level workload types:
kubectl get all is a hard-coded convenience command and will not list CRDs even if they declare categories: [all]. The category is still useful for other tooling and kubectl api-resources --categories=all.
kubectl get all will not list your CRs even if categories: [all] is set. Use kubectl api-resources --categories=all or kubectl get webapps / kubectl get wa to view your resources.Final consolidated CRD (relevant fragments)
Below is a consolidated view showing the key fields you should include. Fill in the remaining CRD metadata as appropriate for your project.Apply the CRD
No API server restart is required — changes to CRDs are picked up immediately.kubectl get wawill show the extra columns you defined. (TheImagecolumn may be hidden unless you use-o widebecause it haspriority: 1.)kubectl scale wa <name> --replicas=<n>updates.spec.replicasvia the scale subresource.- Regular
kubectl apply/kubectl updateattempts that include.statuswill see.statusfields dropped — only/statusupdates persist status.
Validate category registration
Summary
By adding these CRD fields:schemaforstatusandspecvalidationsubresources.statussubresources.scaleadditionalPrinterColumnsnames.categories: [all]
- Kubebuilder can generate these CRD fields automatically from Go marker comments on your types.