forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
88 lines (79 loc) · 3.71 KB
/
app.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
// Copyright 2016-2019, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import * as k8s from "@pulumi/kubernetes";
import * as pulumi from "@pulumi/pulumi";
// Arguments for the demo app.
export interface DemoAppArgs {
provider: k8s.Provider; // Provider resource for the target Kubernetes cluster.
imageTag: string; // Tag for the kuard image to deploy.
staticAppIP?: pulumi.Input<string>; // Optional static IP to use for the service. (Required for AKS).
}
export class DemoApp extends pulumi.ComponentResource {
public appUrl: pulumi.Output<string>;
constructor(name: string,
args: DemoAppArgs,
opts: pulumi.ComponentResourceOptions = {}) {
super("examples:kubernetes-ts-multicloud:demo-app", name, args, opts);
// Create the kuard Deployment.
const appLabels = {app: "kuard"};
const deployment = new k8s.apps.v1.Deployment(`${name}-demo-app`, {
spec: {
selector: {matchLabels: appLabels},
replicas: 1,
template: {
metadata: {labels: appLabels},
spec: {
containers: [
{
name: "kuard",
image: `gcr.io/kuar-demo/kuard-amd64:${args.imageTag}`,
ports: [{containerPort: 8080, name: "http"}],
livenessProbe: {
httpGet: {path: "/healthy", port: "http"},
initialDelaySeconds: 5,
timeoutSeconds: 1,
periodSeconds: 10,
failureThreshold: 3,
},
readinessProbe: {
httpGet: {path: "/ready", port: "http"},
initialDelaySeconds: 5,
timeoutSeconds: 1,
periodSeconds: 10,
failureThreshold: 3,
},
},
],
},
},
},
}, {provider: args.provider, parent: this});
// Create a LoadBalancer Service to expose the kuard Deployment.
const service = new k8s.core.v1.Service(`${name}-demo-app`, {
spec: {
loadBalancerIP: args.staticAppIP, // Required for AKS - automatic LoadBalancer still in preview.
selector: appLabels,
ports: [{port: 80, targetPort: 8080}],
type: "LoadBalancer",
},
}, {provider: args.provider, parent: this});
// The address appears in different places depending on the Kubernetes service provider.
let address = service.status.loadBalancer.ingress[0].hostname;
if (name === "gke" || name === "aks") {
address = service.status.loadBalancer.ingress[0].ip;
}
this.appUrl = pulumi.interpolate`http://${address}:${service.spec.ports[0].port}`;
this.registerOutputs();
}
}