-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
68 lines (64 loc) · 1.78 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
import * as k8s from "@pulumi/kubernetes";
import * as pulumi from "@pulumi/pulumi";
// Create a deployment.
const appLabelsV1 = { app: "blue" };
const deploymentV1 = new k8s.apps.v1.Deployment("app-v1", {
spec: {
selector: { matchLabels: appLabelsV1 },
replicas: 3,
template: {
metadata: { labels: appLabelsV1 },
spec: {
containers: [{
name: "app",
image: "gcr.io/cloud-solutions-images/app:current",
ports: [{containerPort: 8080}],
livenessProbe: {httpGet: {path: "/version", port: 8080 }},
readinessProbe: {httpGet: {path: "/version", port: 8080 }},
lifecycle: {
preStop: {
exec: {command: ["/bin/bash", "-c", "sleep 5"]},
},
}
}],
},
}
}
});
// Create a deployment v2.
const appLabelsV2 = { app: "green" };
const deploymentV2 = new k8s.apps.v1.Deployment("app-v2", {
spec: {
selector: { matchLabels: appLabelsV2 },
replicas: 3,
template: {
metadata: { labels: appLabelsV2 },
spec: {
containers: [{
name: "app",
image: "gcr.io/cloud-solutions-images/app:new",
ports: [{containerPort: 8080}],
livenessProbe: {httpGet: {path: "/version", port: 8080 }},
readinessProbe: {httpGet: {path: "/version", port: 8080 }},
lifecycle: {
preStop: {
exec: {command: ["/bin/bash", "-c", "sleep 5"]},
},
}
}],
},
}
}
});
// Create a service load balancer.
const service = new k8s.core.v1.Service("app", {
spec: {
selector: appLabelsV2,
ports: [{ port: 80, targetPort: 8080 }],
type: "LoadBalancer",
},
});
// Export the URL for the service.
const address = service.status.loadBalancer.ingress[0].ip;
const port = service.spec.ports[0].port;
export const url = pulumi.interpolate`http://${address}:${port}`;