Visual Studio Code (VS Code) supports auto-completion, validation, error highlighting and tooltips for Kubernetes through the Visual Studio Code Kubernetes Tools extension. This extension uses kubectl
to interact with your Kubernetes cluster without leaving VS Code.
Prerequisites
- VS Code is installed.
- Kubernetes cluster with the Airlock Microgateway CRDs deployed.
kubectl
is installed.- A valid
kubeconfig
to interact with your Kubernetes cluster.
- The
kubeconfig
must fulfill the following requirements: - Allows to access the Kubernetes cluster where the Airlock Microgateway CRDs are deployed.
- The
current-context
is set to this Kubernetes cluster.
The default kubeconfig
is located in ~/.kube/config
. For further information consult the Kubernetes manual: (Kubernetes) Kubeconfig
How to install the Kubernetes extension in VS Code
- Start Visual Studio Code.
- Open the extensions search tree with Ctrl+Shift+X and search for Kubernetes.
- Install the VS Code extension Kubernetes Tools. See also the list of included features in the extension description.
- The Kubernetes icon appears in the left icon bar.
- Restart Visual Studio Code to reload the extension.
- With a click on the Kubernetes icon, a Kubernetes section with a list of reachable clusters appears.
The display name is Kubernetes and the full extension name is displayed in the Details tab.
Use Ctrl+Shift+P to open the command palette. Start typing Kubernetes will show all available Kubernetes-related commands such as Kubernetes: Apply which calls kubectl apply
remotely.
YAML support is based on the Red Hat YAML language extension that is automatically installed as a dependency of the Kubernetes tools extension. VS Code Visual Studio code validates only the CustomResources with the OpenAPI schema specification within the CRD. This means, that it's only a syntactical validation but when applying the code, the semantic validation could still fail.
Visual Studio Code Desktop configuration
The VS Code for the web configuration is relevant to have autocompletion, validation, error highlighting and tooltips for the CRDs.
- Start VS Code on your desktop.
- Use Ctrl+Shift+P to open the command palette. Start typing Preferences and select Preferences: Open User Settings (JSON).
- Adjust
settings.json
to your needs. We used the following configuration:
The vs-kubernetes
settings belong to the Kubernetes plugin mentioned on this page and must fit your setup. In addition, the setting editor.wordBasedSuggestions
should be switched to false
otherwise wrong suggestions are made.
... "[yaml]": { ... "editor.wordBasedSuggestions": false }, ...
Ensure that the mentioned settings are configured the way we did. For a simple test, you can also use our configuration.
Automatic validation example with Visual Studio Code
After configuring Visual Studio Code as described, completion, validation and tooltip is available while typing.