How can I fix Edit cancelled, no changes made in shell
With vim, when you try to save it saves an edited copy which is specified in /tmp/
path, along with the error message, when you quit the editor.
This is equivalent to using get
the resource, edit it in text editor, and then apply the resource with the updated version:
kubectl get deployment my-nginx -o yaml > /tmp/nginx.yaml
vim /tmp/nginx.yaml
kubectl apply -f /tmp/nginx.yaml
deployment.apps/my-nginx configured
then remove the file
rm /tmp/nginx.yaml
So basically use apply
on the file saved in the /tmp/<file.yaml>
A refinement to the ample answer provided by @faho.
An approach with the $EDITOR variable achieves the goal but changes the default command-line editor. This might affect other programs dependent on this setting (e.g. crontab, edquota).
It'd be better to rely on the $KUBE_EDITOR variable. For example for the one-time use you might try:
KUBE_EDITOR="nano" kubectl edit deploy/hello-world
(Please see Editing Resources)
Things like this are most likely caused by it opening an editor that forks off instead of staying.
That means you'll want to set $EDITOR to an editor that does wait. E.g. nano
, vim
or emacs
should work, and e.g. if you use sublime text you'll have to use subl -w
to explicitly tell it to wait.
It's not quite clear which shell you're running at the moment. If it's bash, run export EDITOR="subl -w"
, in fish run set -gx EDITOR subl -w
(or "subl -w"
if you use fish < 3.0).