forked from kubernetes/autoscaler
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathaks-dev-deploy.sh
More file actions
executable file
·103 lines (87 loc) · 3.92 KB
/
aks-dev-deploy.sh
File metadata and controls
executable file
·103 lines (87 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env bash
# Copyright 2024 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -euo pipefail
# This script deploys an AKS cluster with a user node pool and ACR,
# and workload identity to be used for cluster-autoscaler. It creates
# the necessary role assignments to allow the cluster-autoscaler to manage VMSS,
# configures skaffold to use the ACR for the cluster-autoscaler deployment,
# and updates the cluster-autoscaler deployment with the necessary values,
# ready to be used with skaffold dev/run/debug.
# assumed logged in (az login) and subscription set (az account set --subscription ...)
# set resource group and ACR name (preferably unique)
RG=${CODESPACE_NAME:-cluster-autoscaler-test}
ACR_NAME=$(echo "$RG" | tr -d -) # remove hyphens
az group create --name "${RG}" --location westus3 --output none
# deploy AKS & ACR
DEPLOYMENT_JSON=$(az deployment group create --name aks-dev --resource-group "${RG}" \
--template-file ./aks-dev.bicep \
--parameters acrName="${ACR_NAME}")
# get relevant information
RESOURCE_GROUP_MC=$(jq -r ".properties.outputs.nodeResourceGroup.value" <<< "$DEPLOYMENT_JSON")
USER_POOL_NAME=$( jq -r ".properties.outputs.userNodePoolName.value" <<< "$DEPLOYMENT_JSON")
AKS_NAME=$( jq -r ".properties.outputs.aksName.value" <<< "$DEPLOYMENT_JSON")
CAS_UAI_PRINCIPAL=$(jq -r ".properties.outputs.casUserAssignedIdentityPrincipal.value" <<< "$DEPLOYMENT_JSON")
CAS_UAI_CLIENTID=$( jq -r ".properties.outputs.casUserAssignedIdentityClientId.value" <<< "$DEPLOYMENT_JSON")
# confgure dev environment
az aks get-credentials --name "${AKS_NAME}" --resource-group "${RG}"
az acr login --name "${ACR_NAME}"
skaffold config set default-repo "${ACR_NAME}.azurecr.io/cluster-autoscaler"
# create role assignments to let CAS manage VMSS
az role assignment create \
--assignee "${CAS_UAI_PRINCIPAL}" \
--scope "$(az group show --name "${RESOURCE_GROUP_MC}" --query "id" --output tsv)" \
--role "Virtual Machine Contributor" \
--output none
# prep values for and update CAS deployment
VMSS_NAME=$(az resource list \
--tag aks-managed-poolName="${USER_POOL_NAME}" \
--query "[?resourceGroup=='${RESOURCE_GROUP_MC}'].name" \
--output tsv)
TENANT_ID_B64=$(az account show --query tenantId --output tsv | base64)
RESOURCE_GROUP_MC_B64=$(base64 <<< "$RESOURCE_GROUP_MC")
SUBSCRIPTION_ID_B64=$(az account show --query id --output tsv | base64)
export TENANT_ID_B64 RESOURCE_GROUP_MC_B64 VMSS_NAME CAS_UAI_CLIENTID SUBSCRIPTION_ID_B64
yq '(.. | select(tag == "!!str")) |= envsubst(nu)' \
cluster-autoscaler-vmss-wi-dynamic.yaml.tpl > \
cluster-autoscaler-vmss-wi-dynamic.yaml
# create the dynamic node group config (required by the AKS fork)
kubectl apply -f - <<SETTINGS
apiVersion: v1
kind: ConfigMap
metadata:
name: autoscaler-settings
namespace: kube-system
data:
settings.json: |
{
"nodeGroups": [
{
"name": "${VMSS_NAME}",
"minSize": 1,
"maxSize": 10,
"scaleDownPolicy": "Delete"
}
]
}
SETTINGS
# skaffold dev/run/debug
exit
# To recover access after restarting codespace with existing AKS and ACR:
# az login & az account set -n ...
# az aks get-credentials -n cas-test -g $CODESPACE_NAME
# ACR_NAME=$(echo "$CODESPACE_NAME" | tr -d -)
# az acr login -n $ACR_NAME
# skaffold config set default-repo "${ACR_NAME}.azurecr.io/cluster-autoscaler"
# skaffold dev/run/debug