-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathaksCluster.bicep
940 lines (801 loc) · 33.7 KB
/
aksCluster.bicep
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
// Parameters
@description('Specifies the name of the AKS cluster.')
param name string = 'aks-${uniqueString(resourceGroup().id)}'
@description('Specifies whether to enable API server VNET integration for the cluster or not.')
param enableVnetIntegration bool = true
@description('Specifies the name of the existing virtual network.')
param virtualNetworkName string
@description('Specifies the name of the subnet hosting the worker nodes of the default system agent pool of the AKS cluster.')
param systemAgentPoolSubnetName string = 'SystemSubnet'
@description('Specifies the name of the subnet hosting the worker nodes of the user agent pool of the AKS cluster.')
param userAgentPoolSubnetName string = 'UserSubnet'
@description('Specifies the name of the subnet hosting the pods running in the AKS cluster.')
param podSubnetName string = 'PodSubnet'
@description('Specifies the name of the subnet delegated to the API server when configuring the AKS cluster to use API server VNET integration.')
param apiServerSubnetName string = 'ApiServerSubnet'
@description('Specifies the name of the AKS user-defined managed identity.')
param managedIdentityName string
@description('Specifies the DNS prefix specified when creating the managed cluster.')
param dnsPrefix string = name
@description('Specifies the network plugin used for building Kubernetes network. - azure or kubenet.')
@allowed([
'azure'
'kubenet'
])
param networkPlugin string = 'azure'
@description('Specifies the Network plugin mode used for building the Kubernetes network.')
@allowed([
''
'overlay'
])
param networkPluginMode string = ''
@description('Specifies the network mode. This cannot be specified if networkPlugin is anything other than azure.')
@allowed([
'bridge'
'transparent'
])
param networkMode string = 'transparent'
@description('Specifies the network policy used for building Kubernetes network. - calico or azure')
@allowed([
'azure'
'calico'
'cilium'
'none'
])
param networkPolicy string = 'azure'
@description('Specifies the network dataplane used in the Kubernetes cluster..')
@allowed([
'azure'
'cilium'
])
param networkDataplane string = 'azure'
@description('Specifies the CIDR notation IP range from which to assign pod IPs when kubenet is used.')
param podCidr string = '192.168.0.0/16'
@description('A CIDR notation IP range from which to assign service cluster IPs. It must not overlap with any Subnet IP ranges.')
param serviceCidr string = '172.16.0.0/16'
@description('Specifies the IP address assigned to the Kubernetes DNS service. It must be within the Kubernetes service address range specified in serviceCidr.')
param dnsServiceIP string = '172.16.0.10'
@description('Specifies the sku of the load balancer used by the virtual machine scale sets used by nodepools.')
@allowed([
'basic'
'standard'
])
param loadBalancerSku string = 'standard'
@description('Specifies the type of the managed inbound Load Balancer BackendPool.')
@allowed([
'nodeIP'
'nodeIPConfiguration'
])
param loadBalancerBackendPoolType string = 'nodeIPConfiguration'
@description('Specifies Advanced Networking profile for enabling observability on a cluster. Note that enabling advanced networking features may incur additional costs. For more information see aka.ms/aksadvancednetworking.')
param advancedNetworking object = {
observability: {
enabled: true
tlsManagement: 'Managed'
}
security: networkDataplane == 'cilium'
? {
fqdnPolicy: {
enabled: true
}
}
: null
}
@description('Specifies outbound (egress) routing method. - loadBalancer or userDefinedRouting.')
@allowed([
'loadBalancer'
'managedNATGateway'
'userAssignedNATGateway'
'userDefinedRouting'
])
param outboundType string = 'loadBalancer'
@description('Specifies the tier of a managed cluster SKU: Paid or Free')
@allowed([
'Free'
'Standard'
'Premium'
])
param skuTier string = 'Free'
@description('Specifies the version of Kubernetes specified when creating the managed cluster.')
param kubernetesVersion string = '1.18.8'
@description('Specifies the administrator username of Linux virtual machines.')
param adminUsername string = 'azureuser'
@description('Specifies the SSH RSA public key string for the Linux nodes.')
param sshPublicKey string
@description('Specifies the tenant id of the Azure Active Directory used by the AKS cluster for authentication.')
param aadProfileTenantId string = subscription().tenantId
@description('Specifies the AAD group object IDs that will have admin role of the cluster.')
param aadProfileAdminGroupObjectIDs array = []
@description('Specifies the node OS upgrade channel. The default is Unmanaged, but may change to either NodeImage or SecurityPatch at GA. .')
@allowed([
'NodeImage'
'None'
'SecurityPatch'
'Unmanaged'
])
param nodeOSUpgradeChannel string = 'Unmanaged'
@description('Specifies the upgrade channel for auto upgrade. Allowed values include rapid, stable, patch, node-image, none.')
@allowed([
'rapid'
'stable'
'patch'
'node-image'
'none'
])
param upgradeChannel string = 'stable'
@description('Specifies whether to create the cluster as a private cluster or not.')
param enablePrivateCluster bool = true
@description('Specifies the Private DNS Zone mode for private cluster. When the value is equal to None, a Public DNS Zone is used in place of a Private DNS Zone')
param privateDNSZone string = 'none'
@description('Specifies whether to create additional public FQDN for private cluster or not.')
param enablePrivateClusterPublicFQDN bool = true
@description('Specifies whether to enable managed AAD integration.')
param aadProfileManaged bool = true
@description('Specifies whether to to enable Azure RBAC for Kubernetes authorization.')
param aadProfileEnableAzureRBAC bool = true
@description('Specifies the unique name of of the system node pool profile in the context of the subscription and resource group.')
param systemAgentPoolName string = 'nodepool1'
@description('Specifies the vm size of nodes in the system node pool.')
param systemAgentPoolVmSize string = 'Standard_DS5_v2'
@description('Specifies the OS Disk Size in GB to be used to specify the disk size for every machine in the system agent pool. If you specify 0, it will apply the default osDisk size according to the vmSize specified.')
param systemAgentPoolOsDiskSizeGB int = 100
@description('Specifies the OS disk type to be used for machines in a given agent pool. Allowed values are \'Ephemeral\' and \'Managed\'. If unspecified, defaults to \'Ephemeral\' when the VM supports ephemeral OS and has a cache disk larger than the requested OSDiskSizeGB. Otherwise, defaults to \'Managed\'. May not be changed after creation. - Managed or Ephemeral')
@allowed([
'Ephemeral'
'Managed'
])
param systemAgentPoolOsDiskType string = 'Ephemeral'
@description('Specifies the number of agents (VMs) to host docker containers in the system node pool. Allowed values must be in the range of 1 to 100 (inclusive). The default value is 1.')
param systemAgentPoolAgentCount int = 3
@description('Specifies the OS type for the vms in the system node pool. Choose from Linux and Windows. Default to Linux.')
@allowed([
'Linux'
'Windows'
])
param systemAgentPoolOsType string = 'Linux'
@description('Specifies the OS SKU used by the system agent pool. If not specified, the default is Ubuntu if OSType=Linux or Windows2019 if OSType=Windows. And the default Windows OSSKU will be changed to Windows2022 after Windows2019 is deprecated.')
@allowed([
'Ubuntu'
'Windows2019'
'Windows2022'
'AzureLinux'
])
param systemAgentPoolOsSKU string = 'Ubuntu'
@description('Specifies the maximum number of pods that can run on a node in the system node pool. The maximum number of pods per node in an AKS cluster is 250. The default maximum number of pods per node varies between kubenet and Azure CNI networking, and the method of cluster deployment.')
param systemAgentPoolMaxPods int = 30
@description('Specifies the maximum number of nodes for auto-scaling for the system node pool.')
param systemAgentPoolMaxCount int = 5
@description('Specifies the minimum number of nodes for auto-scaling for the system node pool.')
param systemAgentPoolMinCount int = 3
@description('Specifies whether to enable auto-scaling for the system node pool.')
param systemAgentPoolEnableAutoScaling bool = true
@description('Specifies the virtual machine scale set priority in the system node pool: Spot or Regular.')
@allowed([
'Spot'
'Regular'
])
param systemAgentPoolScaleSetPriority string = 'Regular'
@description('Specifies the ScaleSetEvictionPolicy to be used to specify eviction policy for spot virtual machine scale set. Default to Delete. Allowed values are Delete or Deallocate.')
@allowed([
'Delete'
'Deallocate'
])
param systemAgentPoolScaleSetEvictionPolicy string = 'Delete'
@description('Specifies the Agent pool node labels to be persisted across all nodes in the system node pool.')
param systemAgentPoolNodeLabels object = {}
@description('Specifies the taints added to new nodes during node pool create and scale. For example, key=value:NoSchedule.')
param systemAgentPoolNodeTaints array = []
@description('Determines the placement of emptyDir volumes, container runtime data root, and Kubelet ephemeral storage.')
@allowed([
'OS'
'Temporary'
])
param systemAgentPoolKubeletDiskType string = 'OS'
@description('Specifies the type for the system node pool: VirtualMachineScaleSets or AvailabilitySet')
@allowed([
'VirtualMachineScaleSets'
'AvailabilitySet'
])
param systemAgentPoolType string = 'VirtualMachineScaleSets'
@description('Specifies the availability zones for the agent nodes in the system node pool. Requirese the use of VirtualMachineScaleSets as node pool type.')
param systemAgentPoolAvailabilityZones array = [
'1'
'2'
'3'
]
@description('Specified the scale down mode that effects the cluster autoscaler behavior. If not specified, it defaults to Delete.')
@allowed([
'Delete'
'Deallocate'
])
param systemAgentPoolScaleDownMode string = 'Delete'
@description('Possible values are any decimal value greater than zero or -1 which indicates the willingness to pay any on-demand price. For more details on spot pricing, see spot VMs pricing')
param systemAgentPoolSpotMaxPrice int = -1
@description('Specifies the unique name of of the user node pool profile in the context of the subscription and resource group.')
param userAgentPoolName string = 'nodepool1'
@description('Specifies the vm size of nodes in the user node pool.')
param userAgentPoolVmSize string = 'Standard_DS5_v2'
@description('Specifies the OS Disk Size in GB to be used to specify the disk size for every machine in the system agent pool. If you specify 0, it will apply the default osDisk size according to the vmSize specified..')
param userAgentPoolOsDiskSizeGB int = 100
@description('Specifies the OS disk type to be used for machines in a given agent pool. Allowed values are \'Ephemeral\' and \'Managed\'. If unspecified, defaults to \'Ephemeral\' when the VM supports ephemeral OS and has a cache disk larger than the requested OSDiskSizeGB. Otherwise, defaults to \'Managed\'. May not be changed after creation. - Managed or Ephemeral')
@allowed([
'Ephemeral'
'Managed'
])
param userAgentPoolOsDiskType string = 'Ephemeral'
@description('Specifies the number of agents (VMs) to host docker containers in the user node pool. Allowed values must be in the range of 1 to 100 (inclusive). The default value is 1.')
param userAgentPoolAgentCount int = 3
@description('Specifies the OS type for the vms in the user node pool. Choose from Linux and Windows. Default to Linux.')
@allowed([
'Linux'
'Windows'
])
param userAgentPoolOsType string = 'Linux'
@description('Specifies the OS SKU used by the system agent pool. If not specified, the default is Ubuntu if OSType=Linux or Windows2019 if OSType=Windows. And the default Windows OSSKU will be changed to Windows2022 after Windows2019 is deprecated.')
@allowed([
'Ubuntu'
'Windows2019'
'Windows2022'
'AzureLinux'
])
param userAgentPoolOsSKU string = 'Ubuntu'
@description('Specifies the maximum number of pods that can run on a node in the user node pool. The maximum number of pods per node in an AKS cluster is 250. The default maximum number of pods per node varies between kubenet and Azure CNI networking, and the method of cluster deployment.')
param userAgentPoolMaxPods int = 30
@description('Specifies the maximum number of nodes for auto-scaling for the user node pool.')
param userAgentPoolMaxCount int = 5
@description('Specifies the minimum number of nodes for auto-scaling for the user node pool.')
param userAgentPoolMinCount int = 3
@description('Specifies whether to enable auto-scaling for the user node pool.')
param userAgentPoolEnableAutoScaling bool = true
@description('Specifies the virtual machine scale set priority in the user node pool: Spot or Regular.')
@allowed([
'Spot'
'Regular'
])
param userAgentPoolScaleSetPriority string = 'Regular'
@description('Specifies the ScaleSetEvictionPolicy to be used to specify eviction policy for spot virtual machine scale set. Default to Delete. Allowed values are Delete or Deallocate.')
@allowed([
'Delete'
'Deallocate'
])
param userAgentPoolScaleSetEvictionPolicy string = 'Delete'
@description('Specifies the Agent pool node labels to be persisted across all nodes in the user node pool.')
param userAgentPoolNodeLabels object = {}
@description('Specifies the taints added to new nodes during node pool create and scale. For example, key=value:NoSchedule.')
@allowed([
'OS'
'Temporary'
])
param userAgentPoolNodeTaints array = []
@description('Determines the placement of emptyDir volumes, container runtime data root, and Kubelet ephemeral storage.')
param userAgentPoolKubeletDiskType string = 'OS'
@description('Specifies the type for the user node pool: VirtualMachineScaleSets or AvailabilitySet')
@allowed([
'VirtualMachineScaleSets'
'AvailabilitySet'
])
param userAgentPoolType string = 'VirtualMachineScaleSets'
@description('Specifies the availability zones for the agent nodes in the user node pool. Requirese the use of VirtualMachineScaleSets as node pool type.')
param userAgentPoolAvailabilityZones array = [
'1'
'2'
'3'
]
@description('Specified the scale down mode that effects the cluster autoscaler behavior. If not specified, it defaults to Delete.')
@allowed([
'Delete'
'Deallocate'
])
param userAgentPoolScaleDownMode string = 'Delete'
@description('Possible values are any decimal value greater than zero or -1 which indicates the willingness to pay any on-demand price. For more details on spot pricing, see spot VMs pricing')
param userAgentPoolSpotMaxPrice int = -1
@description('Specifies whether the httpApplicationRouting add-on is enabled or not.')
param httpApplicationRoutingEnabled bool = false
@description('Specifies whether the Istio Service Mesh add-on is enabled or not.')
param istioServiceMeshEnabled bool = false
@description('Specifies whether the Istio Ingress Gateway is enabled or not.')
param istioIngressGatewayEnabled bool = false
@description('Specifies the type of the Istio Ingress Gateway.')
@allowed([
'Internal'
'External'
])
param istioIngressGatewayType string = 'External'
@description('Specifies whether the Kubernetes Event-Driven Autoscaler (KEDA) add-on is enabled or not.')
param kedaEnabled bool = false
@description('Specifies whether the Dapr extension is enabled or not.')
param daprEnabled bool = false
@description('Enable high availability (HA) mode for the Dapr control plane')
param daprHaEnabled bool = false
@description('Specifies whether the Flux V2 extension is enabled or not.')
param fluxGitOpsEnabled bool = false
@description('Specifies whether the Vertical Pod Autoscaler is enabled or not.')
param verticalPodAutoscalerEnabled bool = false
@description('Specifies whether the aciConnectorLinux add-on is enabled or not.')
param aciConnectorLinuxEnabled bool = false
@description('Specifies whether the azurepolicy add-on is enabled or not.')
param azurePolicyEnabled bool = true
@description('Specifies whether the Azure Key Vault Provider for Secrets Store CSI Driver addon is enabled or not.')
param azureKeyvaultSecretsProviderEnabled bool = true
@description('Specifies the name of the Key Vault resource.')
param keyVaultName string
@description('Specifies whether the kubeDashboard add-on is enabled or not.')
param kubeDashboardEnabled bool = false
@description('Specifies whether the pod identity addon is enabled..')
param podIdentityProfileEnabled bool = false
@description('Specifies whether the OIDC issuer is enabled.')
param oidcIssuerProfileEnabled bool = true
@description('Specifies the scan interval of the auto-scaler of the AKS cluster.')
param autoScalerProfileScanInterval string = '10s'
@description('Specifies the scale down delay after add of the auto-scaler of the AKS cluster.')
param autoScalerProfileScaleDownDelayAfterAdd string = '10m'
@description('Specifies the scale down delay after delete of the auto-scaler of the AKS cluster.')
param autoScalerProfileScaleDownDelayAfterDelete string = '20s'
@description('Specifies scale down delay after failure of the auto-scaler of the AKS cluster.')
param autoScalerProfileScaleDownDelayAfterFailure string = '3m'
@description('Specifies the scale down unneeded time of the auto-scaler of the AKS cluster.')
param autoScalerProfileScaleDownUnneededTime string = '10m'
@description('Specifies the scale down unready time of the auto-scaler of the AKS cluster.')
param autoScalerProfileScaleDownUnreadyTime string = '20m'
@description('Specifies the utilization threshold of the auto-scaler of the AKS cluster.')
param autoScalerProfileUtilizationThreshold string = '0.5'
@description('Specifies the max graceful termination time interval in seconds for the auto-scaler of the AKS cluster.')
param autoScalerProfileMaxGracefulTerminationSec string = '600'
@description('Specifies the type of node pool expander to be used in scale up. Possible values: most-pods, random, least-waste, priority.')
@allowed([
'least-waste'
'most-pods'
'priority'
'random'
])
param autoScalerProfileExpander string = 'random'
@description('Specifies the resource id of the Log Analytics workspace.')
param workspaceId string
@description('Specifies the location.')
param location string = resourceGroup().location
@description('Specifies the resource tags.')
param tags object
@description('Specifies whether to enable the Azure Blob CSI Driver. The default value is false.')
param blobCSIDriverEnabled bool = false
@description('Specifies whether to enable the Azure Disk CSI Driver. The default value is true.')
param diskCSIDriverEnabled bool = true
@description('Specifies whether to enable the Azure File CSI Driver. The default value is true.')
param fileCSIDriverEnabled bool = true
@description('Specifies whether to enable the Snapshot Controller. The default value is true.')
param snapshotControllerEnabled bool = true
@description('Specifies whether to enable Defender threat detection. The default value is false.')
param defenderSecurityMonitoringEnabled bool = false
@description('Specifies whether to enable ImageCleaner on AKS cluster. The default value is false.')
param imageCleanerEnabled bool = false
@description('Specifies whether ImageCleaner scanning interval in hours.')
param imageCleanerIntervalHours int = 24
@description('Specifies whether to enable Node Restriction. The default value is false.')
param nodeRestrictionEnabled bool = false
@description('Specifies whether to enable Workload Identity. The default value is false.')
param workloadIdentityEnabled bool = false
@description('Specifies the Azure Monitor Container Insights Profile for Kubernetes Events, Inventory and Container stdout & stderr logs etc. See aka.ms/AzureMonitorContainerInsights for an overview.')
param containerInsights object = {
disableCustomMetrics: false
disablePrometheusMetricsScraping: false
enabled: true
logAnalyticsWorkspaceResourceId: workspaceId
}
@description('Specifies whether to create or not Azure Monitor managed service for Prometheus and Azure Managed Grafana resources.')
param prometheusAndGrafanaEnabled bool = false
@description('Specifies a comma-separated list of additional Kubernetes label keys that will be used in the resource labels metric.')
param metricAnnotationsAllowList string = ''
@description('Specifies a comma-separated list of Kubernetes annotations keys that will be used in the resource labels metric.')
param metricLabelsAllowlist string = ''
@description('Specifies the IP families are used to determine single-stack or dual-stack clusters. For single-stack, the expected value is IPv4. For dual-stack, the expected values are IPv4 and IPv6.')
param ipFamilies array = ['IPv4']
@description('Specifies whether the managed NGINX Ingress Controller application routing addon is enabled.')
param webAppRoutingEnabled bool = true
@description('Specifies the ingress type for the default NginxIngressController custom resource')
@allowed([
'AnnotationControlled'
'External'
'Internal'
'None'
])
param nginxDefaultIngressControllerType string = 'AnnotationControlled'
@description('Specifies the name of the public DNS zone used by the managed NGINX Ingress Controller, when enabled.')
param dnsZoneName string
@description('Specifies the resource group name of the public DNS zone used by the managed NGINX Ingress Controller, when enabled.')
param dnsZoneResourceGroupName string
@description('Specifies the object id of an Azure Active Directory user. In general, this the object id of the system administrator who deploys the Azure resources.')
param userId string = ''
// Variables
var diagnosticSettingsName = 'diagnosticSettings'
var logCategories = [
'kube-apiserver'
'kube-audit'
'kube-audit-admin'
'kube-controller-manager'
'kube-scheduler'
'cluster-autoscaler'
'cloud-controller-manager'
'guard'
'csi-azuredisk-controller'
'csi-azurefile-controller'
'csi-snapshot-controller'
]
var metricCategories = [
'AllMetrics'
]
var logs = [
for category in logCategories: {
category: category
enabled: true
retentionPolicy: {
enabled: true
days: 0
}
}
]
var metrics = [
for category in metricCategories: {
category: category
enabled: true
retentionPolicy: {
enabled: true
days: 0
}
}
]
// Resources
resource managedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-07-31-preview' existing = {
name: managedIdentityName
}
resource virtualNetwork 'Microsoft.Network/virtualNetworks@2023-04-01' existing = {
name: virtualNetworkName
}
resource systemAgentPoolSubnet 'Microsoft.Network/virtualNetworks/subnets@2023-04-01' existing = {
parent: virtualNetwork
name: systemAgentPoolSubnetName
}
resource userAgentPoolSubnet 'Microsoft.Network/virtualNetworks/subnets@2023-04-01' existing = {
parent: virtualNetwork
name: userAgentPoolSubnetName
}
resource podSubnet 'Microsoft.Network/virtualNetworks/subnets@2023-04-01' existing = if (networkPlugin != 'overlay') {
parent: virtualNetwork
name: podSubnetName
}
resource apiServerSubnet 'Microsoft.Network/virtualNetworks/subnets@2023-04-01' existing = {
parent: virtualNetwork
name: apiServerSubnetName
}
resource dnsZone 'Microsoft.Network/dnsZones@2018-05-01' existing = if (webAppRoutingEnabled && !empty(dnsZoneName) && !empty(dnsZoneResourceGroupName)) {
name: dnsZoneName
scope: resourceGroup(dnsZoneResourceGroupName)
}
resource keyVault 'Microsoft.KeyVault/vaults@2023-07-01' existing = if (azureKeyvaultSecretsProviderEnabled && !empty(keyVaultName)) {
name: keyVaultName
}
resource aksCluster 'Microsoft.ContainerService/managedClusters@2024-06-02-preview' = {
name: name
location: location
tags: tags
sku: {
name: 'Base'
tier: skuTier
}
identity: {
type: 'UserAssigned'
userAssignedIdentities: {
'${managedIdentity.id}': {}
}
}
properties: {
kubernetesVersion: kubernetesVersion
dnsPrefix: dnsPrefix
agentPoolProfiles: [
{
name: toLower(systemAgentPoolName)
count: systemAgentPoolAgentCount
vmSize: systemAgentPoolVmSize
vnetSubnetID: systemAgentPoolSubnet.id
podSubnetID: networkPluginMode == 'overlay' ? null : podSubnet.id
maxPods: systemAgentPoolMaxPods
osDiskSizeGB: systemAgentPoolOsDiskSizeGB
osDiskType: systemAgentPoolOsDiskType
osSKU: systemAgentPoolOsSKU
osType: systemAgentPoolOsType
maxCount: systemAgentPoolMaxCount
minCount: systemAgentPoolMinCount
scaleDownMode: systemAgentPoolScaleDownMode
scaleSetPriority: systemAgentPoolScaleSetPriority
scaleSetEvictionPolicy: systemAgentPoolScaleSetEvictionPolicy == 'Spot'
? systemAgentPoolScaleSetEvictionPolicy
: null
spotMaxPrice: systemAgentPoolScaleSetEvictionPolicy == 'Spot' ? systemAgentPoolSpotMaxPrice : null
enableAutoScaling: systemAgentPoolEnableAutoScaling
mode: 'System'
type: systemAgentPoolType
availabilityZones: systemAgentPoolAvailabilityZones
nodeLabels: systemAgentPoolNodeLabels
nodeTaints: systemAgentPoolNodeTaints
kubeletDiskType: systemAgentPoolKubeletDiskType
}
{
name: toLower(userAgentPoolName)
count: userAgentPoolAgentCount
vmSize: userAgentPoolVmSize
vnetSubnetID: userAgentPoolSubnet.id
podSubnetID: networkPluginMode == 'overlay' ? null : podSubnet.id
maxPods: userAgentPoolMaxPods
osDiskSizeGB: userAgentPoolOsDiskSizeGB
osDiskType: userAgentPoolOsDiskType
osSKU: userAgentPoolOsSKU
osType: userAgentPoolOsType
maxCount: userAgentPoolMaxCount
minCount: userAgentPoolMinCount
scaleDownMode: userAgentPoolScaleDownMode
scaleSetPriority: userAgentPoolScaleSetPriority
scaleSetEvictionPolicy: userAgentPoolScaleSetEvictionPolicy == 'Spot'
? userAgentPoolScaleSetEvictionPolicy
: null
spotMaxPrice: userAgentPoolScaleSetEvictionPolicy == 'Spot' ? userAgentPoolSpotMaxPrice : null
enableAutoScaling: userAgentPoolEnableAutoScaling
mode: 'User'
type: userAgentPoolType
availabilityZones: userAgentPoolAvailabilityZones
nodeLabels: userAgentPoolNodeLabels
nodeTaints: userAgentPoolNodeTaints
kubeletDiskType: userAgentPoolKubeletDiskType
}
]
linuxProfile: {
adminUsername: adminUsername
ssh: {
publicKeys: [
{
keyData: sshPublicKey
}
]
}
}
addonProfiles: {
httpApplicationRouting: {
enabled: httpApplicationRoutingEnabled
}
omsagent: {
enabled: true
config: {
logAnalyticsWorkspaceResourceID: workspaceId
}
}
aciConnectorLinux: {
enabled: aciConnectorLinuxEnabled
}
azurepolicy: {
enabled: azurePolicyEnabled
config: {
version: 'v2'
}
}
kubeDashboard: {
enabled: kubeDashboardEnabled
}
azureKeyvaultSecretsProvider: {
config: {
enableSecretRotation: 'false'
}
enabled: azureKeyvaultSecretsProviderEnabled
}
}
podIdentityProfile: {
enabled: podIdentityProfileEnabled
}
oidcIssuerProfile: {
enabled: oidcIssuerProfileEnabled
}
enableRBAC: true
ingressProfile: {
webAppRouting: {
enabled: webAppRoutingEnabled
dnsZoneResourceIds: [
dnsZone.id
]
nginx: {
defaultIngressControllerType: nginxDefaultIngressControllerType
}
}
}
networkProfile: {
networkDataplane: networkDataplane
networkMode: networkPlugin == 'azure' ? networkMode : ''
networkPlugin: networkPlugin
networkPluginMode: networkPlugin == 'azure' ? networkPluginMode : ''
networkPolicy: networkPolicy
podCidr: networkPlugin == 'kubenet' || networkPluginMode == 'overlay' ? podCidr : null
serviceCidr: serviceCidr
dnsServiceIP: dnsServiceIP
outboundType: outboundType
loadBalancerSku: loadBalancerSku
advancedNetworking: advancedNetworking
loadBalancerProfile: {
backendPoolType: loadBalancerBackendPoolType
}
ipFamilies: ipFamilies
}
workloadAutoScalerProfile: {
keda: {
enabled: kedaEnabled
}
verticalPodAutoscaler: {
enabled: verticalPodAutoscalerEnabled
}
}
aadProfile: {
clientAppID: null
serverAppID: null
serverAppSecret: null
managed: aadProfileManaged
enableAzureRBAC: aadProfileEnableAzureRBAC
adminGroupObjectIDs: aadProfileAdminGroupObjectIDs
tenantID: aadProfileTenantId
}
autoUpgradeProfile: {
nodeOSUpgradeChannel: nodeOSUpgradeChannel
upgradeChannel: upgradeChannel
}
azureMonitorProfile: {
containerInsights: containerInsights
metrics: {
enabled: prometheusAndGrafanaEnabled
kubeStateMetrics: {
metricAnnotationsAllowList: metricAnnotationsAllowList
metricLabelsAllowlist: metricLabelsAllowlist
}
}
}
autoScalerProfile: {
'scan-interval': autoScalerProfileScanInterval
'scale-down-delay-after-add': autoScalerProfileScaleDownDelayAfterAdd
'scale-down-delay-after-delete': autoScalerProfileScaleDownDelayAfterDelete
'scale-down-delay-after-failure': autoScalerProfileScaleDownDelayAfterFailure
'scale-down-unneeded-time': autoScalerProfileScaleDownUnneededTime
'scale-down-unready-time': autoScalerProfileScaleDownUnreadyTime
'scale-down-utilization-threshold': autoScalerProfileUtilizationThreshold
'max-graceful-termination-sec': autoScalerProfileMaxGracefulTerminationSec
expander: autoScalerProfileExpander
}
apiServerAccessProfile: {
enablePrivateCluster: enablePrivateCluster
enableVnetIntegration: enableVnetIntegration
privateDNSZone: enablePrivateCluster ? privateDNSZone : null
enablePrivateClusterPublicFQDN: enablePrivateClusterPublicFQDN
subnetId: apiServerSubnet.id
}
securityProfile: {
defender: {
logAnalyticsWorkspaceResourceId: workspaceId
securityMonitoring: {
enabled: defenderSecurityMonitoringEnabled
}
}
imageCleaner: {
enabled: imageCleanerEnabled
intervalHours: imageCleanerIntervalHours
}
nodeRestriction: {
enabled: nodeRestrictionEnabled
}
workloadIdentity: {
enabled: workloadIdentityEnabled
}
}
serviceMeshProfile: istioServiceMeshEnabled
? {
istio: {
components: {
ingressGateways: istioIngressGatewayEnabled
? [
{
enabled: true
mode: istioIngressGatewayType
}
]
: null
}
}
mode: 'Istio'
}
: null
storageProfile: {
blobCSIDriver: {
enabled: blobCSIDriverEnabled
}
diskCSIDriver: {
enabled: diskCSIDriverEnabled
}
fileCSIDriver: {
enabled: fileCSIDriverEnabled
}
snapshotController: {
enabled: snapshotControllerEnabled
}
}
}
}
// Dapr Extension
resource daprExtension 'Microsoft.KubernetesConfiguration/extensions@2023-05-01' = if (daprEnabled) {
name: 'dapr'
scope: aksCluster
properties: {
extensionType: 'Microsoft.Dapr'
autoUpgradeMinorVersion: true
releaseTrain: 'Stable'
configurationSettings: {
'global.ha.enabled': '${daprHaEnabled}'
}
scope: {
cluster: {
releaseNamespace: 'dapr-system'
}
}
configurationProtectedSettings: {}
}
}
// Role Definitions
resource azureKubernetesServiceRBACClusterAdminRoleDefinition 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
name: 'b1ff04bb-8a4e-4dc4-8eb5-8693973ce19b'
scope: subscription()
}
resource keyVaultAdministratorRoleDefinition 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
name: '00482a5a-887f-4fb3-b363-3b7fe8e74483'
scope: subscription()
}
// Role Assignments
resource azureKubernetesServiceRBACClusterAdminRoleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = if (!empty(userId)) {
name: guid(aksCluster.id, 'CSIDriver', azureKubernetesServiceRBACClusterAdminRoleDefinition.id, userId)
scope: aksCluster
properties: {
roleDefinitionId: azureKubernetesServiceRBACClusterAdminRoleDefinition.id
principalType: 'User'
principalId: userId
}
}
resource keyVaultCSIdriverSecretsUserRoleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = if (azureKeyvaultSecretsProviderEnabled) {
name: guid(keyVault.id, 'CSIDriver', keyVaultAdministratorRoleDefinition.id)
scope: keyVault
properties: {
roleDefinitionId: keyVaultAdministratorRoleDefinition.id
principalType: 'ServicePrincipal'
principalId: aksCluster.properties.addonProfiles.azureKeyvaultSecretsProvider.identity.objectId
}
}
// Flux v2 Extension
resource fluxAddon 'Microsoft.KubernetesConfiguration/extensions@2023-05-01' = if (fluxGitOpsEnabled) {
name: 'flux'
scope: aksCluster
properties: {
extensionType: 'microsoft.flux'
autoUpgradeMinorVersion: true
releaseTrain: 'Stable'
scope: {
cluster: {
releaseNamespace: 'flux-system'
}
}
configurationProtectedSettings: {}
}
dependsOn: [daprExtension]
}
// Diagnostics Settings
resource diagnosticSettings 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = {
name: diagnosticSettingsName
scope: aksCluster
properties: {
workspaceId: workspaceId
logs: logs
metrics: metrics
}
}
// Output
output id string = aksCluster.id
output name string = aksCluster.name
output fqdn string = aksCluster.properties.fqdn
output nodeResourceGroup string = aksCluster.properties.nodeResourceGroup
output azureKeyvaultSecretsProviderIdentity object = aksCluster.properties.addonProfiles.azureKeyvaultSecretsProvider.identity