Skip to content

Commit bac107c

Browse files
Merge pull request #6029 from kiryl-filatau:aks-nodepool-provisioning
PiperOrigin-RevId: 820775455
2 parents baf2761 + 4931f78 commit bac107c

File tree

4 files changed

+96
-17
lines changed

4 files changed

+96
-17
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{% if id == '001' -%}
2+
---
3+
apiVersion: karpenter.azure.com/v1beta1
4+
kind: AKSNodeClass
5+
metadata:
6+
name: aks-managed-class
7+
spec:
8+
imageFamily: "Ubuntu2204"
9+
{%- endif %}
10+
---
11+
apiVersion: karpenter.sh/v1
12+
kind: NodePool
13+
metadata:
14+
name: {{ batch }}-nodepool-{{ id }}
15+
spec:
16+
disruption:
17+
budgets:
18+
- nodes: 30%
19+
consolidateAfter: 0s
20+
consolidationPolicy: WhenEmptyOrUnderutilized
21+
template:
22+
spec:
23+
nodeClassRef:
24+
group: karpenter.azure.com
25+
kind: AKSNodeClass
26+
name: aks-managed-class
27+
requirements:
28+
- key: kubernetes.io/arch
29+
operator: In
30+
values: ["amd64"]
31+
- key: kubernetes.io/os
32+
operator: In
33+
values: ["linux"]
34+
- key: karpenter.sh/capacity-type
35+
operator: In
36+
values: ["on-demand"]
37+
- key: karpenter.azure.com/sku-family
38+
operator: In
39+
values: ["D"]
40+
- key: "group"
41+
operator: In
42+
values:
43+
- pool-{{ batch }}-{{ id }}

perfkitbenchmarker/linux_benchmarks/provisioning_benchmarks/provision_node_pools_benchmark.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@
7777
gke_max_cpu: 520
7878
# (100 init_batch + 20 test_batch + 10 buffer) * 16 GB
7979
gke_max_memory: 2080
80+
# Azure flag for AKS cluster with node auto provisioning feature
81+
azure_aks_auto_node_provisioning: True
8082
"""
8183

8284
INIT_BATCH_NAME = "init-batch"
@@ -102,6 +104,7 @@ def _CreateJobsAndWait(
102104
batch_name,
103105
jobs,
104106
)
107+
105108
apply_start = time.monotonic()
106109
for i in range(jobs):
107110
cluster.AddNodepool(batch_name, pool_id="{:03d}".format(i + 1))

perfkitbenchmarker/providers/azure/azure_kubernetes_service.py

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,16 @@ def _Create(self):
170170
'--nodepool-labels',
171171
f'pkb_nodepool={container_service.DEFAULT_NODEPOOL}',
172172
] + self._GetNodeFlags(self.default_nodepool)
173-
if self._IsAutoscalerEnabled():
174-
cmd += [
175-
'--enable-cluster-autoscaler',
176-
f'--min-count={self.min_nodes}',
177-
f'--max-count={self.max_nodes}',
178-
]
173+
if FLAGS.azure_aks_auto_node_provisioning:
174+
# For provision_node_pools benchmark, add auto provisioning mode
175+
cmd.append('--node-provisioning-mode=auto')
176+
else:
177+
if self._IsAutoscalerEnabled():
178+
cmd += [
179+
'--enable-cluster-autoscaler',
180+
f'--min-count={self.min_nodes}',
181+
f'--max-count={self.max_nodes}',
182+
]
179183

180184
# TODO(pclay): expose quota and capacity errors
181185
# Creating an AKS cluster with a fresh service principal usually fails due
@@ -435,17 +439,40 @@ def ResizeNodePool(
435439

436440
def GetNodePoolNames(self) -> list[str]:
437441
"""Get node pool names for the cluster."""
438-
cmd = [
439-
azure.AZURE_PATH,
440-
'aks',
441-
'nodepool',
442-
'list',
443-
'--cluster-name',
444-
self.name,
445-
] + self.resource_group.args
446-
stdout, _, _ = vm_util.IssueCommand(cmd)
447-
nodepools = json.loads(stdout)
448-
return [nodepool['name'] for nodepool in nodepools]
442+
if FLAGS.azure_aks_auto_node_provisioning:
443+
cmd = [
444+
FLAGS.kubectl,
445+
'--kubeconfig',
446+
FLAGS.kubeconfig,
447+
'get',
448+
'nodepools',
449+
'-o',
450+
'json',
451+
]
452+
stdout, _, _ = vm_util.IssueCommand(cmd)
453+
nodepools = json.loads(stdout).get('items', [])
454+
return [nodepool['metadata']['name'] for nodepool in nodepools]
455+
else:
456+
cmd = [
457+
azure.AZURE_PATH,
458+
'aks',
459+
'nodepool',
460+
'list',
461+
'--cluster-name',
462+
self.name,
463+
] + self.resource_group.args
464+
stdout, _, _ = vm_util.IssueCommand(cmd)
465+
nodepools = json.loads(stdout)
466+
return [nodepool['name'] for nodepool in nodepools]
467+
468+
def AddNodepool(self, batch_name, pool_id):
469+
"""Add a Karpenter NodePool and AKSNodeClass to the AKS cluster."""
470+
self.ApplyManifest(
471+
'provision_node_pools/aks/nodepool.yaml.j2',
472+
batch=batch_name,
473+
id=pool_id,
474+
cluster_name=self.name,
475+
)
449476

450477

451478
class AksAutomaticCluster(AksCluster):

perfkitbenchmarker/providers/azure/flags.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,9 @@
181181
'Enable/Disable secure boot of the VM to allow unsigned operating systems'
182182
' and drivers. Defaults to None to fallback to Azure default behavior',
183183
)
184+
flags.DEFINE_boolean(
185+
'azure_aks_auto_node_provisioning',
186+
False,
187+
'Enable automatic node provisioning for Azure AKS clusters. '
188+
'This is automatically set to True for the provision_node_pools benchmark.',
189+
)

0 commit comments

Comments
 (0)