1
+ // Copyright 2016-2020, Pulumi Corporation. All rights reserved.
2
+ import * as azuread from "@pulumi/azuread" ;
3
+ import * as pulumi from "@pulumi/pulumi" ;
4
+ import * as random from "@pulumi/random" ;
5
+ import * as tls from "@pulumi/tls" ;
6
+
7
+ import * as containerservice from "@pulumi/azure-native/containerservice" ;
8
+ import * as resources from "@pulumi/azure-native/resources" ;
9
+
10
+ const resourceGroup = new resources . ResourceGroup ( "azure-go-aks" ) ;
11
+
12
+ // Create an AD service principal
13
+ const adApp = new azuread . Application ( "aks" , {
14
+ displayName : "aks" ,
15
+ } ) ;
16
+ const adSp = new azuread . ServicePrincipal ( "aksSp" , {
17
+ applicationId : adApp . applicationId ,
18
+ } ) ;
19
+
20
+ const password = new random . RandomPassword ( "password" , {
21
+ length : 20 ,
22
+ special : true ,
23
+ } ) ;
24
+
25
+ // Create the Service Principal Password
26
+ const adSpPassword = new azuread . ServicePrincipalPassword ( "aksSpPassword" , {
27
+ servicePrincipalId : adSp . id ,
28
+ value : password . result ,
29
+ endDate : "2099-01-01T00:00:00Z" ,
30
+ } ) ;
31
+
32
+ // Generate an SSH key
33
+ const sshKey = new tls . PrivateKey ( "ssh-key" , {
34
+ algorithm : "RSA" ,
35
+ rsaBits : 4096 ,
36
+ } ) ;
37
+
38
+ const config = new pulumi . Config ( ) ;
39
+ const managedClusterName = config . get ( "managedClusterName" ) || "azure-aks" ;
40
+ const cluster = new containerservice . ManagedCluster ( managedClusterName , {
41
+ resourceGroupName : resourceGroup . name ,
42
+ agentPoolProfiles : [ {
43
+ count : 1 ,
44
+ maxPods : 110 ,
45
+ mode : "System" ,
46
+ name : "agentpool" ,
47
+ nodeLabels : { } ,
48
+ osDiskSizeGB : 20 ,
49
+ osType : "Linux" ,
50
+ type : "VirtualMachineScaleSets" ,
51
+ vmSize : "Standard_B2s" ,
52
+ } ] ,
53
+ dnsPrefix : resourceGroup . name ,
54
+ enableRBAC : true ,
55
+ kubernetesVersion : "1.20.7" ,
56
+ linuxProfile : {
57
+ adminUsername : "testuser" ,
58
+ ssh : {
59
+ publicKeys : [ {
60
+ keyData : sshKey . publicKeyOpenssh ,
61
+ } ] ,
62
+ } ,
63
+ } ,
64
+ nodeResourceGroup : `MC_azure-go_${ managedClusterName } ` ,
65
+ servicePrincipalProfile : {
66
+ clientId : adApp . applicationId ,
67
+ secret : adSpPassword . value ,
68
+ } ,
69
+ } ) ;
70
+
71
+ const creds = pulumi . all ( [ cluster . name , resourceGroup . name ] ) . apply ( ( [ clusterName , rgName ] ) => {
72
+ return containerservice . listManagedClusterUserCredentials ( {
73
+ resourceGroupName : rgName ,
74
+ resourceName : clusterName ,
75
+ } ) ;
76
+ } ) ;
77
+
78
+ const encoded = creds . kubeconfigs [ 0 ] . value ;
79
+ export const kubeconfig = encoded . apply ( enc => Buffer . from ( enc , "base64" ) . toString ( ) ) ;
0 commit comments