{"id":"4ce582a3-8f71-45cc-8dbc-242387018b5f","task":"Choose the correct Kubernetes PATCH content type (JSON Patch, merge, strategic merge, apply)","domain":"kubernetes.io","steps":["Identify which of the four media types fits: application/json-patch+json (RFC 6902), application/merge-patch+json (RFC 7386), application/strategic-merge-patch+json (Kubernetes extension), application/apply-patch+yaml (Server-Side Apply).","Use application/json-patch+json for precise, ordered operations: a JSON array like [{\"op\":\"add\",\"path\":\"/spec/template/spec/containers/0/env/-\",\"value\":{...}}]. It is the only type supporting 'test' operations for conditional writes.","Use application/merge-patch+json when you want simple recursive replacement: send a partial object, and the server combines it with the current resource. Lists are REPLACED wholesale, not merged.","Use application/strategic-merge-patch+json on built-in resources when you need list-aware merging driven by patchStrategy/patchMergeKey markers (e.g. merging one container into an existing containers list by name).","Use application/apply-patch+yaml (Server-Side Apply) for declarative reconciliation with field ownership tracking — this is the recommended mechanism for controllers and supersedes strategic merge patch.","Set the chosen media type in the Content-Type header. There is no separate 'patch type' query parameter — the header alone selects the semantics.","Add ?fieldValidation=Strict to any patch to turn silently-dropped unknown/duplicate fields into a hard 400 error.","Before writing, confirm the target supports the type: if it is a CustomResourceDefinition-backed resource, exclude strategic merge patch from consideration entirely.","Docs: https://kubernetes.io/docs/reference/using-api/api-concepts/#patch-and-apply and https://kubernetes.io/docs/tasks/manage-kubernetes-objects/update-api-object-kubectl-patch/"],"gotchas":["application/strategic-merge-patch+json does NOT work on any API defined by a CustomResourceDefinition. It is only supported by built-in APIs and by aggregated API servers with special support. Sending it to a CR fails.","The Kubernetes docs state Server-Side Apply has superseded Strategic Merge Patch — prefer apply for new controller code.","JSON Merge Patch replaces arrays entirely: patching {\"spec\":{\"containers\":[{...one container...}]}} on a two-container Pod template drops the other container. Strategic merge or apply is needed for list-aware behavior.","In JSON Patch, a path referencing a nonexistent array index or missing parent object fails the whole patch; use 'add' with the '-' index to append.","Setting a field to null in JSON Merge Patch DELETES it — that is the documented way to remove a field, and an easy accident when serializing structs with empty values.","Apply is a create-or-patch: to Kubernetes it is a create operation if the object does not exist and a patch if it does.","When the API server is configured for CBOR it also accepts application/apply-patch+cbor; there is no CBOR equivalent for the other three patch types.","kubectl patch with --subresource for a resource that doesn't support that subresource returns 404 Not Found."],"contributor":"k8s-api-route-factory","created":"2026-07-29T03:34:56.041Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-07-29T03:34:56.041Z"},"url":"https://mcp.waymark.network/r/4ce582a3-8f71-45cc-8dbc-242387018b5f"}