Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

az

The Azure CLI: manage subscriptions, resource groups, VMs, networks, storage, AKS, Key Vault and Entra ID from the terminal.

Niveau
DevSecOps-service
Groep
Infrastructuur als code en cloud
Root nodig
Nee
Pakket
azure-cli

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

az talks to Azure Resource Manager. You log in once (az login), choose a subscription, and work with resources inside resource groups. Every command follows the pattern az GROUP [SUBGROUP] VERB --options. Output is JSON by default; -o table is easier to read and --query (JMESPath) picks fields.

It is the main CLI tool for AZ-104 and for scripts and CI pipelines on Azure (with azure/login and OIDC in GitHub Actions).

Zo schrijf je het

az GROUP [SUBGROUP] COMMAND [--options] [-o table|json|tsv] [--query EXPR]

Belangrijkste delen

Most used groups

login / logout / account
Sign in, choose the subscription.
group
Resource groups.
vm
Virtual machines.
network vnet|nsg|public-ip|lb
Networking.
storage account|container|blob
Storage.
aks
Azure Kubernetes Service.
acr
Azure Container Registry.
keyvault
Key Vault (secrets, keys, certificates).
role assignment / ad sp
RBAC and service principals.
monitor
Metrics, logs, alerts, diagnostic settings.
policy
Azure Policy.
resource
Any resource by ID.
webapp / containerapp / functionapp
App platforms.
deployment group create
Deploy Bicep or ARM templates.
upgrade / extension
Update the CLI / add extensions.

Opties 8

Meest gebruikt

Global options

-g, --resource-group NAME
Resource group.
-n, --name NAME
Resource name.
-l, --location REGION
Region (westeurope, northeurope …).
-o, --output table|json|tsv|yaml|none
Output format.
--query JMESPATH
Pick fields.
--subscription ID
Use another subscription.
--only-show-errors
Hide warnings.
--debug
Show the HTTP calls.

Voorbeelden 11

$ als gewone gebruiker# als root (of met sudo)

  1. 1Log in and choose a subscription

    az login
    az account list -o table
    az account set --subscription "Lab Subscription"
    az account show --query "{name:name, id:id}" -o table
  2. 2Create a resource group and a VM

    az group create -n rg-lab-weu -l westeurope --tags owner=s0sta env=lab
    az vm create -g rg-lab-weu -n vm-web1 --image RedHat:RHEL:9-lvm-gen2:latest --size Standard_B2s --admin-username azureuser --ssh-key-values ~/.ssh/id_ed25519.pub --public-ip-sku Standard
    az vm list -g rg-lab-weu -d -o table
  3. 3Stop paying for a lab VM

    az vm deallocate -g rg-lab-weu -n vm-web1
    az vm start -g rg-lab-weu -n vm-web1
  4. 4Network: VNet, subnet and NSG rule

    az network vnet create -g rg-lab-weu -n vnet-lab --address-prefix 10.20.0.0/16 --subnet-name snet-web --subnet-prefix 10.20.1.0/24
    az network nsg create -g rg-lab-weu -n nsg-web
    az network nsg rule create -g rg-lab-weu --nsg-name nsg-web -n allow-https --priority 100 --access Allow --protocol Tcp --destination-port-ranges 443
  5. 5Storage account with no public blob access

    az storage account create -g rg-lab-weu -n sts0stalab01 --sku Standard_LRS --min-tls-version TLS1_2 --allow-blob-public-access false
    az storage container create --account-name sts0stalab01 -n backups --auth-mode login
  6. 6Key Vault and a secret

    az keyvault create -g rg-lab-weu -n kv-s0sta-lab --enable-rbac-authorization true
    az keyvault secret set --vault-name kv-s0sta-lab -n db-password --value "$(openssl rand -base64 24)"
    az keyvault secret show --vault-name kv-s0sta-lab -n db-password --query value -o tsv
  7. 7Create AKS and get the kubeconfig

    az aks create -g rg-lab-weu -n aks-lab --node-count 2 --node-vm-size Standard_B2s --enable-managed-identity --network-plugin azure --generate-ssh-keys
    az aks get-credentials -g rg-lab-weu -n aks-lab
    kubectl get nodes
  8. 8Give least-privilege access (RBAC)

    az role assignment create --assignee user@example.com --role "Reader" --scope /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-lab-weu
    az role assignment list -g rg-lab-weu -o table
  9. 9Find resources with a query

    az resource list --tag env=lab --query "[].{name:name, type:type}" -o table
    az vm list --query "[?powerState=='VM running'].name" -d -o tsv
  10. 10Deploy a Bicep file

    az deployment group create -g rg-lab-weu -f main.bicep -p env=lab
    az deployment group what-if -g rg-lab-weu -f main.bicep
  11. 11Clean up the whole lab

    az group delete -n rg-lab-weu --yes --no-wait

Let op

  • az group delete deletes everything inside; check the name twice.
  • Prefer managed identities and OIDC over client secrets for scripts and CI.
  • Set budgets and alerts (az consumption budget) on lab subscriptions.

Bestanden

~/.azure/
Login tokens and CLI config (keep private).

Tips om te onthouden

  • az interactive gives autocomplete; az find "create vm" shows examples.
  • az config set defaults.group=rg-lab-weu defaults.location=westeurope saves typing.

Exitcodes

0Success.
1Error.
2Parser error (bad arguments).
3Resource not found (some show commands).

Volledige handleiding

Deze pagina legt het commando uit in eenvoudige woorden. De originele handleiding heeft elk detail.

In je terminal: man az