Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Availability Zone selection when provisioning AKS and zone-redundant resources #1290

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions dev-infrastructure/modules/aks-cluster-base.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ param dnsServiceIP string = '10.130.0.10'
// Passed Params and Overrides
param location string

@description('List of Availability Zones to use for the AKS cluster')
param locationAvailabilityZones array
var locationHasAvailabilityZones = length(locationAvailabilityZones) > 0

@description('Set to true to prevent resources from being pruned after 48 hours')
param persist bool = false

Expand Down Expand Up @@ -58,13 +62,6 @@ var istioIngressGatewayIPAddressIPTagsArray = [
}
]

@description('List of Availability Zones for zone-redundant resources')
param zoneRedundancyZones array = [
'1'
'2'
'3'
]

@maxLength(24)
param aksKeyVaultName string

Expand Down Expand Up @@ -255,7 +252,7 @@ module istioIngressGatewayIPAddress '../modules/network/publicipaddress.bicep' =
name: istioIngressGatewayIPAddressName
ipTags: istioIngressGatewayIPAddressIPTagsArray
location: location
zones: zoneRedundancyZones
zones: locationHasAvailabilityZones ? locationAvailabilityZones : null
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could set this as a variable at the top, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it reads better without another variable which may not convey the two possible outcomes

// Role Assignment needed for the public IP address to be used on the Load Balancer
roleAssignmentProperties: {
principalId: aksClusterUserDefinedManagedIdentity.properties.principalId
Expand All @@ -272,7 +269,7 @@ module aksClusterOutboundIPAddress '../modules/network/publicipaddress.bicep' =
name: aksClusterOutboundIPAddressName
ipTags: aksClusterOutboundIPAddressIPTagsArray
location: location
zones: zoneRedundancyZones
zones: locationHasAvailabilityZones ? locationAvailabilityZones : null
// Role Assignment needed for the public IP address to be used on the Load Balancer
roleAssignmentProperties: {
principalId: aksClusterUserDefinedManagedIdentity.properties.principalId
Expand Down Expand Up @@ -338,7 +335,7 @@ resource aksCluster 'Microsoft.ContainerService/managedClusters@2024-04-02-previ
vnetSubnetID: aksNodeSubnet.id
podSubnetID: aksPodSubnet.id
maxPods: 100
availabilityZones: zoneRedundancyZones
availabilityZones: locationHasAvailabilityZones ? locationAvailabilityZones : null
securityProfile: {
enableSecureBoot: false
enableVTPM: false
Expand Down Expand Up @@ -492,9 +489,7 @@ resource userAgentPools 'Microsoft.ContainerService/managedClusters/agentPools@2
vnetSubnetID: aksNodeSubnet.id
podSubnetID: aksPodSubnet.id
maxPods: 225
availabilityZones: [
'${(i + 1)}'
]
availabilityZones: locationHasAvailabilityZones ? [locationAvailabilityZones[i]] : null
securityProfile: {
enableSecureBoot: false
enableVTPM: false
Expand Down
18 changes: 9 additions & 9 deletions dev-infrastructure/scripts/list-az-regions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ az rest \
--method get \
--uri "/subscriptions/$(az account show --query id --output tsv)/locations?api-version=2024-11-01" \
| jq -r '
# First, print items with availabilityZoneMappings set
"Regions with Availability Zones:",
(.value[] | select(.availabilityZoneMappings) | .name),
"",
# Then, print items without availabilityZoneMappings
"Regions without Availability Zones:",
(.value[] | select(.availabilityZoneMappings | not) | .name)
'

reduce .value[] as $item ({}; .[$item.name] = {
availabilityZones: (
if $item.availabilityZoneMappings then
$item.availabilityZoneMappings | map(.logicalZone)
else
[]
end
)
}) | to_entries | sort_by(.key) | from_entries'
Loading
Loading