Set a default editor for kubectl

Shivakumar Ganganna
1 min readFeb 19, 2021

--

kubectl is a popular command line tool used for connecting to Kubernetes cluster, which allows you to execute commands and interact with the cluster.

We normally come across situation where for minor changes or testing, we may have to make inplace updates to the Kubernetes resources like deployment, service, configmap etc. by default the resource contents open on the default editor, (vi on MacOS and Notepad on Windows) which is not very user friendly.

To use your favorite editor by default, set the environment variable KUBE_EDITOR and then execute the kubectl edit command.

On MacOS, for any of the popular editors installed on your machine, execute one of the below command in the Terminal.

To set Visual Studio Code as a default editor.
export KUBE_EDITOR='open -a "Visual Studio Code" --wait'
To set Sublime Text as a default editor.
export KUBE_EDITOR='open -a "Sublime Text" --wait'
To set Atom as a default editor.
export KUBE_EDITOR='open -a "Atom" --wait'

Generic format to set any application editor.
export KUBE_EDITOR=‘open -a “<application_name>” --wait’

Note: Environment variables set on the Terminal is short lived as long as its open. To persist permanently, set the variable in the .bash_profile file present under the root folder.

On Windows, navigate to Advanced system settings > System Properties > Advanced tab, then select Environment Variables to create a variable named as KUBE_EDITOR with the value pointing to the path of your favorite text editor.

Example command to edit deployment.
kubectl edit deployment <deployment_name> -n <namespace>

--

--

Shivakumar Ganganna
Shivakumar Ganganna

Written by Shivakumar Ganganna

Cloud Enthusiast, DevOps, Kubernetes, Pega Consultant

No responses yet