forked from BrandonPotter/kubergui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeploymentBuilder.html
321 lines (302 loc) · 11.8 KB
/
DeploymentBuilder.html
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://unpkg.com/vue"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-yaml/3.8.2/js-yaml.min.js"></script>
<title>Kubernetes Deployment Builder</title>
</head>
<body>
<div id="app">
<div class="col-md-6 col-lg-6 col-sm-12">
<h3>Kubernetes Deployment Builder</h3>
<div id="app">
<div class="form-group">
<label for="txtDockerImageName">Docker Image Name:</label>
<input type="text" class="form-control" id="txtDockerImageName" name="txtDockerImageName" v-model="DockerImageName" />
Examples:
<pre>
busybox
nginx
busybox:latest
gcr.io/your-project-id/your-namespace/your-image:latest
</pre>
</div>
<div class="form-group">
<label for="txtContainerCommand">Container Command:</label>
<input type="text" class="form-control" id="txtContainerCommand" name="txtContainerCommand" placeholder="Docker command for container, if any" v-model="ContainerCommand" />
</div>
<div class="form-group">
<label for="txtContainerArgs">Container Args:</label>
<input type="text" class="form-control" id="txtContainerArgs" name="txtContainerArgs" placeholder="Docker args for container, if any" v-model="ContainerArgs" />
</div>
<div class="form-group">
<label for="txtDeploymentNameOverride">Deployment Name:</label>
<input type="text" class="form-control" id="txtDeploymentNameOverride" name="txtDeploymentNameOverride" v-bind:placeholder="DeploymentName" v-model="DeploymentNameOverride" />
</div>
<div class="form-group">
<label for="txtContainerNameoverride">Container Name:</label>
<input type="text" class="form-control" id="txtContainerNameoverride" name="txtContainerNameoverride" v-bind:placeholder="ContainerName" v-model="ContainerNameOverride" />
</div>
<div class="form-group">
<label for="txtAppLabelOverride">App Label:</label>
<input type="text" class="form-control" id="txtAppLabelOverride" name="txtAppLabelOverride" v-bind:placeholder="AppLabel" v-model="AppLabelOverride" />
</div>
<div class="form-group">
<label for="txtReplicas">Replicas:</label>
<input type="text" class="form-control" id="txtReplicas" name="txtReplicas" v-model="Replicas" />
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4>Ports</h4>
</div>
<div class="panel-body">
<div>Add container ports, and optionally specify if any ports should be exposed via a service. (Will add additonal service configuration to YAML template.)</div>
<button class="btn btn-primary" v-on:click="addPort"><span class="glyphicon glyphicon-plus"></span> Add Port</button>
<div> </div>
<div v-for="port in Ports">
<div class="panel panel-primary">
<div class="panel-body">
<div class="row">
<div class="col-lg-6 col-sm-6 col-md-6">
<div class="input-group">
<span class="input-group-addon" style=" padding:0 15px;"><button v-on:click="deletePort(port)"><span class="glyphicon glyphicon-trash"></span></button> Container Port</span>
<input type="text" class="form-control" v-model="port.ContainerPort" />
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-6" style="margin-top: 5px;">
<input type="checkbox" v-model="port.ExposeViaService" /> Expose Service Port
</div>
<div class="clearfix"> </div>
<div class="col-lg-6 col-md-6 col-sm-6" v-show="port.ExposeViaService">
<div class="input-group">
<span class="input-group-addon">
Exposed Port Number
</span>
<input type="text" class="form-control" v-model="port.ServicePort" placeholder="port #" style="min-width: 50px;" />
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-6" v-show="port.ExposeViaService">
<div class="input-group">
<span class="input-group-addon">Port Name</span>
<input type="text" class="form-control" v-model="port.ServicePortName" placeholder="Port Name (optional)" />
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-6" style=" margin-top:10px;" v-show="port.ExposeViaService">
<div>
<label for="selProtocol">Protocol</label>
<select class="form-control" name="selProtocol" ID="selProtocol" v-model="port.ServicePortProtocol" style="min-width: 100px;">
<option value="TCP">TCP</option>
<option value="UDP">UDP</option>
</select>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="panel panel-primary" v-if="HasOneOrMoreServicePorts">
<div class="panel-heading">
<h4>Service Information</h4>
</div>
<div class="panel-body">
<div class="form-group">
<label for="txtReplicas">Service Name:</label>
<input type="txtServiceNameOverride" class="form-control" id="txtServiceNameOverride" name="txtServiceNameOverride" v-model="ServiceNameOverride" v-bind:placeholder="ServiceName" />
</div>
<div class="form-group">
<label for="selServiceType">Service Type:</label>
<select class="form-control" name="selServiceType" ID="selServiceType" v-model="ServiceType" style="min-width: 100px;">
<option value="ClusterIP">Cluster IP</option>
<option value="NodePort">NodePort</option>
<option value="LoadBalancer">LoadBalancer</option>
</select>
<div v-if="ServiceType === 'ClusterIP'" class="alert alert-primary">
<strong>ClusterIP</strong> exposes the service on a cluster-internal IP. Choosing this value makes the service only reachable from within the cluster.
</div>
<div v-if="ServiceType === 'NodePort'" class="alert alert-primary">
<strong>NodePort</strong> exposes the service on each Node's IP on a high randomly chosen port. The port used to access the service will be generated in the 30000's range (i.e. port 31229).
</div>
<div v-if="ServiceType === 'LoadBalancer'" class="alert alert-primary">
<span class="label label-warning">Cloud Provider Only</span> <strong>LoadBalancer</strong> exposes the service externally using a cloud provider's load balancer.
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-6 col-lg-6 col-sm-12">
<h4>Generated YAML</h4>
<pre>
{{DeploymentYaml}}
<template v-if="HasOneOrMoreServicePorts">---
{{ServiceYaml}}
</template>
</pre>
</div>
</div>
<script type="text/javascript">
var app = new Vue({
el: '#app',
data: {
DockerImageName: '',
ContainerCommand: '',
ContainerArgs: '',
DeploymentNameOverride: '',
ContainerNameOverride: '',
AppLabelOverride: '',
ServiceNameOverride: '',
Replicas: '3',
ServiceType: 'ClusterIP',
Ports: []
},
computed: {
DockerImageNameNoTag: function() {
var imageName = '';
imageName = this.DockerImageName;
if (imageName.lastIndexOf('/') >= 0) {
imageName = imageName.substr(imageName.lastIndexOf('/')+1, imageName.length-1);
}
if (imageName.indexOf(':') >= 0) {
imageName = imageName.substr(0, imageName.indexOf(':'));
}
return imageName;
},
DeploymentName: function() {
if (this.DeploymentNameOverride.length > 0) {
return this.DeploymentNameOverride;
}
return this.DockerImageNameNoTag;
},
ContainerName: function() {
if (this.ContainerNameOverride.length > 0) {
return this.ContainerNameOverride;
}
return this.DockerImageNameNoTag;
},
AppLabel: function() {
if (this.AppLabelOverride.length > 0) {
return this.AppLabelOverride;
}
return this.DockerImageNameNoTag;
},
ServiceName: function() {
if (this.ServiceNameOverride.length > 0) {
return this.ServiceNameOverride;
}
if (this.DeploymentName.length === 0) {
return "unnamed-service";
}
return this.DeploymentName + "-service";
},
ServicePorts: function() {
var portsWithServices = this.Ports.filter(function( port ) {
return port.ExposeViaService === true;
});
return portsWithServices;
},
HasOneOrMoreServicePorts: function() {
return (this.ServicePorts.length > 0);
},
DeploymentYaml: function() {
var containerPorts = [];
for (var i = 0; i < this.Ports.length; i++) {
var portString = this.Ports[i].ContainerPort;
if ((portString%1)===0) {
containerPorts.push({
'containerPort': parseInt(portString)
});
}
}
var deploymentObj = {
'apiVersion': 'extensions/v1beta1',
'kind': 'Deployment',
'metadata': {
'name': this.DeploymentName
},
'spec': {
'replicas': parseInt(this.Replicas),
'template': {
'metadata': {
'labels': {
'app': this.AppLabel
} // end labels
}, // end metadata
'spec': {
'containers': [{
'name': this.ContainerName,
'image': this.DockerImageName,
'ports': containerPorts
}]
} // end spec
} // end template
} // end spec
} // end deploymentObj
if (this.ContainerCommand.length > 0) {
deploymentObj.spec.template.spec.containers[0].command = [this.ContainerCommand];
}
if (this.ContainerArgs.length > 0) {
deploymentObj.spec.template.spec.containers[0].args = [this.ContainerArgs];
}
return jsyaml.dump(deploymentObj);
},
ServiceYaml: function() {
var ports = [];
for (var i = 0; i < this.ServicePorts.length; i++) {
var port = this.ServicePorts[i];
var servicePortObj = {
'port': parseInt(port.ServicePort),
'targetPort': parseInt(port.ContainerPort),
'protocol': port.ServicePortProtocol
};
if (port.ServicePortName.length > 0) {
servicePortObj.name = port.ServicePortName;
}
ports.push(servicePortObj);
}
var serviceObj = {
'apiVersion': 'v1',
'kind': 'Service',
'metadata': {
'name': this.ServiceName,
'labels': {
'name': this.ServiceName
} // end labels
},
'spec': {
'ports': ports,
'selector': {
'app': this.AppLabel
},
'type': this.ServiceType
} // end spec
} // end deploymentObj
return jsyaml.dump(serviceObj);
}
},
methods: {
addPort: function() {
var newPort = {
ContainerPort: '80',
ExposeViaService: false,
ServicePortName: '',
ServicePort: '80',
ServicePortProtocol: 'TCP'
};
this.Ports.push(newPort);
},
deletePort: function(port) {
var portIndex = this.Ports.indexOf(port);
if (portIndex > -1) {
this.Ports.splice(portIndex, 1);
}
}
}
});
</script>
</body>
</html>