File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change 1+ const k8s = require ( '@kubernetes/client-node' )
2+ const kc = new k8s . KubeConfig ( )
3+ kc . loadFromDefault ( )
4+
5+ // Using apiVersion networking.k8s.io/v1beta1, for versions before 1.14 use extensions/v1beta1
6+ const k8sApi = kc . makeApiClient ( k8s . NetworkingV1beta1Api )
7+
8+ function createIngress ( clientIdentifier ) {
9+ return {
10+ apiVersions : 'networking.k8s.io/v1beta1' ,
11+ kind : 'Ingress' ,
12+ metadata : {
13+ name : `production-custom-${ clientIdentifier } ` ,
14+ namespace : 'default'
15+ } ,
16+ spec : {
17+ rules : [
18+ {
19+ name : `production-custom-${ clientIdentifier } ` ,
20+ host : `${ clientIdentifier } .example.com` ,
21+ http : {
22+ paths : [
23+ {
24+ backend : {
25+ serviceName : 'production-auto-deploy' ,
26+ servicePort : 5000
27+ } ,
28+ path : '/'
29+ }
30+ ]
31+ }
32+ }
33+ ] ,
34+ tls : [
35+ {
36+ hosts : [ `${ clientIdentifier } .example.com` ]
37+ }
38+ ]
39+ } ,
40+ }
41+ }
42+
43+ function main ( ) {
44+ const clientIdentifier = 'poop'
45+ const ingress = createIngress ( clientIdentifier )
46+ k8sApi . createNamespacedIngress ( 'default' , ingress )
47+ . then ( ( ) => console . log ( 'Success' ) )
48+ . catch ( e => {
49+ console . log ( e )
50+ } )
51+ }
52+
53+ main ( )
You can’t perform that action at this time.
0 commit comments