When you use a Windows machine it is not straight forward to install and configure kubectl tool. kubectl is command line tool for controlling Kubernetes clusters, Didn`t knew that Microsoft has introduced WSL (Windows Subsystem for Linux on Windows 10) feature for Windows 10 users. In short, it means that you can run Linux commands on your Windows machine. 😮

To complete installation you should follow a few steps:

  • Update your Windows 10 that build version would be 16215 or later
  • Enable WSL Windows 10 feature using Powershell
  • Install Ubuntu distribution
  • Install Visual Studio Code
  • Connect remotely from Visual Studio to Ubuntu
  • Install and configure kubectl tool

Update Windows 10 💻

Got to Windows - Settings - About and find section Windows specification if OS build is less 16215 you have to update your operation system.  

Windows OS build

Enable WSL Windows 10 feature using Powershell

I found Microsoft instruction very helpful. Run inside Powershell command to activate WSL.

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

When command completed restart your PC.

Install Ubuntu distribution

Open Microsoft Store on your PC and find Ubuntu. I prefer the latest version 18.04 LTS.

Ubuntu distribution

Install Visual Studio Code

If you already have Visual Studio Code, then skip this step. The installation you can find https://code.visualstudio.com/.

Connect remotely from Visual Studio to Ubuntu

When you open Visual Studio Code it automatically detects WSL. Just click on that green icon and choose the distribution you installed. WSL plugin will connect to your Ubuntu.

WSL connection to Ubuntu

Thant using shortcutCtrl+Shift+` open terminal and you are in and how you can use Linux commands.

Linux commands inside Visual Studio Code

Install and configure kubectl tool 💡

In terminal execute following commands. I followed this documentation https://kubernetes.io/docs/tasks/tools/install-kubectl/.

curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
kubectl version --client

When you need to connect to your enterprise Kubernetes cluster, you need to create a configuration file. Using Visual Studio Code you can easily browse the directory and create files inside your Ubuntu distribution. Create configuration file kube.conf.

To tell kubectl that you have to use this configuration file need to set environment variable KUBECONFIG which points to this configuration file.

export KUBECONFIG=/home/valdis/kube.conf 

Inside kube.conf add access to your Kubernetes cluster.

apiVersion: v1
clusters:
- cluster:
    certificate-authority: fake-ca-file
    server: https://1.2.3.4
  name: development
contexts:
- context:
    cluster: development
    namespace: frontend
    user: developer
  name: dev-frontend
current-context: dev-frontend
kind: Config
preferences: {}
users:
- name: developer
  user:
    client-certificate: fake-cert-file
    client-key: fake-key-file
https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/

Now you can test using kubectl cluster-info.

Have fun with k8s 💡!

[eof]