Skip to content

Instantly share code, notes, and snippets.

@MartinLuksik
Last active February 6, 2023 10:40
Show Gist options
  • Save MartinLuksik/0dc11bb6e92e529ff4c9272b745b0f1d to your computer and use it in GitHub Desktop.
Save MartinLuksik/0dc11bb6e92e529ff4c9272b745b0f1d to your computer and use it in GitHub Desktop.
[Azure CLI] Azure CLI #az #azcli
az acr repository show --name btcsacr --image myapp:v1
# Unlocked it:
az acr repository update --name btcsacr --image myapp:v1 --write-enabled true --delete-enabled true
az acr repository update --name btcsacr --image myapp@sha256:436519e38d07508ed8e68214fea9824f4867009c185771fb3e5 --write-enabled true --delete-enabled true
## Generate credentials:
az aks get-credentials --resource-group $RSG_NAME --name $CLUSTER_NAME --overwrite-existing --subscription $SUBS_NAME --admin
az ad user show --id $USER_MAIL
az account set --subscription $SUBS_ID
# return all vm ids where tag alert is missing
vms=$(az vm list --query "[?tags.Alerting == null].id" -o tsv)
#vms=$(az vm list --query "[?storageProfile.osDisk.osType=='Windows'].id" -o tsv)
#vms="
#/subscriptions/325e54e8-9091-467f-b677-5dc9572aa4dc/resourceGroups/Q-SN-HOW-RSG/providers/Microsoft.Compute/virtualMachines/qsnhow01vm
#"
for item in $vms
do
# clean break line
AFTER=`echo $item | sed 's/\\r//g'`
az tag update --operation merge --resource-id $AFTER --tags Monitoring=enabled Alerting=enabled Function=General\ Infrastructure
done
az vm list --query "[?storageProfile.imageReference.offer != 'WindowsServer'].{Name:name, Offer:storageProfile.imageReference.offer}" --output table
az vm image list --offer WindowsServer --sku 2022-datacenter-azure-edition-smalldisk --location switzerlandnorth --all
#!/bin/bash
set -e
## PROVIDE VARIABLES START
newDiskName=disk1
diskZone=3
diskCapacity=850Gi
pvcName=mypvcname
nodeResourceGroup=MC_blabla-aks_switzerlandnorth
## PROVIDE VARIABLES END
## Create the new disk in a zone:
volumeName=$(kubectl get pvc $pvcName -o jsonpath={.spec.volumeName})
diskID=$(az disk list --query '[].id | [?contains(@,`'"$volumeName"'`)]' -o tsv)
az snapshot create \
--resource-group $nodeResourceGroup \
--name ss$newDiskName \
--source $diskID
az disk create --resource-group $nodeResourceGroup --name $newDiskName --source ss$newDiskName --zone $diskZone
newDiskID=$(az disk show --resource-group $nodeResourceGroup --name $newDiskName --query id -o tsv)
printf "The disk was created:\n -name: $newDiskName\n -id: $newDiskID\n -zone: $diskZone\n -rsg: $nodeResourceGroup"
## Create PV:
kubectl apply -f - <<EOT
apiVersion: v1
kind: PersistentVolume
metadata:
name: $newDiskName
labels:
diskname: $newDiskName
spec:
capacity:
storage: $diskCapacity
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: managed-csi
csi:
driver: disk.csi.azure.com
readOnly: false
volumeHandle: $newDiskID
EOT
az network vnet check-ip-address --name vnet --resource-group rsg --ip-address 10.10.193.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment