forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example for multiple AKS clusters. (pulumi#190)
* Add example for multiple AKS clusters.
- Loading branch information
Showing
8 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/bin/ | ||
/node_modules/ | ||
key.rsa | ||
key.rsa.pub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: azure-ts-aks-multicluster | ||
runtime: nodejs | ||
description: Create multiple Azure Kubernetes Service (AKS) clusters in different regions and with different node counts | ||
template: | ||
config: | ||
azure:environment: | ||
description: The Azure environment to use (`public`, `usgovernment`, `german`, `china`) | ||
default: public | ||
password: | ||
description: Your cluster password | ||
secret: true | ||
sshPublicKey: | ||
description: Your SSH public key (generate with `ssh-keygen -t rsa -f key.rsa`) | ||
resourceGroupLocation: | ||
description: The location to use for the Azure Resource Group |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
[![Deploy](https://get.pulumi.com/new/button.svg)](https://app.pulumi.com/new) | ||
|
||
# Multiple Azure Kubernetes Service (AKS) Clusters | ||
|
||
This example demonstrates creating multiple Azure Kubernetes Service (AKS) clusters in different regions and with | ||
different node counts. Please see https://docs.microsoft.com/en-us/azure/aks/ for more information about AKS. | ||
|
||
# Prerequisites | ||
|
||
Ensure you have [downloaded and installed the Pulumi CLI](https://pulumi.io/install). | ||
|
||
We will be deploying to Azure, so you will need an Azure account. If you don't have an account, | ||
[sign up for free here](https://azure.microsoft.com/en-us/free/). | ||
[Follow the instructions here](https://pulumi.io/install/azure.html) to connect Pulumi to your Azure account. | ||
|
||
# Running the Example | ||
|
||
> **Note**: Due to an issue in the Azure Terraform Provider (https://github.com/terraform-providers/terraform-provider-azurerm/issues/1635) the | ||
> creation of an Azure Service Principal, which is needed to create the Kubernetes cluster (see index.ts), is delayed and may not | ||
> be available when the cluster is created. If you get a Service Principal not found error, as a work around, you should be able to run `pulumi up` | ||
> again, at which time the Service Principal should have been created. | ||
After cloning this repo, `cd` into it and run these commands. | ||
|
||
1. Create a new stack, which is an isolated deployment target for this example: | ||
|
||
```bash | ||
$ pulumi stack init | ||
``` | ||
|
||
2. Set the required configuration variables for this program: | ||
|
||
```bash | ||
$ pulumi config set azure:environment public | ||
$ pulumi config set password --secret [your-cluster-password-here] | ||
$ ssh-keygen -t rsa -f key.rsa | ||
$ pulumi config set sshPublicKey < key.rsa.pub | ||
``` | ||
|
||
3. Deploy everything with the `pulumi up` command. This provisions all the Azure resources necessary, including | ||
an Active Directory service principal and AKS clusters: | ||
|
||
```bash | ||
$ pulumi up | ||
``` | ||
|
||
4. After a couple minutes, your AKS clusters will be ready. The AKS cluster names will be printed as output variables | ||
once `pulumi up` completes. | ||
|
||
```bash | ||
$ pulumi up | ||
... | ||
|
||
Outputs: | ||
+ aksClusterNames: [ | ||
+ [0]: "akscluster-east513be264" | ||
+ [1]: "akscluster-westece285c7" | ||
] | ||
... | ||
``` | ||
|
||
5. At this point, you have multiple AKS clusters running in different regions. Feel free to modify your program, and | ||
run `pulumi up` to redeploy changes. The Pulumi CLI automatically detects what has changed and makes the minimal | ||
edits necessary to accomplish these changes. | ||
|
||
6. Once you are done, you can destroy all of the resources, and the stack: | ||
|
||
```bash | ||
$ pulumi destroy | ||
$ pulumi stack rm | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright 2016-2018, Pulumi Corporation. All rights reserved. | ||
|
||
import * as azure from "@pulumi/azure"; | ||
import * as pulumi from "@pulumi/pulumi"; | ||
|
||
// Parse and export configuration variables for this stack. | ||
const config = new pulumi.Config(); | ||
export const password = config.require("password"); | ||
export const location = config.get("location") || "East US"; | ||
export const sshPublicKey = config.require("sshPublicKey"); | ||
export const resourceGroup = new azure.core.ResourceGroup("aks", {location: location}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2016-2018, Pulumi Corporation. All rights reserved. | ||
|
||
import * as azure from "@pulumi/azure"; | ||
import * as pulumi from "@pulumi/pulumi"; | ||
import * as config from "./config"; | ||
|
||
// Per-Cluster Config | ||
const aksClusterConfig = [ | ||
{ | ||
name: 'east', | ||
location: "East US", | ||
nodeCount: 2, | ||
nodeSize: "Standard_D2_v2", | ||
}, | ||
{ | ||
name: 'west', | ||
location: "West US", | ||
nodeCount: 5, | ||
nodeSize: "Standard_D2_v2", | ||
}, | ||
]; | ||
|
||
// Create the AD service principal for the K8s cluster. | ||
const adApp = new azure.ad.Application("aks"); | ||
const adSp = new azure.ad.ServicePrincipal("aksSp", {applicationId: adApp.applicationId}); | ||
const adSpPassword = new azure.ad.ServicePrincipalPassword("aksSpPassword", { | ||
servicePrincipalId: adSp.id, | ||
value: config.password, | ||
endDate: "2099-01-01T00:00:00Z", | ||
}); | ||
|
||
// Create the individual clusters | ||
const k8sClusters = aksClusterConfig.map((perClusterConfig, index) => { | ||
const cluster = new azure.containerservice.KubernetesCluster(`aksCluster-${perClusterConfig.name}`, { | ||
resourceGroupName: config.resourceGroup.name, | ||
location: config.location, | ||
agentPoolProfile: { | ||
name: "aksagentpool", | ||
count: perClusterConfig.nodeCount, | ||
vmSize: perClusterConfig.nodeSize, | ||
}, | ||
dnsPrefix: `${pulumi.getStack()}-kube`, | ||
linuxProfile: { | ||
adminUsername: "aksuser", | ||
sshKeys: [{ | ||
keyData: config.sshPublicKey, | ||
}], | ||
}, | ||
servicePrincipal: { | ||
clientId: adApp.applicationId, | ||
clientSecret: adSpPassword.value, | ||
}, | ||
}); | ||
return cluster; | ||
}); | ||
|
||
export const aksClusterNames = k8sClusters.map(cluster => cluster.name); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "azure-ts-aks-multicluster", | ||
"version": "0.1.0", | ||
"devDependencies": { | ||
"@types/node": "latest" | ||
}, | ||
"dependencies": { | ||
"@pulumi/azure": "latest", | ||
"@pulumi/kubernetes": "latest", | ||
"@pulumi/pulumi": "latest" | ||
}, | ||
"license": "Apache-2.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "bin", | ||
"target": "es6", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"declaration": true, | ||
"sourceMap": true, | ||
"stripInternal": true, | ||
"experimentalDecorators": true, | ||
"pretty": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitAny": true, | ||
"noImplicitReturns": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strictNullChecks": true | ||
}, | ||
"files": [ | ||
"index.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters