|
16 | 16 | SERVICES_POOL="services"
|
17 | 17 | WORKSPACES_POOL="workspaces"
|
18 | 18 |
|
19 |
| -K8S_NODE_VM_SIZE=${K8S_NODE_VM_SIZE:="Standard_D4_v3"} |
| 19 | +K8S_NODE_VM_SIZE=${K8S_NODE_VM_SIZE:="Standard_DS3_v2"} |
20 | 20 |
|
21 | 21 | function check_prerequisites() {
|
22 | 22 | if [ -z "${AZURE_SUBSCRIPTION_ID}" ]; then
|
@@ -141,6 +141,7 @@ function install() {
|
141 | 141 | setup_managed_dns
|
142 | 142 | setup_mysql_database
|
143 | 143 | setup_storage
|
| 144 | + setup_backup |
144 | 145 | output_config
|
145 | 146 | }
|
146 | 147 |
|
@@ -366,6 +367,86 @@ function setup_mysql_database() {
|
366 | 367 | --start-ip-address "0.0.0.0"
|
367 | 368 | }
|
368 | 369 |
|
| 370 | +function setup_backup() { |
| 371 | + if [ -n "${BACKUPS_ENABLED}" ] && [ "${BACKUPS_ENABLED}" == "true" ]; then |
| 372 | + echo "Configuring backups..." |
| 373 | + |
| 374 | + # Based from https://github.com/vmware-tanzu/velero-plugin-for-microsoft-azure#setup |
| 375 | + BACKUP_ACCOUNT="${STORAGE_ACCOUNT_NAME}backup" |
| 376 | + if [ "$(az storage account show --name ${BACKUP_ACCOUNT} --resource-group ${RESOURCE_GROUP} --query "name == '${BACKUP_ACCOUNT}'" || echo "empty")" == "true" ]; then |
| 377 | + echo "Backup storage account exists..." |
| 378 | + else |
| 379 | + echo "Create backup storage account..." |
| 380 | + az storage account create \ |
| 381 | + --name "${STORAGE_ACCOUNT_NAME}backup" \ |
| 382 | + --resource-group "${RESOURCE_GROUP}" \ |
| 383 | + --location "${LOCATION}" \ |
| 384 | + --sku Standard_GRS \ |
| 385 | + --encryption-services blob \ |
| 386 | + --https-only true \ |
| 387 | + --kind BlobStorage \ |
| 388 | + --access-tier Hot |
| 389 | + fi |
| 390 | + |
| 391 | + ACCOUNT_KEY="$(az storage account keys list --resource-group "${RESOURCE_GROUP}" --account-name "${BACKUP_ACCOUNT}" --query "[0].value" -o tsv)" |
| 392 | + |
| 393 | + BLOB_CONTAINER="velero" |
| 394 | + if [ "$(az storage container show --account-name ${BACKUP_ACCOUNT} --name ${BLOB_CONTAINER} --account-key="${ACCOUNT_KEY}" --query "name == '${BLOB_CONTAINER}'" || echo "empty")" == "true" ]; then |
| 395 | + echo "Backup storage container exists..." |
| 396 | + else |
| 397 | + echo "Create backup storage container..." |
| 398 | + az storage container create \ |
| 399 | + -n "${BLOB_CONTAINER}" \ |
| 400 | + --account-key="${ACCOUNT_KEY}" \ |
| 401 | + --public-access off \ |
| 402 | + --account-name "${BACKUP_ACCOUNT}" |
| 403 | + fi |
| 404 | + |
| 405 | + kubectl apply -f https://raw.githubusercontent.com/Azure/aad-pod-identity/v1.8.9/deploy/infra/deployment-rbac.yaml |
| 406 | + |
| 407 | + IDENTITY_NAME=velero |
| 408 | + IDENTITY_RESOURCE_ID=$(az aks show --name "${CLUSTER_NAME}" --resource-group "${RESOURCE_GROUP}" --query "identityProfile.kubeletidentity.resourceId" -o tsv) |
| 409 | + IDENTITY_CLIENT_ID=$(az aks show --name "${CLUSTER_NAME}" --resource-group "${RESOURCE_GROUP}" --query "identityProfile.kubeletidentity.clientId" -o tsv) |
| 410 | + |
| 411 | + cat <<EOF | kubectl apply -f - |
| 412 | +apiVersion: "aadpodidentity.k8s.io/v1" |
| 413 | +kind: AzureIdentity |
| 414 | +metadata: |
| 415 | + name: $IDENTITY_NAME |
| 416 | +spec: |
| 417 | + type: 0 |
| 418 | + resourceID: $IDENTITY_RESOURCE_ID |
| 419 | + clientID: $IDENTITY_CLIENT_ID |
| 420 | +EOF |
| 421 | + |
| 422 | + cat <<EOF | kubectl apply -f - |
| 423 | +apiVersion: "aadpodidentity.k8s.io/v1" |
| 424 | +kind: AzureIdentityBinding |
| 425 | +metadata: |
| 426 | + name: $IDENTITY_NAME-binding |
| 427 | +spec: |
| 428 | + azureIdentity: $IDENTITY_NAME |
| 429 | + selector: $IDENTITY_NAME |
| 430 | +EOF |
| 431 | + |
| 432 | + cat << EOF > ./credentials-velero |
| 433 | +AZURE_SUBSCRIPTION_ID=${AZURE_SUBSCRIPTION_ID} |
| 434 | +AZURE_RESOURCE_GROUP=${RESOURCE_GROUP} |
| 435 | +AZURE_CLOUD_NAME=AzurePublicCloud |
| 436 | +EOF |
| 437 | + |
| 438 | + velero install \ |
| 439 | + --provider azure \ |
| 440 | + --plugins velero/velero-plugin-for-microsoft-azure:v1.4.0 \ |
| 441 | + --bucket "${BLOB_CONTAINER}" \ |
| 442 | + --secret-file ./credentials-velero \ |
| 443 | + --backup-location-config "resourceGroup=${RESOURCE_GROUP},storageAccount=${BACKUP_ACCOUNT}" \ |
| 444 | + --snapshot-location-config apiTimeout=30m \ |
| 445 | + --use-restic \ |
| 446 | + --wait |
| 447 | + fi |
| 448 | +} |
| 449 | + |
369 | 450 | function setup_storage() {
|
370 | 451 | if [ "$(az storage account show --name ${STORAGE_ACCOUNT_NAME} --resource-group ${RESOURCE_GROUP} --query "name == '${STORAGE_ACCOUNT_NAME}'" || echo "empty")" == "true" ]; then
|
371 | 452 | echo "Storage account exists..."
|
|
0 commit comments