Visual Studio Code Kubernetes Tools Extension

Simplified Kubernetes Development — Visual Studio Code Kubernetes Tools Extension

Mickey Boxell
ITNEXT
Published in
5 min readJul 10, 2019

--

I find the command line to be comfortable and efficient. Using it to interact with a Kubernetes cluster via kubectl is relatively intuitive. Anytime you forget a command you can pop over to the kubectl cheatsheet or run kubectl -h to get some help. One thing the command line lacks — by design — is the ability to easily visualize and explore resources in your cluster. Also, when it comes to Kubernetes, the indentation-obsessed nature of yaml can make editing with command line editors a pain. The Visual Studio Code Kubernetes Tools extension addresses these challenges by providing a visualization of your Kubernetes cluster and also yaml and Kubernetes-specific editing tools absent from command line editors. The extension works with Kubernetes regardless of where it is running (Docker for Desktop, Minikube, Azure, Google Cloud, Oracle Cloud, etc.).

Pre-Requisites

Install Docker and Install kubectl.

In order to test out how VS Code can be used to interact with a Kubernetes cluster, of course you need a Kubernetes cluster with which to interact. This can be accomplished by creating a local Kubernetes cluster with Docker for Desktop or a managed Kubernetes cluster with Oracle Container Engine for Kubernetes (OKE).

Installation

To install the Kubernetes extension, open Extensions (⇧⌘X) and search for “kubernetes”. Select the Microsoft Kubernetes extension.

Using the Extension

Interacting with Your Cluster

The extension will show the clusters available in your kubeconfig file. Right-clicking on a cluster name gives you the options to Show Cluster Info, Open Dashboard, and Delete from kubeconfig. If you right-click on a cluster different from your current context, you also will have the option to Set as Current Cluster. Show Cluster Info opens up a terminal and runs kubectl cluster-info. Open Dashboard configures a port forward and opens your browser to the Kubernetes Dashboard. Set as Current Cluster saves you from having to manually run kubectl commands or download a tool such askubectx to change your context.

Visualizing Your Cluster

The extension also visualizes the various components of your cluster. Rather than having to run kubectl get namespaces, your namespaces are all available when you expand the Clusters tab. The same is true for Nodes, Workloads (including Deployments, StatefulSets, DaemonSets, Jobs, CronJobs, Pods), Network (including Services, Endpoints, and Ingress), Storage (including Persistent Volumes, Persistent Volume Claims, and Storage Classes), Configuration (including Config Maps and Secrets), and also your Custom Resource Definitions. Digging into specific resource provides more options for interaction.

Take Pods for example: clicking into Workloads > Pods will show you a list of all the Pods running in your current namespace. Clicking on the Pod itself will show you the status. Right-clicking the Pod name shows a list of commands used to interact with the Pod. Each command takes care of something typically done with kubectl. For example, right-clicking and choosing Get will run kubectl get pod/[pod name] --namespace default -o wide and provide you with the output. The same list of commands also allows you to delete the pod, describe the pod, get logs from the pod, create a port-forward, exec into the pod, and more. This can be a huge time-saver.

Simplify YAML

The Kubernetes extension also provides autocompletion with Intellisense, code snippets, and verification for Kubernetes manifest files. For example, once you type kind: Deployment and tab to autocomplete, the rest of the manifest file is generated for you. The only manual effort required is for you to enter a name for your app, your image, and also the port you want to use. Additionally, the extension includes other features to find your way around a yaml file. Hovering above a component of the manifest will reveal additional information about that component.

Run Commands

The extension also allows you to run simplified Kubernetes commands. Once your manifest file is ready, you can start a deployment by opening the Command Palette (⇧⌘P) and running Kubernetes: Create. This command will deploy the application to your cluster based on the selected Kubernetes manifest file.

Azure-Specific Tools

Some features of the extension are Azure-specific. For instance, you have the ability to create a Kubernetes cluster running on Azure directly from VS Code. This can be accomplished by clicking on More, signified by three horizontal dots, next to Clusters and choose Create Cluster. Follow the instructions to choose between Azure Container Service, Azure Kubernetes Service, and Minikube as your cluster type. Even if you are not an Azure user, this part of the UI is useful because it allows you to specify a new Kubeconfig file in order to connect to a different cluster. It would be helpful to be able to add a new cluster, context, and user to an existing Kubeconfig file.

There are a few other aspects of the extension that are not Azure-specific, but tie directly into the Azure ecosystem. This includes Helm and Draft. The Kubernetes Tools extension provides the ability to visualize Helm Releases in your cluster and also view Helm repositories. The latter is useful for inspecting charts, values, and dependencies. It can also be used to fetch and install charts. Many Helm commands (helm fetch, helm install, helm lint, etc.) are available to run from the Command Palette. The same is true for a handful of Draft commands (draft up, draft create, and draft version).

Additional Extensions

Linkerd

The Visual Studio Code Linkerd extension was built to provide support for the Linkerd2 Service Mesh within the VSCode Kubernetes Extension. Automatically runs the linkerd check --pre command and the linkerd install command. Provides the ability to configure a portforward and connect to the Linkerd and Grafana dashboards for a particular pod. It would be great if they could add the ability to inject the Linkerd proxy to a Kubernetes config, either at a pod or namespace level. It is important to remember to modify your VS Code Settings (⌘,) with the path to the Linkerd2 binary.

Summary

The Visual Studio Code Kubernetes Tools Extension is a useful tool for working on Kubernetes manifest files and interacting with your cluster(s). It is useful both for developers building containerized applications for Kubernetes clusters and for the DevOps practitioners supporting those applications.

Additional Reading

Additional information can be found on the Working with Kubernetes in VS Code page and on the VS Kubernetes Tools GitHub page.

--

--

Writer for

Product Manager — OCI Container Engine for Kubernetes (OKE)