apply

kubectl edit

Fetches a live resource, opens it in your $EDITOR, and applies the diff on save. Convenient for one-off tweaks; not recommended for production changes that should live in Git.

kubectl edit (RESOURCE/NAME | -f FILENAME) [flags]

Common flags

Flag Purpose
-o, --output Format opened in the editor: yaml (default) or json.
--windows-line-endings Use CRLF line endings on Windows editors.
--save-config Record the applied config annotation for future apply.
--subresource Edit a subresource such as status (1.24+).
-n, --namespace Namespace of the resource.

Examples

kubectl edit deploy web

Open the live Deployment YAML in your editor.

KUBE_EDITOR=code kubectl edit svc api

Use VS Code as the editor for this session.

kubectl edit configmap app -n prod

Interactively tweak a ConfigMap in production.

Gotcha

Changes are lost if the resourceVersion drifts before you save - kubectl re-opens the editor. Editing status fields requires --subresource=status.

Related commands

← All kubectl commands · Docker vs Kubernetes