Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add the ability to deploy a node app to Kubernetes(Minikube)
* This feature adds the ability to deploy a node application to a vanilla kubernetes cluster. Only Minikube is supported at the moment.
- Loading branch information
1 parent
3873041
commit 3e03c00
Showing
29 changed files
with
1,140 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
|
||
const { readFileSync } = require('fs'); | ||
const Docker = require('dockerode'); | ||
|
||
function dockerClientSetup (options = {}, kubeEnvVars) { | ||
const url = new URL(kubeEnvVars.DOCKER_HOST); | ||
|
||
const docker = new Docker({ | ||
host: url.hostname, | ||
port: url.port || 2375, | ||
ca: readFileSync(`${kubeEnvVars.DOCKER_CERT_PATH}/ca.pem`), | ||
cert: readFileSync(`${kubeEnvVars.DOCKER_CERT_PATH}/cert.pem`), | ||
key: readFileSync(`${kubeEnvVars.DOCKER_CERT_PATH}/key.pem`) | ||
}); | ||
|
||
return docker; | ||
} | ||
|
||
module.exports = dockerClientSetup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict'; | ||
|
||
// export DOCKER_TLS_VERIFY="1" | ||
// export DOCKER_HOST="tcp://192.168.39.50:2376" | ||
// export DOCKER_CERT_PATH="/home/lucasholmquist/.minikube/certs" | ||
// export MINIKUBE_ACTIVE_DOCKERD="minikube" | ||
const util = require('util'); | ||
const exec = util.promisify(require('child_process').exec); | ||
|
||
async function getMinikubeEnvironmentVariables () { | ||
// Make a call to minikube docker-env | ||
try { | ||
const { stdout } = await exec('minikube docker-env'); | ||
const envs = stdout | ||
.split('\n') // Split on newline | ||
.filter((v) => { // Then only return the lines that have the export | ||
return v.includes('export'); | ||
}) | ||
.map((v) => { // Now make those lines into an Array of objects | ||
const splitExport = v.split('export')[1].trim(); | ||
const splitObject = splitExport.split('='); | ||
return { [splitObject[0]]: splitObject[1].replace(/"/g, '') }; | ||
}) | ||
.reduce((acc, x) => { // Flatten the array of objects into one object | ||
return { ...acc, ...x }; | ||
}, {}); | ||
|
||
return envs; | ||
} catch (err) { | ||
return Promise.reject(new Error(err)); | ||
} | ||
} | ||
|
||
async function getKubernetesEnv () { | ||
return getMinikubeEnvironmentVariables(); | ||
} | ||
|
||
module.exports = getKubernetesEnv; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
|
||
const logger = require('./common-log')(); | ||
|
||
function outputKubeUrl (config, appliedResources) { | ||
const deployedService = appliedResources.find((v) => { return v.body.kind === 'Service'; }); | ||
|
||
if (deployedService) { | ||
const kubeUrl = new URL(config.openshiftRestClient.backend.requestOptions.baseUrl); | ||
|
||
// Output the host:port where the running application is? | ||
const parsedURL = `http://${kubeUrl.hostname}:${deployedService.body.spec.ports[0].nodePort}`; | ||
logger.info(`Application running at: ${parsedURL}`); | ||
return parsedURL; | ||
} | ||
logger.warn('No Deployed Service Found'); | ||
} | ||
|
||
module.exports = outputKubeUrl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.