forked from cdk8s-team/cdk8s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
82 lines (72 loc) · 2.18 KB
/
main.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
import { Construct } from 'constructs';
import { App, Chart } from 'cdk8s';
import { Elasticsearch } from './imports/elasticsearch.k8s.elastic.co/elasticsearch';
import * as kplus from 'cdk8s-plus';
export class MyChart extends Chart {
constructor(scope: Construct, name: string) {
super(scope, name);
// define resources here
const esPort = 9200;
const elastic = new Elasticsearch(this, 'Elasticsearch', {
spec: {
version: '7.7.1',
nodeSets: [{
count: 1,
name: 'default',
config: {
'node.master': true,
'node.data': true,
'node.ingest': true,
'node.store.allow_mmap': false,
'xpack.security.enabled': true,
'xpack.security.http.ssl.enabled': false,
}
}],
http: {
service: {
spec: {
ports: [{
port: esPort
}]
}
},
tls: {
selfSignedCertificate: {
disabled: true
}
}
}
}
})
const passwordSecret = kplus.Secret.fromSecretName(`${elastic.name}-es-elastic-user`);
const workingDir = '/root';
const queryPort = 8000;
const container = new kplus.Container({
image: 'node:12.18.0-stretch',
workingDir: workingDir,
command: ['node', 'query.js', queryPort.toString()],
port: queryPort,
env: {
ELASTIC_USERNAME: kplus.EnvValue.fromValue('elastic'),
ELASTIC_ENDPOINT: kplus.EnvValue.fromValue(`http://${elastic.name}-es-http:${esPort}`),
ELASTIC_PASSWORD: kplus.EnvValue.fromSecret(passwordSecret, 'elastic')
}
})
const configMap = new kplus.ConfigMap(this, 'Config');
configMap.addFile(`${__dirname}/query.js`);
const volume = kplus.Volume.fromConfigMap(configMap);
container.mount(workingDir, volume);
const deployment = new kplus.Deployment(this, 'Deployment', {
spec: {
replicas: 1,
podSpecTemplate: {
containers: [container]
}
}
})
deployment.expose({port: 9000});
}
}
const app = new App();
new MyChart(app, 'elasticsearch-query');
app.synth();