apply

kubectl patch

Applies a partial update to a resource using strategic-merge, JSON-merge, or JSON-patch semantics. It is the surgical tool for changing a single field without rewriting the whole manifest.

kubectl patch (TYPE NAME | -f FILENAME) [-p PATCH] [--type strategic|merge|json] [flags]

Common flags

Flag Purpose
-p, --patch Inline patch document (JSON or YAML).
--patch-file Read the patch from a file instead of the CLI.
--type strategic (default for built-ins), merge, or json (RFC 6902).
--subresource Target a subresource such as status or scale (1.24+).
--dry-run none, client, or server to preview the change.

Examples

kubectl patch deploy web -p '{"spec":{"replicas":5}}'

Strategic-merge patch to change replica count.

kubectl patch svc api --type=json -p='[{"op":"replace","path":"/spec/type","value":"ClusterIP"}]'

JSON Patch to flip Service type.

kubectl patch node worker-1 -p '{"spec":{"unschedulable":true}}'

Cordon a node via patch.

kubectl patch pod web --subresource=status -p '{"status":{"phase":"Failed"}}'

Patch a status subresource (rarely needed).

Gotcha

Strategic merge only works on built-in types; CRDs default to JSON-merge. Quoting matters on Windows PowerShell - prefer --patch-file for multi-line patches.

Related commands

← All kubectl commands · Docker vs Kubernetes