提交 a7eec01e 编写于 作者: L Lukasz Zajaczkowski

Introduce Heapster to local Kubernetes cluster

上级 d1ac65e2
......@@ -26,6 +26,11 @@ import conf from './conf';
*/
const clusterHealthzUrl = `http://${conf.backend.apiServerHost}/healthz`;
/**
* The validate URL of the heapster to check that it is running.
*/
const heapsterValidateUrl = `http://${conf.backend.heapsterServerHost}/validate`;
/**
* A Number, representing the ID value of the timer that is set for function which periodically
* checks if cluster is running. The null means that no timer is running.
......@@ -34,6 +39,14 @@ const clusterHealthzUrl = `http://${conf.backend.apiServerHost}/healthz`;
*/
let isRunningSetIntervalHandler = null;
/**
* A Number, representing the ID value of the timer that is set for function which periodically
* checks if Heapster is running. The null means that no timer is running.
*
* @type {?number}
*/
let isHeapsterRunningSetIntervalHandler = null;
/**
* Checks if cluster health check return correct status.
* When custer is up and running then return 'ok'.
......@@ -48,6 +61,20 @@ function clusterHealthCheck(doneFn) {
});
}
/**
* Checks if Heapster return debug messages.
* When Heapster is running then return some debug text otherwise server return error.
* @param {function(?Error=)} doneFn
*/
function heapsterHealthCheck(doneFn) {
childProcess.exec(`curl ${heapsterValidateUrl}`, function(err, stdout) {
if (err) {
return doneFn(new Error(err));
}
return doneFn(stdout.trim());
});
}
/**
* Creates cluster from scratch.
* Downloads latest version of kubernetes from git repository.
......@@ -59,7 +86,7 @@ function clusterHealthCheck(doneFn) {
* * Install golang
* * Install etcd
*/
gulp.task('local-up-cluster', ['spawn-cluster', 'wait-for-cluster']);
gulp.task('local-up-cluster', ['spawn-cluster', 'wait-for-cluster', 'wait-for-heapster']);
/**
* Spawns a local Kubernetes cluster running inside a Docker container.:
......@@ -75,6 +102,35 @@ gulp.task('spawn-cluster', function(doneFn) {
});
});
/**
* Checks periodically if heapster is up and running.
*/
gulp.task('wait-for-heapster', function(doneFn) {
let counter = 0;
if (!isHeapsterRunningSetIntervalHandler) {
isHeapsterRunningSetIntervalHandler = setInterval(isRunning, 1000);
}
function isRunning() {
if (counter % 10 === 0) {
gulpUtil.log(
gulpUtil.colors.magenta(
`Waiting for a Heapster on ${conf.backend.heapsterServerHost}...`));
}
counter += 1;
// constantly query the heapster until it is properly running
heapsterHealthCheck(function(result) {
if (result.length > 0) {
gulpUtil.log(gulpUtil.colors.magenta('Heapster is up and running.'));
clearTimeout(isHeapsterRunningSetIntervalHandler);
isHeapsterRunningSetIntervalHandler = null;
doneFn();
}
});
}
});
/**
* Checks periodically if cluster is up and running.
*/
......
......@@ -46,6 +46,10 @@ export default {
* Address for the Kubernetes API server.
*/
apiServerHost: 'localhost:8080',
/**
* Address for the Heapster API server.
*/
heapsterServerHost: 'localhost:8082',
},
/**
......
......@@ -20,6 +20,8 @@
K8S_VERSION="1.1.2"
# Port of the apiserver to serve on.
PORT=8080
# Port of the heapster to serve on.
HEAPSTER_PORT=8082
docker run --net=host -d gcr.io/google_containers/etcd:2.0.12 \
/usr/local/bin/etcd --addr=127.0.0.1:4001 --bind-addr=0.0.0.0:4001 --data-dir=/var/etcd/data
......@@ -43,3 +45,7 @@ docker run \
docker run -d --net=host --privileged gcr.io/google_containers/hyperkube:v${K8S_VERSION} \
/hyperkube proxy --master=http://127.0.0.1:${PORT} --v=2
# Runs Heapster in standalone mode
docker run --net=host -d kubernetes/heapster -port ${HEAPSTER_PORT}\
--source=kubernetes:http://127.0.0.1:${PORT}?inClusterConfig=false&auth=""
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册