Skip to content

Commit d6234f5

Browse files
authored
[DOC] Show an example of creating an ingress
Something nearly everyone actually does, an is actually quite painful if you're not used to typescript or how kubeConfig works.
1 parent 3ef3738 commit d6234f5

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

examples/ingress.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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()

0 commit comments

Comments
 (0)