🌳
pt0/deployF/k8sProvF/ingressNginxBaremetalAI.mts
1import fetch from 'node-fetch'
9type NodePortsResult = {httpNodePort: number, httpsNodePort: number}
11const ingressNginxBareMetalUrl = (version: string) =>
12 `https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-${version}/deploy/static/provider/baremetal/deploy.yaml`
14const getIngressNodePorts = async (): Promise<NodePortsResult | null> => {
15 const svc: any = await readKlustResource({
16 apiVersion: 'v1',
17 kind: 'Service',
18 metadata: { name: 'ingress-nginx-controller', namespace: 'ingress-nginx' },
19 })
20 if (!svc) return null
22 const httpPort = svc.spec.ports.find((p: any) => p.port === 80)?.nodePort
23 const httpsPort = svc.spec.ports.find((p: any) => p.port === 443)?.nodePort
24 return { httpNodePort: httpPort, httpsNodePort: httpsPort }
27export const applyIngressNginxBaremetal = async ({version, kubeConfigPath}: {version: string, kubeConfigPath: string}) => {
28 console.log('installing ingress-nginx (baremetal/NodePort mode)...')
30 const manifestUrl = ingressNginxBareMetalUrl(version)
31 const resp = await fetch(manifestUrl)
32 throwIf(() => resp.status !== 200, {manifestUrl, status: resp.status})
33 const resources = yamlReplaceAndLoad({contentS: await resp.text()}) as KubeResource[]
34 await kube2ApplyK({action: 'apply', resources})
36 console.log('waiting for ingress-nginx service...')
37 let nodePorts: NodePortsResult | null = null
38 for (let i = 0; i < 30; i++) {
39 nodePorts = await getIngressNodePorts()
40 if (nodePorts?.httpNodePort && nodePorts?.httpsNodePort) break
41 await sleep(2000)
42 }
44 assertDefined(nodePorts)
45 console.log(`ingress-nginx NodePorts: HTTP=${nodePorts.httpNodePort}, HTTPS=${nodePorts.httpsNodePort}`)
46 return nodePorts