Skip to content

Commit 4049416

Browse files
author
Noah Ispas
committed
breakthrough
1 parent aec3fe3 commit 4049416

7 files changed

+211
-0
lines changed

.gitignore

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
lib-cov
2+
*.seed
3+
*.log
4+
*.csv
5+
*.dat
6+
*.out
7+
*.pid
8+
*.gz
9+
*.swp
10+
11+
pids
12+
logs
13+
results
14+
tmp
15+
16+
# Build
17+
public/css/main.css
18+
19+
# Coverage reports
20+
coverage
21+
22+
# API keys and secrets
23+
.env
24+
25+
# Dependency directory
26+
node_modules
27+
bower_components
28+
29+
# Editors
30+
.idea
31+
*.iml
32+
33+
# OS metadata
34+
.DS_Store
35+
Thumbs.db
36+
37+
# Ignore built ts files
38+
dist/**/*
39+
40+
# ignore yarn.lock
41+
yarn.lock
42+
43+
/.pulumi/
44+
/.vscode/
45+
/.vs/
46+
bin/
47+
build/
48+
node_modules/
49+
*.pyc
50+
.Python
51+
venv/
52+
include/
53+
lib/
54+
yarn.lock
55+
package-lock.json
56+
Pulumi.*.yaml
57+
.idea/
58+
.ionide/
59+
*.iml
60+
key.rsa*
61+
obj/
62+
vendor
63+
Gopkg.lock
64+
65+
**/ci-scripts
66+
67+
# Java app
68+
.gradle/
69+
.settings/
70+
.project
71+
.classpath
72+
kubeconfig.yaml

infra/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/bin/
2+
/node_modules/

infra/Pulumi.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: azure-aks-typescript
2+
runtime: nodejs
3+
description: A minimal Azure Native TypeScript Pulumi program

infra/index.ts

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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());

infra/package.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "azure-aks-typescript",
3+
"devDependencies": {
4+
"@pulumi/azuread": "^4.3.0",
5+
"@pulumi/random": "^4.2.0",
6+
"@pulumi/tls": "^4.0.0",
7+
"@types/node": "^10.0.0"
8+
},
9+
"dependencies": {
10+
"@pulumi/pulumi": "^3.0.0",
11+
"@pulumi/azure-native": "^1.0.0"
12+
}
13+
}

infra/tsconfig.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"compilerOptions": {
3+
"strict": true,
4+
"outDir": "bin",
5+
"target": "es2016",
6+
"module": "commonjs",
7+
"moduleResolution": "node",
8+
"sourceMap": true,
9+
"experimentalDecorators": true,
10+
"pretty": true,
11+
"noFallthroughCasesInSwitch": true,
12+
"noImplicitReturns": true,
13+
"forceConsistentCasingInFileNames": true
14+
},
15+
"files": [
16+
"index.ts"
17+
]
18+
}

readme.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Pulumi AKS Typescript
2+
3+
This repo contains a walkthrough for getting started with [Pulumi](https://www.pulumi.com) on Azure, creating a Kubernetes cluster (aka AKS) utilizing TypeScript.
4+
5+
Pulumi is a Infrastructure As Code Framework, that allows to build, deploy and manage modern cloud applications and infrastructure using familiar languages.
6+
7+
## Prerequisites
8+
* [Install Pulumi](https://www.pulumi.com/docs/get-started/install/)
9+
* [Signup to Pulumi](https://app.pulumi.com/signup)
10+
* Install [Node.js](https://nodejs.org/en/download/)
11+
* Install [TypeScript](https://www.typescriptlang.org/download)
12+
* Install [Azure CLI](https://docs.microsoft.com/de-de/cli/azure/install-azure-cli) and login using `az login`
13+
14+
## Deploy stack
15+
* `pulumi login`
16+
* `cd infra && pulumi up`
17+
18+
## Connect to k8s
19+
* `pulumi stack output kubeconfig --show-secrets > kubeconfig.yaml`
20+
* `export KUBECONFIG=./kubeconfig.yaml`
21+
22+
23+
## Destroy stack
24+
* `pulumi destroy`

0 commit comments

Comments
 (0)