示例#1
0
    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 = "******",
                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 = Output.Tuple(k8sCluster.Name, args.ResourceGroupName.ToOutput())
                          .Apply(pair =>
        {
            var k8sClusterName    = pair.Item1;
            var resourceGroupName = pair.Item2;

            return(ListManagedClusterUserCredentials.InvokeAsync(new ListManagedClusterUserCredentialsArgs
            {
                ResourceGroupName = resourceGroupName,
                ResourceName = k8sClusterName
            }));
        })
                          .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
        });
    }
示例#2
0
        public FantasticBikeStack()
        {
            const string projectName   = "fantasticbike";
            var          stackName     = Deployment.Instance.StackName;
            var          azureConfig   = new Config("azure-native");
            var          location      = azureConfig.Require("location");
            var          ignoreChanges = new CustomResourceOptions
            {
                IgnoreChanges = new List <string> {
                    "tags"
                }
            };

            #region Resource Group

            var resourceGroupName = $"{projectName}-{stackName}-rg";
            var resourceGroup     = new ResourceGroup(resourceGroupName, new ResourceGroupArgs
            {
                Location          = location,
                ResourceGroupName = resourceGroupName
            }, ignoreChanges);

            #endregion

            #region Azure Storage

            var storageAccountName = $"{projectName}{stackName}st";
            var storageAccount     = new Storage.StorageAccount(storageAccountName, new Storage.StorageAccountArgs
            {
                AccountName       = storageAccountName,
                ResourceGroupName = resourceGroup.Name,
                Location          = location,
                Sku = new Storage.Inputs.SkuArgs
                {
                    Name = Storage.SkuName.Standard_LRS
                },
                Kind = Storage.Kind.StorageV2
            }, ignoreChanges);

            #endregion

            #region ASB

            var asbNamespaceName = $"{projectName}{stackName}ns";
            var asbNamespace     = new ASB.Namespace(asbNamespaceName, new ASB.NamespaceArgs
            {
                Location          = location,
                NamespaceName     = asbNamespaceName,
                ResourceGroupName = resourceGroup.Name,
                Sku = new ASB.Inputs.SBSkuArgs
                {
                    Name = ASB.SkuName.Standard,
                    Tier = ASB.SkuTier.Standard
                }
            }, ignoreChanges);

            #endregion

            #region Serverless Functions

            #endregion

            #region AKS Functions

            #endregion

            #region AKS

            var aksArgs = new AksClusterArgs
            {
                ProjectName       = projectName,
                ResourceGroupName = resourceGroup.Name,
                VmCount           = 1,
                VmSize            = "Standard_D2_v3",
                K8sVersion        = "1.18.14"
            };
            var aks = new AksCluster("aks", aksArgs);

            #endregion

            #region Output

            // Export the primary key of the Storage Account
            PrimaryStorageKey = Output.Tuple(resourceGroup.Name, storageAccount.Name).Apply(names =>
                                                                                            Output.Create(GetStorageAccountPrimaryKey(names.Item1, names.Item2)));

            ASBPrimaryConnectionString = Output.Tuple(resourceGroup.Name, asbNamespace.Name).Apply(names =>
                                                                                                   Output.Create(GetASBPrimaryConectionString(names.Item1, names.Item2)));

            KubeConfig  = aks.KubeConfig;
            PrincipalId = aks.PrincipalId;

            #endregion
        }