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

Spot Instances for user pools #611

Merged
merged 13 commits into from
Oct 26, 2023
57 changes: 34 additions & 23 deletions bicep/aksagentpool.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -46,39 +46,50 @@ param osSKU string
@description('Assign a public IP per node')
param enableNodePublicIP bool = false

@description('If the node pool should use VM spot instances')
param spotInstance bool = false

@description('Apply a default sku taint to Windows node pools')
param autoTaintWindows bool = false

var taints = autoTaintWindows ? union(nodeTaints, ['sku=Windows:NoSchedule']) : nodeTaints

var spotProperties = {
scaleSetPriority: 'Spot'
scaleSetEvictionPolicy: 'Delete'
spotMaxPrice: -1
}

resource aks 'Microsoft.ContainerService/managedClusters@2023-08-02-preview' existing = {
name: AksName
}

resource userNodepool 'Microsoft.ContainerService/managedClusters/agentPools@2023-08-02-preview' = {
parent: aks
name: PoolName
properties: {
mode: 'User'
vmSize: agentVMSize
count: agentCount
minCount: autoScale ? agentCount : null
maxCount: autoScale ? agentCountMax : null
enableAutoScaling: autoScale
availabilityZones: !empty(availabilityZones) ? availabilityZones : null
osDiskType: osDiskType
osSKU: osSKU
osDiskSizeGB: osDiskSizeGB
osType: osType
maxPods: maxPods
type: 'VirtualMachineScaleSets'
vnetSubnetID: !empty(subnetId) ? subnetId : null
podSubnetID: !empty(podSubnetID) ? podSubnetID : null
upgradeSettings: {
maxSurge: '33%'
}
nodeTaints: taints
nodeLabels: nodeLabels
enableNodePublicIP: enableNodePublicIP
}
properties: union({
mode: 'User'
vmSize: agentVMSize
count: agentCount
minCount: autoScale ? agentCount : null
maxCount: autoScale ? agentCountMax : null
enableAutoScaling: autoScale
availabilityZones: !empty(availabilityZones) ? availabilityZones : null
osDiskType: osDiskType
osSKU: osSKU
osDiskSizeGB: osDiskSizeGB
osType: osType
maxPods: maxPods
type: 'VirtualMachineScaleSets'
vnetSubnetID: !empty(subnetId) ? subnetId : null
podSubnetID: !empty(podSubnetID) ? podSubnetID : null
upgradeSettings: spotInstance ? {} : {
maxSurge: '33%' //Spot pools can't set max surge
}
nodeTaints: taints
nodeLabels: nodeLabels
enableNodePublicIP: enableNodePublicIP
},
spotInstance ? spotProperties : {}
)
}
4 changes: 4 additions & 0 deletions bicep/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,9 @@ var autoScale = agentCountMax > agentCount
@description('Name for user node pool')
param nodePoolName string = 'npuser01'

@description('Config the user node pool as a spot instance')
param nodePoolSpot bool = false

@description('Allocate pod ips dynamically')
param cniDynamicIpAllocation bool = false

Expand Down Expand Up @@ -1396,6 +1399,7 @@ module userNodePool '../bicep/aksagentpool.bicep' = if (!JustUseSystemPool){
enableNodePublicIP: enableNodePublicIP
osDiskSizeGB: osDiskSizeGB
availabilityZones: availabilityZones
spotInstance: nodePoolSpot
}
}

Expand Down
1 change: 1 addition & 0 deletions helper/src/components/clusterTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export default function ({ defaults, tabValues, updateFn, featureFlag, invalidAr
<MessageBar messageBarType={MessageBarType.error}>{getError(invalidArray, 'osDiskType')}</MessageBar>
}
<TextField label="VM SKU" onChange={(ev, val) => updateFn('vmSize', val)} required errorMessage={getError(invalidArray, 'vmSize')} value={cluster.vmSize} />
<Checkbox checked={cluster.nodePoolSpot} onChange={(ev, val) => updateFn("nodePoolSpot", val)} disabled={cluster.SystemPoolType=='none'} onRenderLabel={() => <Text styles={{ root: { color: 'gray' } }}>Spot Instance</Text>} />
<ChoiceGroup
onChange={(ev, { key }) => updateFn("osDiskType", key)}
selectedKey={cluster.osDiskType}
Expand Down
1 change: 1 addition & 0 deletions helper/src/components/deployTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default function DeployTab({ defaults, updateFn, tabValues, invalidArray,
...(cluster.autoscale && { agentCountMax: cluster.maxCount }),
...(cluster.osType !== defaults.cluster.osType && { osType: cluster.osType}),
...(cluster.osSKU !== defaults.cluster.osSKU && { osSKU: cluster.osSKU}),
...(cluster.SystemPoolType !== 'none' && cluster.nodePoolSpot !== defaults.cluster.nodePoolSpot && { nodePoolSpot: cluster.nodePoolSpot}),
...(cluster.osDiskType === "Managed" && { osDiskType: cluster.osDiskType, ...(cluster.osDiskSizeGB > 0 && { osDiskSizeGB: cluster.osDiskSizeGB }) }),
...(net.vnet_opt === "custom" && {
custom_vnet: true,
Expand Down
3 changes: 2 additions & 1 deletion helper/src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
"enableAzureRBAC": true,
"aadgroupids": "",
"availabilityZones": "no",
"DefenderForContainers" : false
"DefenderForContainers" : false,
"nodePoolSpot": false
},
"addons": {
"logDataCap": 0,
Expand Down
Loading