-
Notifications
You must be signed in to change notification settings - Fork 880
/
AksCluster.cs
121 lines (108 loc) · 4.09 KB
/
AksCluster.cs
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
// Copyright 2016-2021, Pulumi Corporation. All rights reserved.
using System;
using System.Text;
using Pulumi;
using Pulumi.AzureAD;
using Pulumi.AzureNative.ContainerService;
using Pulumi.AzureNative.ContainerService.Inputs;
using Pulumi.AzureNative.Resources;
using Pulumi.Random;
using Pulumi.Tls;
using K8s = Pulumi.Kubernetes;
public class AksCluster : ComponentResource
{
public Output<string> ClusterName { get; set; }
public Output<string> KubeConfig { get; set; }
public K8s.Provider Provider { get; set; }
public AksCluster(string name, AksClusterArgs args)
: base("example:component:AksCluster", name)
{
var adApp = new Application("app", new ApplicationArgs
{
DisplayName = "aks-cosmos"
}, new CustomResourceOptions { Parent = this });
var adSp = new ServicePrincipal("service-principal", new ServicePrincipalArgs
{
ApplicationId = adApp.ApplicationId
}, new CustomResourceOptions { Parent = this });
var pw = new RandomPassword("pw", new RandomPasswordArgs
{
Length = 20,
Special = true
}, new CustomResourceOptions { Parent = this });
var adSpPassword = new ServicePrincipalPassword("sp-password", new ServicePrincipalPasswordArgs
{
ServicePrincipalId = adSp.Id,
Value = pw.Result,
EndDate = "2099-01-01T00:00:00Z"
}, new CustomResourceOptions { Parent = this });
var keyPair = new PrivateKey("ssh-key", new PrivateKeyArgs
{
Algorithm = "RSA",
RsaBits = 4096
}, new CustomResourceOptions { Parent = this });
var k8sCluster = new ManagedCluster(name, new ManagedClusterArgs
{
ResourceGroupName = args.ResourceGroupName,
AddonProfiles =
{
["KubeDashboard"] = new ManagedClusterAddonProfileArgs { Enabled = true }
},
AgentPoolProfiles =
{
new ManagedClusterAgentPoolProfileArgs
{
Count = args.NodeCount,
VmSize = args.NodeSize,
MaxPods = 110,
Mode = "System",
Name = "agentpool",
OsDiskSizeGB = 30,
OsType = "Linux",
Type = "VirtualMachineScaleSets"
}
},
DnsPrefix = args.ResourceGroupName,
EnableRBAC = true,
KubernetesVersion = args.KubernetesVersion,
LinuxProfile = new ContainerServiceLinuxProfileArgs
{
AdminUsername = "testuser",
Ssh = new ContainerServiceSshConfigurationArgs
{
PublicKeys = new ContainerServiceSshPublicKeyArgs
{
KeyData = keyPair.PublicKeyOpenssh
}
}
},
NodeResourceGroup = $"{name}-node-rg",
ServicePrincipalProfile = new ManagedClusterServicePrincipalProfileArgs
{
ClientId = adApp.ApplicationId,
Secret = adSpPassword.Value
}
}, new CustomResourceOptions { Parent = this });
this.ClusterName = k8sCluster.Name;
this.KubeConfig = ListManagedClusterUserCredentials.Invoke(
new ListManagedClusterUserCredentialsInvokeArgs
{
ResourceGroupName = args.ResourceGroupName,
ResourceName = k8sCluster.Name
})
.Apply(x => x.Kubeconfigs[0].Value)
.Apply(Convert.FromBase64String)
.Apply(Encoding.UTF8.GetString);
this.Provider = new K8s.Provider("k8s-provider", new K8s.ProviderArgs
{
KubeConfig = this.KubeConfig
}, new CustomResourceOptions { Parent = this });
}
}
public class AksClusterArgs
{
public Input<string> ResourceGroupName { get; set; }
public string KubernetesVersion { get; set; }
public int NodeCount { get; set; }
public string NodeSize { get; set; }
}