Skip to content

Commit 288c4bd

Browse files
committed
add guidance on using user managed identity with aks cluster
1 parent f4c4330 commit 288c4bd

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

scripts/aks-as-mgmt.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ main() {
7474
echo "AKS_MGMT_DNS_SERVICE_IP: $AKS_MGMT_DNS_SERVICE_IP"
7575
echo "AKS_MGMT_SUBNET_NAME: $AKS_MGMT_SUBNET_NAME"
7676
echo "AKS_MGMT_SUBNET_CIDR: $AKS_MGMT_SUBNET_CIDR"
77-
echo
7877
echo "AZURE_SUBSCRIPTION_ID: $AZURE_SUBSCRIPTION_ID"
7978
echo "AZURE_CLIENT_ID: $AZURE_CLIENT_ID"
8079
echo "AZURE_TENANT_ID: $AZURE_TENANT_ID"
@@ -86,7 +85,6 @@ main() {
8685
echo "MANAGED_IDENTITY_RG: $MANAGED_IDENTITY_RG"
8786
echo "ASO_CREDENTIAL_SECRET_MODE: $ASO_CREDENTIAL_SECRET_MODE"
8887
echo "SKIP_AKS_CREATE: $SKIP_AKS_CREATE"
89-
echo "IS_DEV_BOX: $IS_DEV_BOX"
9088
echo "AZURE_CLIENT_ID_USER_ASSIGNED_IDENTITY: $AZURE_CLIENT_ID_USER_ASSIGNED_IDENTITY"
9189
echo "AZURE_OBJECT_ID_USER_ASSIGNED_IDENTITY: $AZURE_OBJECT_ID_USER_ASSIGNED_IDENTITY"
9290
echo "AZURE_USER_ASSIGNED_IDENTITY_RESOURCE_ID: $AZURE_USER_ASSIGNED_IDENTITY_RESOURCE_ID"
@@ -135,6 +133,7 @@ create_aks_cluster() {
135133
--node-vm-size "${AKS_NODE_VM_SIZE}" \
136134
--node-resource-group "${AKS_NODE_RESOURCE_GROUP}" \
137135
--vm-set-type VirtualMachineScaleSets \
136+
--enable-managed-identity \
138137
--generate-ssh-keys \
139138
--network-plugin azure \
140139
--vnet-subnet-id "/subscriptions/${AZURE_SUBSCRIPTION_ID}/resourceGroups/${AKS_RESOURCE_GROUP}/providers/Microsoft.Network/virtualNetworks/${AKS_MGMT_VNET_NAME}/subnets/${AKS_MGMT_SUBNET_NAME}" \
@@ -159,8 +158,10 @@ create_aks_cluster() {
159158
az aks get-credentials --name "${MGMT_CLUSTER_NAME}" --resource-group "${AKS_RESOURCE_GROUP}" \
160159
--overwrite-existing --only-show-errors
161160

162-
if [[ "${IS_DEV_BOX}" == "true" ]]; then
163-
echo "using the Managed Identity created by the user instead of the one created by AKS"
161+
if [[ -n "${AZURE_CLIENT_ID_USER_ASSIGNED_IDENTITY:-}" ]] && \
162+
[[ -n "${AZURE_OBJECT_ID_USER_ASSIGNED_IDENTITY:-}" ]] && \
163+
[[ -n "${AZURE_USER_ASSIGNED_IDENTITY_RESOURCE_ID:-}" ]]; then
164+
echo "using user-provided Managed Identity"
164165
# echo "fetching Client ID for ${MGMT_CLUSTER_NAME}"
165166
AKS_MI_CLIENT_ID=${AZURE_CLIENT_ID_USER_ASSIGNED_IDENTITY}
166167
export AKS_MI_CLIENT_ID
@@ -184,6 +185,14 @@ create_aks_cluster() {
184185
USER_IDENTITY=$MANAGED_IDENTITY_NAME
185186
export USER_IDENTITY
186187

188+
echo "assigning user-assigned managed identity to the AKS cluster"
189+
az aks update --resource-group "${AKS_RESOURCE_GROUP}" \
190+
--name "${MGMT_CLUSTER_NAME}" \
191+
--enable-managed-identity \
192+
--assign-identity "${AKS_MI_RESOURCE_ID}" \
193+
--assign-kubelet-identity "${AKS_MI_RESOURCE_ID}" \
194+
--output none --only-show-errors --yes
195+
187196
else
188197
# echo "fetching Client ID for ${MGMT_CLUSTER_NAME}"
189198
AKS_MI_CLIENT_ID=$(az aks show -n "${MGMT_CLUSTER_NAME}" -g "${AKS_RESOURCE_GROUP}" --output json \

0 commit comments

Comments
 (0)