To operate and maintain TKG clusters, configure a default text editor for kubectl.
Using the kubectl edit command
After you provision a TKG cluster, you operate and maintain it. Typical tasks include scaling cluster nodes and updating the TKR version. To perform such tasks you update the cluster manifest using the kubectl edit command.
The command kubectl edit CLUSTER-KIND/CLUSTER-NAME
opens the cluster manifest in the text editor defined by your KUBE_EDITOR or EDITOR environment variable. When you save the manifest changes, kubectl
reports that the edits were successfully recorded, and the cluster is updated with the changes.
kubectl edit tanzukubernetescluster/tkg-cluster-1 tanzukubernetescluster.run.tanzu.vmware.com/tkg-cluster-1 edited
kubectl edit tanzukubernetescluster/tkg-cluster-1 Edit cancelled, no changes made.
Configuring kubectl edit
To use the kubectl edit
command, on Linux the EDITOR environment variable is set. Otherwise, create a KUBE_EDITOR environment variable and specify your preferred text editor as the variable value. Append the watch flag ( -w
) so that kubectl knows when you have committed (saved) your changes.
Refer to the specific instructions for your operating system.
- Linux
-
To configure
kubectl edit
on Linux (Ubuntu, for example), the default command-lineEDITOR
is Vim. If this case, no further action is needed to use thekubectl edit
command.If you want to use a different text editor, create an environment variable named
KUBE_EDITOR
with the value set to the path of your preferred text editor.
- Mac OS
-
To configure
kubectl edit
on Mac OS, create an environment variable namedKUBE_EDITOR
with the value set to the path of your preferred text editor. Append the wait flag (--wait
, or the shortcut-w
) to the value so that the editor knows when you have committed (saved) your changes.For example, the following addition to the.bash_profile
sets Sublime as the default text editor for kubectl and includes the wait flag so the editor knows when you have saved any changes.export KUBE_EDITOR="/Applications/Sublime.app/Contents/SharedSupport/bin/subl -w"
- Windows
-
To configure
kubectl edit
on Windows, create a system environment variable namedKUBE_EDITOR
with the value set to the path of your preferred text editor. Append the watch flag (-w
) to the value.For example, the following environment variable sets Visual Studio Code as the default text editor for kubectl and includes the watch flag so that Kubernetes knows when you save your changes:KUBE_EDITOR=code -w
To configure Sublime as the kubectl editor on Windows, append the Sublime program directory to the sytem path and create a system variable for the Sublime executable. For example:
Sytem PATH append:C:\Program Files\Sublime Text 3\
System variable name and value:KUBE_EDITOR=sublime_text.exe -w