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> => { 18 metadata: { name: 'ingress-nginx-controller', namespace: 'ingress-nginx' }, 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}) 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 45 console.log(`ingress-nginx NodePorts: HTTP=${nodePorts.httpNodePort}, HTTPS=${nodePorts.httpsNodePort}`)