Adding a required field to a live CRD
CRD schema evolution.
don't make it required immediately; add it optional with a default, introduce a new version with conversion, migrate existing objects, then tighten.
What's really being asked
Whether you understand CRD versioning, schema validation against stored objects, and backward-compatible API evolution.
The full answer
The danger is that making a field required in the existing version breaks validation for every already-stored resource that lacks it, and can wedge the controller and updates. The safe path is incremental. First, add the field as optional, and where it has a sensible default, declare a default in the schema so the API server backfills it on read and write, immediately giving existing objects a value without anyone editing them. If you truly need it required, introduce a new CRD version, for example v1beta2 alongside v1beta1, and mark one as the storage version. Provide a conversion strategy, often a conversion webhook, so objects can move between versions, and the field can be required in the new version while optional or defaulted in the old. Then migrate stored objects to the new version, update clients and the controller, and only after everything is on the new version deprecate and stop serving the old one. Throughout, both versions remain served so nothing breaks.
The mistakes people make
Immediately editing the live CRD to mark the field required, which invalidates existing resources; forgetting defaults; or skipping a new version and conversion webhook when a genuinely required field is needed.
What usually comes next
How do storage versions and conversion webhooks work? What is the difference between served and storage versions? How do you migrate existing stored objects?
A concrete example
You need a required region field. You first ship it in v1 as optional with a default of us-east-1, so all existing objects gain a value automatically. Later you add v1beta2 where region is required with no default, set it as storage version with a conversion webhook, migrate objects, point the controller and clients at v1beta2, and finally stop serving the older optional version.
Interview question
Why is directly marking a new field required in a live CRD's existing version dangerous?
- a.Existing stored objects lack the field and would fail validation, breaking updatesCorrect
- b.Required fields are only allowed in the core API group
- c.It silently deletes every existing custom resource
- d.Kubernetes forbids editing any CRD after it is created
Why? this is the answer
Stored resources without the new field would fail the now-stricter schema, wedging updates and the controller. The safe approach is an optional or defaulted field, or a new version with conversion, before requiring it.
Just read this? Test yourself on what you have been reading.
Read the original → kubernetes.io
- #kubernetes
- #crd
- #versioning
- #schema-migration
- #conversion-webhook
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on kubernetes — each one lists the topics its interview covers.
See open roles