kubectl, allows you to run commands against Kubernetes clusters. Use kubectl to deploy applications, inspect and manage cluster resources, and view logs.
In this post, learn how to install
kubectl, how to access the cluster, and the basic command you use to manage the cluster.
There are a lot of tools you can use. In this post, learn about:
- On Windows: Docker plus WSL
- On Ubuntu Linux: MicroK8s
- On desktops connected to Azure Kubernetes Service
- Bridge to Kubernetes for Visual Studio users
- Kind and Minikube to run cluster on your local development machine
kubectl on your local development machine. It sends API commands to objects in you Kubernetes cluster for you to manage the cluster.
Tip: You must use a
kubectlversion that is within one minor version difference of your cluster. For example, a v1.2 client should work with v1.1, v1.2, and v1.3 master. Using the latest version of
kubectlhelps avoid unforeseen issues.
You have a few options to integrate your development computer with Kubernetes:
- Install a copy of Kubernetes suitable for your desktop.
kubectland interact with a remote Kubernetes cluster
Docker plus WSL: Kubernetes on the Windows Desktop
The quickest way to install both kubectl and a single node cluster on Windows is to use Windows Subsystem for Linux (WSL) which also installs Docker. WSL brought an ability to run Kubernetes on Windows almost seamlessly, but there are some things you need:
- OS: Windows 10 version 2004, Build 19041
- WSL2 enabled. In order to install the distros as WSL2 by default, once WSL2 installed, run the command
wsl.exe --set-default-version 2in PowerShell
- WSL2 distro installed from the Windows Store – the distro used is Ubuntu-18.04
- Docker Desktop for Windows, stable channel – the version used is 188.8.131.52
- [Optional] Microsoft Terminal installed from the Windows Store. Open the Windows store and type “Terminal” in the search, it will be (normally) the first option.
For more information and the steps to configure Docker, see WSL+Docker: Kubernetes on the Windows Desktop.
MicroK8s on Linux
If you are on a Linux as a desktop or server, you may want a local Kubernetes development environment. In this case, you may want to choose MicroK8s, built to run on any Linux. It’s lightweight and deploys all Kubernetes services natively on Ubuntu (i.e. no virtual machines required) while packing the entire set of libraries and binaries needed. It’s suited for laptops, workstations, CI pipelines, IoT devices, and small edge clouds because of its small footprint.
For more information, see How to install Kubernetes on Ubuntu. There is a multi-node option too, but requires a substantial computer.
Install Microk8s using snap, which will create a “clean” deploy of the latest upstream Kubernetes on your local machine. The Snap tool is taking care of all needed operations and can upgrade all associated binaries to their latest versions. By default, Microk8s installs and runs the following services:
Use kubectl to work with Azure Kubernetes Service
If you are using AKS, you can install
kubectl on your desktop using the following commands:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|az aks install-cli|
|az aks get-credentials –resource-group $RESOURCE_GROUP_NAME –name $AKS_NAME|
The CLI command
az aks install-cli downloads and installs
kubectl. It also downloads and installs
kubelogin, a client-go credential (exec) plugin implementing Azure authentication. If you require support for a particular version, you can specify it in the optional parameters.
The second command,
az aks get-credentials uses your log in credentials to get authorization to access the cluster. You can specify that you need cluster administrator credentials or point to a Kubernetes configuration file using optional parameters. The
az aks get-credentials command lets you get the access credentials for an AKS cluster and merges them into the kubeconfig file. You can use Azure role-based access control (Azure RBAC) to control access to these credentials.
If you are using Azure Cloud Shell, kubectl and many other useful tools are already installed.
Bridge to Kubernetes
For those using Visual Studio, you can use Bridge to Kubernetes, which redirects traffic between your Kubernetes cluster and code running on your development computer. Bridge to Kubernetes avoids the need to build and deploy your code to your cluster. It connects your development computer to your cluster during debugging so you can quickly test and develop your service, which allows you to use the context of the full application without creating any Docker or Kubernetes configuration.
To use Bridge to Kubernetes in Visual Studio, you need the Bridge to Kubernetes Extension installed and at least
Visual Studio 2019 version 16.7 Preview 4 or greater running on Windows 10 with the ASP.NET and web development workload installed.
For more information, see Use Bridge to Kubernetes.
There are some other choices, such as:
- kind is a tool for running local Kubernetes clusters using Docker container “nodes”.
kind was primarily designed for testing Kubernetes itself, but may be used for local development or CI.
- minikube runs a single-node Kubernetes cluster on your personal computer (including Windows, macOS and Linux PCs) so that you can try out Kubernetes, or for daily development work.