A Neate Blog


14 November 2019

Changing the default editor of Kubectl Edit

Tags: Kubernetes - Kubectl - VS Code


If you find yourself working with Kubernetes, whether that’s in the cloud on AKS (Azure), EKS (AWS), OKE (Oracle Cloud), GKE (Google Cloud) or even locally, chances are you have encountered the need to edit a piece of config via the kubectl edit command, did you know that you can change the default editor that kubectl edit uses, on Windows it’s Notepad by default but I changed it to VS Code and here’s how.

To achieve this, I needed to create a new system environment variable named:

KUBE_EDITOR

The value of the new environment variable needed to be set to a chosen editor, in my case it was VS Code which uses the CLI command of code

KUBE_EDITOR=code

With the above configuration I was now able to use VS Code as the editor when I executed kubectl edit, the only issue was that VS Code didn’t wait for me to make the changes, save and close the file i.e. it didn’t “watch” the file, a quick search of VS Code documentation revealed the -w flag which allows VS Code to wait for the files to be closed before returning.

After updating the environment variable to the below, VS Code was working with kubectl edit like a charm.

KUBE_EDITOR=code -w

TL;DR:- You need to create an environment variable named KUBE_EDITOR, the value should be set to the CLI command to open the editor of your choice and ideally specify a watch flag so K8s knows when the file has has been saved and closed.

Useful Links: