Skip to content

Commit

Permalink
Use Heapster as an in-built monitoring solution for Kubernetes in GCE.
Browse files Browse the repository at this point in the history
Users will have an option to enable it when they setup their cluster (kube-up).
  • Loading branch information
vishh committed Nov 7, 2014
1 parent 5590adb commit edf6d8e
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 0 deletions.
29 changes: 29 additions & 0 deletions cluster/gce/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,9 @@ EOF
function kube-down {
# Detect the project into $PROJECT
detect-project

# Monitoring might have been setup. It doesn't hurt to attempt shutdown even it wasn't setup.
teardown-monitoring

echo "Bringing down cluster"
gcutil deletefirewall \
Expand Down Expand Up @@ -569,3 +572,29 @@ function ssh-to-node {
function restart-kube-proxy {
ssh-to-node "$1" "sudo /etc/init.d/kube-proxy restart"
}

# Setup monitoring using heapster and InfluxDB
function setup-monitoring {
read -p "Setup monitoring of the cluster using heapster (https://github.com/GoogleCloudPlatform/heapster) [Y|N]? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
teardown-monitoring
kubectl.sh create -f "${KUBE_ROOT}/examples/monitoring/influx-grafana-pod.json" &&
kubectl.sh create -f "${KUBE_ROOT}/examples/monitoring/influx-grafana-service.json" &&
kubectl.sh create -f "${KUBE_ROOT}/examples/monitoring/heapster-pod.json"
if [ $? -ne 0 ]; then
teardown-monitoring
else
dashboardIP="http://`kubectl.sh get -o json pod influx-grafana | grep hostIP | awk '{print $2}' | sed 's/[,|\"]//g'`"
echo "Grafana dashboard is available at $dashboardIP"
echo "username is 'admin' and password is 'admin'"
fi
fi
}

function teardown-monitoring {
kubectl.sh delete pods heapster || true
kubectl.sh delete pods influx-grafana || true
kubectl.sh delete services influx-master || true
}
1 change: 1 addition & 0 deletions cluster/kube-up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ verify-prereqs
kube-up

"${KUBE_ROOT}/cluster/validate-cluster.sh"
setup-monitoring

echo "Done"
52 changes: 52 additions & 0 deletions examples/monitoring/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
Heapster
===========

Heapster enables monitoring of Kubernetes Clusters using [cAdvisor](https://github.com/google/cadvisor). It currently works only on GCE.

#####Run Heapster in a Kubernetes cluster with an Influxdb backend and [Grafana](http://grafana.org/docs/features/influxdb)

**Step 1: Setup Kube cluster**

Fork the Kubernetes repository and [turn up a Kubernetes cluster](https://github.com/GoogleCloudPlatform/kubernetes-new#contents), if you haven't already. Make sure kubectl.sh is exported.

**Step 2: Start a Pod with Influxdb, grafana and elasticsearch**

```shell
$ kubectl.sh create -f deploy/influx-grafana-pod.json
```

**Step 3: Start Influxdb service**

```shell
$ kubectl.sh create -f deploy/influx-grafana-service.json
```

**Step 4: Update firewall rules**

Open up ports tcp:80,8083,8086,9200.
```shell
$ gcutil addfirewall --allowed=tcp:80,tcp:8083,tcp:8086,tcp:9200 --target_tags=kubernetes-minion heapster
```

**Step 5: Start Heapster Pod**

```shell
$ kubectl.sh create -f deploy/heapster-pod.json
```

Verify that all the pods and services are up and running:

```shell
$ kubectl.sh get pods
```
```shell
$ kubectl.sh get services
```

To start monitoring the cluster using grafana, find out the the external IP of the minion where the 'influx-grafana' Pod is running from the output of `kubectl.sh get pods`, and visit `http://<minion-ip>:80`.

To access the Influxdb UI visit `http://<minion-ip>:8083`.

#####Hints
* Grafana's default username and password is 'admin'. You can change that by modifying the grafana container [here](influx-grafana/deploy/grafana-influxdb-pod.json)
* To enable memory and swap accounting on the minions follow the instructions [here](https://docs.docker.com/installation/ubuntulinux/#memory-and-swap-accounting)
18 changes: 18 additions & 0 deletions examples/monitoring/heapster-pod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"id": "heapster",
"kind": "Pod",
"apiVersion": "v1beta1",
"desiredState": {
"manifest": {
"version": "v1beta1",
"id": "heapster",
"containers": [{
"name": "heapster",
"image": "kubernetes/heapster",
}]
}
},
"labels": {
"name": "heapster",
}
}
34 changes: 34 additions & 0 deletions examples/monitoring/influx-grafana-pod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"id": "influx-grafana",
"kind": "Pod",
"apiVersion": "v1beta1",
"desiredState": {
"manifest": {
"version": "v1beta1",
"id": "influx-grafana",
"containers": [{
"name": "influxdb",
"image": "kubernetes/heapster_influxdb",
"ports": [
{"containerPort": 8083, "hostPort": 8083},
{"containerPort": 8086, "hostPort": 8086},
{"containerPort": 8090, "hostPort": 8090},
{"containerPort": 8099, "hostPort": 8099}]
}, {
"name": "grafana",
"image": "kubernetes/heapster_grafana",
"ports": [{"containerPort": 80, "hostPort": 80}],
"env": [{"name": HTTP_USER, "value": admin},
{"name": HTTP_PASS, "value": admin}],
}, {
"name": "elasticsearch",
"image": "dockerfile/elasticsearch",
"ports": [{"containerPort": 9200, "hostPort": 9200},
{"containerPort": 9300}],
}]
},
},
"labels": {
"name": "influxdb",
}
}
10 changes: 10 additions & 0 deletions examples/monitoring/influx-grafana-service.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "influx-master",
"kind": "Service",
"apiVersion": "v1beta1",
"port": 8085,
"containerPort": 8086,
"provider": "kubernetes-default",
"component": "influxdb"
"selector": { "name": "influxdb" }
}

0 comments on commit edf6d8e

Please sign in to comment.