This post shows how I was able to get started using Azure Kubernetes Service (AKS) with PowerShell. Azure provides a Kubernetes service that is capable of orchestrating Windows containers as well as Linux containers. This makes AKS an ideal solution for .NET developers.
There’s more information on the Microsoft site. I’m going to cover most of what they don’t cover and put it in a more straightforward guide. Ping me on Twitter or comment here if you see something that should be added.
Installing in PowerShell
If you have PowerShell 5.1 or higher you can install modules that interact with Azure and the AKS service. You’ll need to install the Az.Aks module first and import it before AKS Kubectl will be available.
Install-Module -Name Az.Aks -AllowPrerelease Import-Module Az.Aks Install-AzAksKubectl -Version latest
You may have to add the .azure-kubectl to your search PATH. You can easily append your path to the system’s environment PATH variable.
$env:Path += ";C:\Users\mrjamiebowman\.azure-kubectl"
If you have issues…
Getting the version of Az.Aks
Get-InstalledModule -Name Az.Aks
Kubectl Autocompletion for PowerShell
I found this module useful and certainly helps with autcompletion.
Install-Module -Name PSKubectlCompletion Import-Module -Name PSKubectlCompletion
Get-Command -Module Az.Aks
Connecting to Azure
You will be prompted to log in to Azure in a pop-up browser Window.
It’s important to set the Azure Context to the subscription you are using. I have multiple subscriptions so I need to list and set the subscription for PowerShell to connect to the appropriate cluster.
Get-AzSubscription Get-AzSubscription -SubscriptionId 00000000-0000-0000-0000-000000000000 | Set-AzContext
Connecting to the Cluster
If you are on the right subscription you should be able to easily connect to the cluster running these commands.
Import-AzAksCredential -ResourceGroupName K8S -Name KubeDev
Basic Kubernetes Commands
These are some basic commands worth noting. I recommend referencing the kubectl cheatsheet. It’s very useful… Some of the commands below are not on the cheatsheet.
kubectl get all
kubectl delete all --all
kubectl get service nugetserver --watch