-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
141 lines (131 loc) · 3.24 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright 2016-2019, Pulumi Corporation. All rights reserved.
import * as awsx from "@pulumi/awsx";
import * as eks from "@pulumi/eks";
import * as k8s from "@pulumi/kubernetes";
const projectName = "fogos-pt";
// Create a VPC for our cluster.
const vpc = new awsx.ec2.Vpc(`${projectName}-vpc-cluster`, {
numberOfAvailabilityZones: 2,
});
// Create the EKS cluster itself and a deployment of the Kubernetes dashboard.
const cluster = new eks.Cluster(`${projectName}-cluster`, {
vpcId: vpc.id,
subnetIds: vpc.publicSubnetIds,
instanceType: "t2.medium",
desiredCapacity: 2,
deployDashboard: false,
version: "1.17",
minSize: 2,
maxSize: 3,
enabledClusterLogTypes: ["api", "audit", "authenticator"],
});
// Export the cluster's kubeconfig.
export const kubeconfig = cluster.kubeconfig;
const clusterAppNamespace = new k8s.core.v1.Namespace(
projectName,
{
metadata: { name: "fogos-pt" },
},
{ provider: cluster.provider }
);
//Create PVC for mongoDB
const pvcMongoDB = new k8s.core.v1.PersistentVolumeClaim(
"mongodb-data",
{
metadata: {
annotations: {
//Skip the await logic for this PersistentVolumeClaim resource.
"pulumi.com/skipAwait": "true",
},
name: "mongodb-data",
namespace: clusterAppNamespace.metadata.name,
},
spec: {
accessModes: ["ReadWriteOnce"],
resources: {
requests: {
storage: "30Gi",
},
},
},
},
{ provider: cluster.provider, parent: clusterAppNamespace }
);
//Create MongoDB Deployment
const mongoAppName = "mongodb";
const mongoAppLabels = { app: mongoAppName };
const mongoAppPortName = "http";
const deploymentMongoDB = new k8s.apps.v1.Deployment(
mongoAppName,
{
metadata: {
labels: mongoAppLabels,
namespace: clusterAppNamespace.metadata.name,
},
spec: {
strategy:{
rollingUpdate:{
maxUnavailable: 1,
maxSurge: 0
}
},
selector: {
matchLabels: mongoAppLabels,
},
replicas: 1,
template: {
metadata: { labels: mongoAppLabels },
spec: {
containers: [
{
image: "mongo:4.2",
name: "mongodb",
volumeMounts: [{ name: "mongo-data", mountPath: "/data/db" }],
ports: [
{
name: mongoAppPortName,
containerPort: 27017,
},
],
},
],
volumes: [
{
name: "mongo-data",
persistentVolumeClaim: {
claimName: pvcMongoDB.metadata.name,
},
},
],
},
},
},
},
{ parent: clusterAppNamespace, provider: cluster.provider }
);
//Create Service for MongoDB
const serviceMongoDB = new k8s.core.v1.Service(
"mongodb",
{
metadata: {
name: "mongodb",
namespace: clusterAppNamespace.metadata.name,
},
spec: {
type: "LoadBalancer",
selector: mongoAppLabels,
ports: [
{
name: "http",
port: 27017,
targetPort: mongoAppPortName,
},
],
},
},
{
dependsOn: deploymentMongoDB,
provider: cluster.provider,
parent: clusterAppNamespace,
}
);