forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
62 lines (56 loc) · 2.07 KB
/
index.ts
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
// Copyright 2016-2019, Pulumi Corporation. All rights reserved.
import * as azure from "@pulumi/azure";
import * as k8s from "@pulumi/kubernetes";
import * as config from "./config";
import * as mongoHelpers from "./mongoHelpers";
// Create an AKS cluster.
import { k8sCluster, k8sProvider } from "./cluster";
// Create a MongoDB-flavored instance of CosmosDB.
const cosmosdb = new azure.cosmosdb.Account("cosmosDb", {
kind: "MongoDB",
resourceGroupName: config.resourceGroup.name,
consistencyPolicy: {
consistencyLevel: "BoundedStaleness",
maxIntervalInSeconds: 10,
maxStalenessPrefix: 200,
},
offerType: "Standard",
enableAutomaticFailover: true,
geoLocations: [
{ location: config.location, failoverPriority: 0 },
{ location: config.failoverLocation, failoverPriority: 1 },
],
});
// Create secret from MongoDB connection string.
const mongoConnStrings = new k8s.core.v1.Secret(
"mongo-secrets",
{
metadata: { name: "mongo-secrets" },
data: mongoHelpers.parseConnString(cosmosdb.connectionStrings),
},
{ provider: k8sProvider },
);
// Boot up nodejs Helm chart example using CosmosDB in place of in-cluster MongoDB.
const node = new k8s.helm.v3.Chart(
"node",
{
chart: "node",
version: "4.0.1",
fetchOpts: {
repo: "https://charts.bitnami.com/bitnami",
},
values: {
serviceType: "LoadBalancer",
mongodb: { install: false },
externaldb: { ssl: true, secretName: "mongo-secrets" },
},
},
{ providers: { kubernetes: k8sProvider }, dependsOn: mongoConnStrings },
);
// Export kubeconfig file, cluster name, and public IP address for Kubernetes application. These can
// be accessed from the CLI, like: `pulumi stack output kubeconfig > kubeconfig.yaml`.
export const kubeconfig = k8sCluster.kubeConfigRaw;
export const cluster = k8sCluster.name;
export const frontendAddress = node
.getResourceProperty("v1/Service", "node-node", "status")
.apply(status => status.loadBalancer.ingress[0].ip);