Skip to content

Commit

Permalink
Issue #50 addon for prometheus in openshift 3.7
Browse files Browse the repository at this point in the history
prometheus for openshift 3.7
  • Loading branch information
durandom committed Nov 26, 2017
1 parent 0984944 commit 173b51c
Show file tree
Hide file tree
Showing 5 changed files with 652 additions and 0 deletions.
31 changes: 31 additions & 0 deletions add-ons/prometheus-3.7/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Prometheus Add-on
An addon that will deploy Prometheus, Node-Exporter and AlertManager.

NOTE: Requires Origin >= 3.7.0-rc.0

Verify you have installed these addons, by following the [general readme](../../README.adoc#download-and-use-community-add-ons).

## Deploy prometheus
To deploy prometheus do:

```
minishift addon apply prometheus --addon-env prometheus_namespace=kube-system
```

_NOTE_: You should provide the namespace where it will be installed with the addon-env prometheus_namespace, like this:

## Use prometheus
Prometheus will be available at:

```
minishift openshift service prometheus -n <prometheus_namespace>
```

_NOTE_: There service is exposed though SSL, so use https to access it.

## Delete prometheus
Delete prometheus with:

```
oc delete sa,clusterrolebinding,route,svc,secret,deployment,configmap,daemonset,statefulset -l 'app in (prometheus,prometheus-node-exporter)' -n <prometheus_namespace> --as=system:admin
```
79 changes: 79 additions & 0 deletions add-ons/prometheus-3.7/node-exporter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# node-exporter is an optional component that collects host level metrics from the nodes
# in the cluster. This group of resources will require the 'hostaccess' level of privilege, which
# should only be granted to namespaces that administrators can access.
apiVersion: v1
kind: List
items:
- apiVersion: v1
kind: ServiceAccount
metadata:
name: prometheus-node-exporter
# You must grant hostaccess via: oadm policy add-scc-to-user -z prometheus-node-exporter hostaccess
# in order for the node-exporter to access the host network and mount /proc and /sys from the host
- apiVersion: v1
kind: Service
metadata:
annotations:
prometheus.io/scrape: "true"
labels:
app: prometheus-node-exporter
name: prometheus-node-exporter
spec:
clusterIP: None
ports:
- name: scrape
port: 9100
protocol: TCP
targetPort: 9100
selector:
app: prometheus-node-exporter
- apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: prometheus-node-exporter
labels:
app: prometheus-node-exporter
role: monitoring
spec:
updateStrategy:
type: RollingUpdate
template:
metadata:
labels:
app: prometheus-node-exporter
role: monitoring
name: prometheus-exporter
spec:
serviceAccountName: prometheus-node-exporter
hostNetwork: true
hostPID: true
containers:
- image: openshift/prometheus-node-exporter:v0.14.0
args:
- "--collector.procfs=/host/proc"
- "--collector.sysfs=/host/sys"
name: node-exporter
ports:
- containerPort: 9100
name: scrape
resources:
requests:
memory: 30Mi
cpu: 100m
limits:
memory: 50Mi
cpu: 200m
volumeMounts:
- name: proc
readOnly: true
mountPath: /host/proc
- name: sys
readOnly: true
mountPath: /host/sys
volumes:
- name: proc
hostPath:
path: /proc
- name: sys
hostPath:
path: /sys
30 changes: 30 additions & 0 deletions add-ons/prometheus-3.7/prometheus.addon
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Name: prometheus-3.7
# Description: This template creates a Prometheus instance preconfigured to gather OpenShift and Kubernetes platform and node metrics and report them to admins. It is protected by an OAuth proxy that only allows access for users who have view access to the prometheus namespace. You may customize where the images (built from openshift/prometheus and openshift/oauth-proxy) are pulled from via template parameters.
# Url: https://raw.githubusercontent.com/openshift/origin/master/examples/prometheus/prometheus.yaml
# OpenShift-Version: >=3.7.0
# Required-Vars: prometheus_namespace

oc new-app -f prometheus.yaml -p NAMESPACE=#{prometheus_namespace} -n #{prometheus_namespace}
oc create -f node-exporter.yaml -n #{prometheus_namespace}
oc adm policy add-scc-to-user -z prometheus-node-exporter -n #{prometheus_namespace} hostaccess

# Add labels to things for easy removal
oc label svc/prometheus app=prometheus -n #{prometheus_namespace}
oc label svc/alerts app=prometheus -n #{prometheus_namespace}
oc label configmap/prometheus app=prometheus -n #{prometheus_namespace}
oc label secret/alerts-proxy app=prometheus -n #{prometheus_namespace}
oc label secret/prometheus-proxy app=prometheus -n #{prometheus_namespace}
oc label secret/prometheus-tls app=prometheus -n #{prometheus_namespace}
oc label sa/prometheus app=prometheus -n #{prometheus_namespace}
oc label sa/prometheus-node-exporter app=prometheus -n #{prometheus_namespace}
oc label routes/prometheus app=prometheus -n #{prometheus_namespace}
oc label routes/alerts app=prometheus -n #{prometheus_namespace}
oc label clusterrolebinding/prometheus-cluster-reader app=prometheus -n #{prometheus_namespace}
oc label configmaps/prometheus-alerts app=prometheus -n #{prometheus_namespace}

echo You have installed #{addon-name}
echo To access #{addon-name} go to https://prometheus-#{prometheus_namespace}.#{routing-suffix}
echo
echo To delete:
echo minishift addon remove prometheus-3.7
echo oc delete sa,clusterrolebinding,route,svc,secret,deployment,configmap,daemonset,statefulset -l 'app in (prometheus,prometheus-node-exporter)' -n #{prometheus_namespace} --as=system:admin
8 changes: 8 additions & 0 deletions add-ons/prometheus-3.7/prometheus.addon.remove
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Name: prometheus-3.7
# Description: Remove add on
# Url: https://raw.githubusercontent.com/openshift/origin/master/examples/prometheus/prometheus.yaml

echo [prometheus] removing all resources
oc delete sa,clusterrolebinding,route,svc,secret,deployment,configmap,daemonset,statefulset -l 'app in (prometheus,prometheus-node-exporter)' -n #{prometheus_namespace} --as=system:admin

echo prometheus addon removed
Loading

0 comments on commit 173b51c

Please sign in to comment.