KUBERNETES(1)(kubernetes)
β¨ kubectl edit β the glow-up your resources deserve β¨
okay bestie, welcome to the kubernetes manual pages π
this one lives in section 1 of the kubernetes manual set, and it's all about kubectl edit. grab a strawberry π and let's get into it.
πΈ NAME πΈ
kubectl edit β literally just edit a resource on the server. that's the whole vibe.
π¦ SYNOPSIS π¦
kubectl edit [OPTIONS]
π DESCRIPTION π
so the edit command lets you open up a resource from your default editor and change it directly. no cap.
Here's the tea β β edit lets you directly edit any API resource you can retrieve through the command-line tools. When you run it, it opens whichever editor is defined by your KUBE_EDITOR or EDITOR environment variables, and if neither of those exists it falls back to vi on Linux or notepad on Windows. iconic behavior honestly.
When it's trying to open the editor, it first tries to use the shell defined in the SHELL environment variable. If SHELL isn't defined, it uses the default shell β which is /bin/bash on Linux or cmd on Windows. periodt.
You can edit multiple objects at once, though the changes get applied one at a time. The command accepts file names as well as command-line arguments β but heads up, the files you point to must be previously saved versions of resources. no random files, bestie.
Editing happens with the API version that was used to fetch the resource. If you wanna edit using a specific API version, you fully-qualify the resource, version, and group. slay.
The default format is YAML. Wanna edit in JSON instead? Just specify "-o json". π
There's also the --windows-line-endings flag if you wanna force Windows line endings β otherwise you get whatever the default for your operating system is.
β οΈ okay so this part matters: if an error happens while updating, a temporary file gets created on disk containing your unapplied changes. The most common error when updating a resource is another editor changing the resource on the server. When that happens, you have to apply your changes to the newer version of the resource, or update your temporary saved copy to include the latest resource version. don't fight it, just do it π
β¨ OPTIONS β¨
--allow-missing-template-keys=trueβ iftrue, ignore any errors in templates when a field or map key is missing from the template. Only applies togolangandjsonpathoutput formats.--field-manager="kubectl-edit"β the name of the manager used to track field ownership. (that's the default name, and it's giving very self-explanatory π«Ά)-f,--filename=[]β filename, directory, or URL to files to use to edit the resource.-k,--kustomize=""β process the kustomization directory. This flag can't be used together with-for-R. pick a lane bestie.-o,--output=""β output format. One of: (json,yaml,kyaml,name,go-template,go-template-file,template,templatefile,jsonpath,jsonpath-as-json,jsonpath-file).--output-patch=falseβ output the patch if the resource is edited.--record=falseβ record the current kubectl command in the resource annotation. If set tofalse, do not record the command. If set totrue, record the command. If not set, it defaults to updating the existing annotation value only if one already exists.-R,--recursive=falseβ process the directory used in-f,--filenamerecursively. super useful when you wanna manage related manifests organized within the same directory. π--save-config=falseβ iftrue, the configuration of the current object gets saved in its annotation. Otherwise the annotation stays unchanged. This flag is useful when you wanna dokubectl applyon this object in the future.--show-managed-fields=falseβ iftrue, keep themanagedFieldswhen printing objects in JSON or YAML format.--subresource=""β if specified, edit will operate on the subresource of the requested object.--template=""β template string or path to template file to use when-o=go-template,-o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].--validate="strict"β must be one of:strict(ortrue),warn,ignore(orfalse)."true"or"strict"will use a schema to validate the input and fail the request if invalid β it performs server side validation ifServerSideFieldValidationis enabled on the api-server, but falls back to less reliable client-side validation if not."warn"will warn about unknown or duplicate fields without blocking the request if server-side field validation is enabled on the API server, and behaves as"ignore"otherwise."false"or"ignore"will not perform any schema validation, and silently drops any unknown or duplicate fields. π--windows-line-endings=falseβ defaults to the line ending native to your platform.
π OPTIONS INHERITED FROM PARENT COMMANDS π
yes, these are the family heirlooms, passed down from kubectl itself π
--as=""β username to impersonate for the operation. User could be a regular user or a service account in a namespace.--as-group=[]β group to impersonate for the operation. This flag can be repeated to specify multiple groups.--as-uid=""β UID to impersonate for the operation.--as-user-extra=[]β user extras to impersonate for the operation. This flag can be repeated to specify multiple values for the same key.--cache-dir="/home/username/.kube/cache"β default cache directory.--certificate-authority=""β path to a cert file for the certificate authority.--client-certificate=""β path to a client certificate file for TLS.--client-key=""β path to a client key file for TLS.--cluster=""β the name of the kubeconfig cluster to use.--context=""β the name of the kubeconfig context to use.--disable-compression=falseβ iftrue, opt-out of response compression for all requests to the server.--insecure-skip-tls-verify=falseβ iftrue, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure. > β οΈ fr fr be careful with this one, it's giving risky π--kubeconfig=""β path to the kubeconfig file to use for CLI requests.--kuberc=""β path to the kuberc file to use for preferences. This can be disabled by exportingKUBECTL_KUBERC=falsefeature gate or turning off the featureKUBERC=off.--match-server-version=falseβ require server version to match client version.-n,--namespace=""β if present, the namespace scope for this CLI request.--password=""β password for basic authentication to the API server.--profile="none"β name of profile to capture. One of (none|cpu|heap|goroutine|threadcreate|block|mutex|trace).--profile-output="profile.pprof"β name of the file to write the profile to.--proxy-url=""β proxy URL to use for requests to the API server.--request-timeout="0"β the length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g.1s,2m,3h). A value of zero means don't timeout requests.-s,--server=""β the address and port of the Kubernetes API server.--tls-server-name=""β server name to use for server certificate validation. If it's not provided, the hostname used to contact the server is used.--token=""β bearer token for authentication to the API server.--user=""β the name of the kubeconfig user to use.--username=""β username for basic authentication to the API server.--version=falseβ--version,--version=rawprints version information and quits;--version=vX.Y.Z...sets the reported version.--warnings-as-errors=falseβ treat warnings received from the server as errors and exit with a non-zero exit code.
π§ EXAMPLE π§
okay these are the actual ones, copy them exactly bestie:
# Edit the service named 'registry'
kubectl edit svc/registry
# Use an alternative editor
KUBE_EDITOR="nano" kubectl edit svc/registry
# Edit the job 'myjob' in JSON using the v1 API format
kubectl edit job.v1.batch/myjob -o json
# Edit the deployment 'mydeployment' in YAML and save the modified config in its annotation
kubectl edit deployment/mydeployment -o yaml --save-config
# Edit the 'status' subresource for the 'mydeployment' deployment
kubectl edit deployment mydeployment --subresource='status'
ate and left no crumbs π₯
π SEE ALSO π
π HISTORY π
January 2015 β originally compiled by Eric Paris (eparis at redhat dot com) based on the kubernetes source material, but hopefully they have been automatically generated since! π
and that's the whole page, bestie π«Ά this one came from the Manuals collection in the User series, under the title KUBERNETES(1)(kubernetes) β go forth and edit responsibly, you gorgeous main character πβ¨π
π¦ where this page comes from
- arch rolling: kubectl 1.37.2-1 Β· Apache-2.0
- fedora 43: kubernetes1.37-client 1.37.0-3.fc43
- fedora 43: kubernetes1.37-client 1.37.1-1.fc43 Β· Apache-2.0 AND BSD-2-Clause AND BSD-3-Clause AND BSD-3-Clause-HP AND CC-BY-4.0 AND ISC AND MIT AND MPL-2.0
- fedora 44: kubernetes1.37-client 1.37.0-3.fc44
- fedora 44: kubernetes1.37-client 1.37.1-1.fc44 Β· Apache-2.0 AND BSD-2-Clause AND BSD-3-Clause AND BSD-3-Clause-HP AND CC-BY-4.0 AND ISC AND MIT AND MPL-2.0
- nixpkgs unstable: kubectl 1.37.2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms