The following are some useful commands in PowerShell for AKS cluster, node, and pod administration and common troubleshooting:
Get-AzAks
Get-AzAksNode
Get-AzAksPod
Get-AzAksService
Get-AzAksDiagnostics
Get-AzAksUpgrade
Get-AzAksScale
Get-AzAksLogs
Before running commands, set your Azure context:
Connect-AzAccount
Select-AzSubscription -SubscriptionName "<YourSubscriptionName>"
Set-AzContext -ResourceGroupName "<YourResourceGroup>"
kubectl drain <node-name> --ignore-daemonsets
kubectl cordon <node-name>
kubectl taint nodes <node-name> key=value:NoSchedule
In order to use the above commands, you will need to have the appropriate permissions. For example, you will need to be an Owner or Contributor of the resource group containing the AKS cluster in order to use the Get-AzAks command.
In order to set the context, you will need to log in to your Azure account using the Connect-AzAccount command. Once you have logged in, you will need to select the subscription you want to use with the Select-AzSubscription command. Finally, you will need to set the context to the resource group containing the AKS cluster with the Set-AzContext command.
A simple guide to complete these steps is as follows:
Log in to your Azure account using the Connect-AzAccount command.
Select the subscription you want to use with the Select-AzSubscription command.
Set the context to the resource group containing the AKS cluster with the Set-AzContext command.
Use the Get-AzAks command to list all the AKS clusters in the Azure subscription.
Use the other Get-AzAks commands to list nodes, pods, services, and more.
in order to execute administrative tasks such as draining nodes, cordoning, or modifying taints you will need to use kubectl. Some useful commands include:
kubectl drain: This command is used to drain a node in an AKS cluster. It can be used to safely evict all pods from the node and make it unavailable for scheduling new pods.
kubectl cordon: This command is used to mark a node as unschedulable. It can be used to prevent new pods from being scheduled on the node.
kubectl taint: This command is used to add, modify, or remove taints on a node. It can be used to control which pods can be scheduled on the node.
In order to use these commands, you will need to have the appropriate permissions. For example, you will need to be an Owner or Contributor of the resource group containing the AKS cluster in order to use the kubectl commands.
In order to set the context, you will need to log in to your Azure account using the Connect-AzAccount command. Once you have logged in, you will need to select the subscription you want to use with the Select-AzSubscription command. Finally, you will need to set the context to the resource group containing the AKS cluster with the Set-AzContext command.
A simple guide to complete these steps is as follows:
Log in to your Azure account using the Connect-AzAccount command.
Select the subscription you want to use with the Select-AzSubscription command.
Set the context to the resource group containing the AKS cluster with the Set-AzContext command.
Use the kubectl drain, cordon, and taint commands to manage nodes in the AKS cluster.