forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
120 lines (111 loc) · 4.12 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
// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
import * as k8s from "@pulumi/kubernetes";
import * as pulumi from "@pulumi/pulumi";
// Minikube does not implement services of type `LoadBalancer`; require the user to specify if we're
// running on minikube, and if so, create only services of type ClusterIP.
const config = new pulumi.Config();
const isMinikube = config.getBoolean("isMinikube");
//
// REDIS MASTER.
//
const redisMasterLabels = { app: "redis-master" };
const redisMasterDeployment = new k8s.apps.v1.Deployment("redis-master", {
spec: {
selector: { matchLabels: redisMasterLabels },
template: {
metadata: { labels: redisMasterLabels },
spec: {
containers: [
{
name: "master",
image: "k8s.gcr.io/redis:e2e",
resources: { requests: { cpu: "100m", memory: "100Mi" } },
ports: [{ containerPort: 6379 }],
},
],
},
},
},
});
const redisMasterService = new k8s.core.v1.Service("redis-master", {
metadata: {
labels: redisMasterDeployment.metadata.labels,
},
spec: {
ports: [{ port: 6379, targetPort: 6379 }],
selector: redisMasterDeployment.spec.template.metadata.labels,
},
});
//
// REDIS REPLICA.
//
const redisReplicaLabels = { app: "redis-replica" };
const redisReplicaDeployment = new k8s.apps.v1.Deployment("redis-replica", {
spec: {
selector: { matchLabels: redisReplicaLabels },
template: {
metadata: { labels: redisReplicaLabels },
spec: {
containers: [
{
name: "replica",
image: "gcr.io/google_samples/gb-redisslave:v1",
resources: { requests: { cpu: "100m", memory: "100Mi" } },
// If your cluster config does not include a dns service, then to instead access an environment
// variable to find the master service's host, change `value: "dns"` to read `value: "env"`.
env: [{ name: "GET_HOSTS_FROM", value: "dns" }],
ports: [{ containerPort: 6379 }],
},
],
},
},
},
});
const redisReplicaService = new k8s.core.v1.Service("redis-replica", {
metadata: { labels: redisReplicaDeployment.metadata.labels },
spec: {
ports: [{ port: 6379, targetPort: 6379 }],
selector: redisReplicaDeployment.spec.template.metadata.labels,
},
});
//
// FRONTEND
//
const frontendLabels = { app: "frontend" };
const frontendDeployment = new k8s.apps.v1.Deployment("frontend", {
spec: {
selector: { matchLabels: frontendLabels },
replicas: 3,
template: {
metadata: { labels: frontendLabels },
spec: {
containers: [
{
name: "php-redis",
image: "gcr.io/google-samples/gb-frontend:v4",
resources: { requests: { cpu: "100m", memory: "100Mi" } },
// If your cluster config does not include a dns service, then to instead access an environment
// variable to find the master service's host, change `value: "dns"` to read `value: "env"`.
env: [{ name: "GET_HOSTS_FROM", value: "dns" /* value: "env"*/ }],
ports: [{ containerPort: 80 }],
},
],
},
},
},
});
const frontendService = new k8s.core.v1.Service("frontend", {
metadata: { labels: frontendDeployment.metadata.labels },
spec: {
type: isMinikube ? "ClusterIP" : "LoadBalancer",
ports: [{ port: 80 }],
selector: frontendDeployment.spec.template.metadata.labels,
},
});
// Export the frontend IP.
export let frontendIp: pulumi.Output<string>;
if (isMinikube) {
frontendIp = frontendService.spec.clusterIP;
} else {
frontendIp = frontendService.status.loadBalancer.ingress[0].ip;
}