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 β€” if true, ignore any errors in templates when a field or map key is missing from the template. Only applies to golang and jsonpath output 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 -f or -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 to false, do not record the command. If set to true, 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, --filename recursively. super useful when you wanna manage related manifests organized within the same directory. 🌈
  • --save-config=false β€” if true, the configuration of the current object gets saved in its annotation. Otherwise the annotation stays unchanged. This flag is useful when you wanna do kubectl apply on this object in the future.
  • --show-managed-fields=false β€” if true, keep the managedFields when 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 (or true), warn, ignore (or false). "true" or "strict" will use a schema to validate the input and fail the request if invalid β€” it performs server side validation if ServerSideFieldValidation is 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 β€” if true, opt-out of response compression for all requests to the server.
  • --insecure-skip-tls-verify=false β€” if true, 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 exporting KUBECTL_KUBERC=false feature gate or turning off the feature KUBERC=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=raw prints 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