Reset the SPN of a K8s cluster

PHOTO EMBED

Mon Oct 25 2021 17:48:18 GMT+0000 (Coordinated Universal Time)

Saved by @KobeLenjou #powershell #k8s #spn #reset #expired #expire

$RG = "di-platform-dev-rg-execution"
$NAME = "di-platform-dev-k8s-exe"

$SP_ID=$(az aks show --resource-group "$RG" --name "$NAME" \
    --query servicePrincipalProfile.clientId -o tsv)

az ad sp credential list --id "$SP_ID" --query "[].endDate" -o tsv

$SP_ID=$(az aks show --resource-group "$RG" --name "$NAME" \
    --query servicePrincipalProfile.clientId -o tsv)

$SP_SECRET=$(az ad sp credential reset --name "$SP_ID" --query password -o tsv)

az aks update-credentials \
    --resource-group "$RG" \
    --name $NAME" \
    --reset-service-principal \
    --service-principal "$SP_ID" \
    --client-secret "$SP_SECRET"
content_copyCOPY

https://docs.microsoft.com/en-us/azure/aks/update-credentials?WT.mc_id=Portal-Microsoft_Azure_Expert#update-aks-cluster-with-new-service-principal-credentials