Пример #1
0
 private static Output <string> GetKubeConfig(Output <string> resourceGroupName, Output <string> clusterName)
 => ListManagedClusterUserCredentials.Invoke(new ListManagedClusterUserCredentialsInvokeArgs
 {
     ResourceGroupName = resourceGroupName,
     ResourceName      = clusterName
 }).Apply(credentials => {
     var encoded = credentials.Kubeconfigs[0].Value;
     var data    = Convert.FromBase64String(encoded);
     return(Encoding.UTF8.GetString(data));
 });
Пример #2
0
    public MyCluster(MyConfig cfg)
    {
        var resourceGroup = new ResourceGroup("rg");

        var adApp = new Application("app", new ApplicationArgs
        {
            DisplayName = "app"
        });

        var adSp = new ServicePrincipal("service-principal", new ServicePrincipalArgs
        {
            ApplicationId = adApp.ApplicationId
        });

        var adSpPassword = new ServicePrincipalPassword("sp-password", new ServicePrincipalPasswordArgs
        {
            ServicePrincipalId = adSp.Id,
            Value   = cfg.Password,
            EndDate = "2099-01-01T00:00:00Z"
        });

        var k8sCluster = new ManagedCluster("cluster", new ManagedClusterArgs
        {
            ResourceGroupName = resourceGroup.Name,
            AddonProfiles     =
            {
                ["KubeDashboard"] = new ManagedClusterAddonProfileArgs {
                    Enabled = true
                }
            },
            AgentPoolProfiles =
            {
                new ManagedClusterAgentPoolProfileArgs
                {
                    Count        = cfg.NodeCount,
                    VmSize       = cfg.NodeSize,
                    MaxPods      = 110,
                    Mode         = "System",
                    Name         = "agentpool",
                    OsDiskSizeGB = 30,
                    OsType       = "Linux",
                    Type         = "VirtualMachineScaleSets"
                }
            },
            DnsPrefix         = resourceGroup.Name,
            EnableRBAC        = true,
            KubernetesVersion = cfg.K8SVersion,
            LinuxProfile      = new ContainerServiceLinuxProfileArgs
            {
                AdminUsername = cfg.AdminUserName,
                Ssh           = new ContainerServiceSshConfigurationArgs
                {
                    PublicKeys = new ContainerServiceSshPublicKeyArgs
                    {
                        KeyData = cfg.SshPublicKey
                    }
                }
            },
            NodeResourceGroup       = "node-resource-group",
            ServicePrincipalProfile = new ManagedClusterServicePrincipalProfileArgs
            {
                ClientId = adApp.ApplicationId,
                Secret   = adSpPassword.Value
            }
        });

        this.ClusterName = k8sCluster.Name;

        this.Kubeconfig = ListManagedClusterUserCredentials.Invoke(
            new ListManagedClusterUserCredentialsInvokeArgs
        {
            ResourceGroupName = resourceGroup.Name,
            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 = Kubeconfig
        });
    }
Пример #3
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 = 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
        });
    }