Azure CLI Notes
Khaled Hikmat
Software EngineerThis is just a note about Azure CLI login options.
Option 1:#
Login interactively via a browser
Option 2:#
The best way to login is to use an Azure Service Principal though. So I registered an application in Azure Directory i.e. AzureCliScriptApp and assigned a service principal. I will use this service principal to login.
Create a service principal:#
Make sure you are in the same tenant that you want to authenticate against. If not, use 'az account set --subscription "your-subs"' to set the account.
To display the Azure Directory apps:
The above will yield the app id ...a big string that looks like this: e68ab97f-cff2-4b50-83d5-eec9fe266ccc
To login with service principal:
Useful Commands:#
List all subscriptions
Set the default account
List the Clouds
Kubernetes#
if you are using the Azure CLI to provision a Kubernetes cluster, you should use this command if you used the service principal to login
Where:
$rgName is the PowerShell variable that holds the resource group name
$k8sClusterName is the PowerShell variable that holds the k8s cluster name
$spAppId is the PowerShell variable that holds the service principal app id
$spPassword is the PowerShell variable that holds the service principal password
$k8sNodesCount is the PowerShell variable that holds the k8s cluster desired nodes count
Refer to this doc for more information