1
0
Fork 0
mirror of https://github.com/prometheus-operator/prometheus-operator.git synced 2025-04-21 11:48:53 +00:00

Documentation/user-guides: add getting-started

This commit is contained in:
Frederic Branczyk 2017-03-02 13:54:28 +01:00
parent 62096c84d3
commit 1804e7fb42
No known key found for this signature in database
GPG key ID: CA14788B1E48B256
10 changed files with 234 additions and 35 deletions

View file

@ -1,31 +1,13 @@
kind: Service
apiVersion: "v1"
metadata:
name: example-app
labels:
app: example-app
spec:
selector:
app: example-app
ports:
- name: web
protocol: TCP
port: 8080
- name: web2
protocol: TCP
port: 8081
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: example-app
spec:
replicas: 4
replicas: 3
template:
metadata:
labels:
app: example-app
version: 2.0.4
spec:
containers:
- name: example-app

View file

@ -0,0 +1,12 @@
apiVersion: monitoring.coreos.com/v1alpha1
kind: ServiceMonitor
metadata:
name: example-app
labels:
team: frontend
spec:
selector:
matchLabels:
app: example-app
endpoints:
- port: web

View file

@ -0,0 +1,12 @@
kind: Service
apiVersion: v1
metadata:
name: example-app
labels:
app: example-app
spec:
selector:
app: example-app
ports:
- name: web
port: 8080

View file

@ -0,0 +1,14 @@
apiVersion: v1
kind: Service
metadata:
name: prometheus-example
spec:
type: NodePort
ports:
- name: web
nodePort: 30900
port: 9090
protocol: TCP
targetPort: web
selector:
prometheus: example

View file

@ -0,0 +1,11 @@
apiVersion: monitoring.coreos.com/v1alpha1
kind: Prometheus
metadata:
name: example
spec:
serviceMonitorSelector:
matchLabels:
team: frontend
resources:
requests:
memory: 400Mi

View file

@ -0,0 +1,174 @@
# Prometheus Operator
The mission of the Prometheus Operator is to make running Prometheus on top of
Kubernetes as easy as possible, while preserving configurability as well as
making the configuration Kubernetes native.
To follow this getting started you will need a Kubernetes cluster you have
access to. Let's give the Prometheus Operator a spin:
[embedmd]:# (../../../deployment.yaml)
```yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: prometheus-operator
labels:
operator: prometheus
spec:
replicas: 1
template:
metadata:
labels:
operator: prometheus
spec:
containers:
- name: prometheus-operator
image: quay.io/coreos/prometheus-operator:v0.6.0
resources:
requests:
cpu: 100m
memory: 50Mi
limits:
cpu: 200m
memory: 100Mi
```
The Prometheus Operator introduces third party resources in Kubernetes to
declare the desired state of a Prometheus and Alertmanager cluster as well as
the Prometheus configuration. The resources it introduces are:
* [`Prometheus`](../../prometheus.md)
* [`Alertmanager`](../../alertmanager.md)
* [`ServiceMonitor`](../../service-monitor.md)
> Important for this guide are the `Prometheus` and `ServiceMonitor` resources.
> Have a look at the [Alerting guide](../alerting/alerting.md) for more
> information about the `Alertmanager` resource.
The Prometheus resource includes fields such as the desired version of
Prometheus to run, the number of replicas, as well as a number of parameters to
configure Prometheus itself. The connection of the Prometheus resource to the
`ServiceMonitor` is established through the `serviceMonitorSelector`, which
selects which `ServiceMonitor`s are to be used to generate the configuration
file for Prometheus.
We will walk through an example application that could look like this:
[embedmd]:# (examples/example-app-deployment.yaml)
```yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: example-app
spec:
replicas: 3
template:
metadata:
labels:
app: example-app
spec:
containers:
- name: example-app
image: fabxc/instrumented_app
ports:
- name: web
containerPort: 8080
```
Essentially the `ServiceMonitor` has a label selector to select `Service`s and
the underlying `Endpoints` objects. For example one might have a `Service` that
looks like the following:
[embedmd]:# (examples/example-app-service.yaml)
```yaml
kind: Service
apiVersion: v1
metadata:
name: example-app
labels:
app: example-app
spec:
selector:
app: example-app
ports:
- name: web
port: 8080
```
This `Service` object could be discovered by a `ServiceMonitor`.
[embedmd]:# (examples/example-app-service-monitor.yaml)
```yaml
apiVersion: monitoring.coreos.com/v1alpha1
kind: ServiceMonitor
metadata:
name: example-app
labels:
team: frontend
spec:
selector:
matchLabels:
app: example-app
endpoints:
- port: web
```
Finally a `Prometheus` object defines the `serviceMonitorSelector` to specify
which `ServiceMonitor`s should be included when generating the Prometheus
configuration.
[embedmd]:# (examples/prometheus-example.yaml)
```yaml
apiVersion: monitoring.coreos.com/v1alpha1
kind: Prometheus
metadata:
name: example
spec:
serviceMonitorSelector:
matchLabels:
team: frontend
resources:
requests:
memory: 400Mi
```
To be able to access the Prometheus instance it will have to be exposed to the
outside somehow. Purely for demonstration purpose we will expose it via a
`Service` of type `NodePort`.
[embedmd]:# (examples/prometheus-example-service.yaml)
```yaml
apiVersion: v1
kind: Service
metadata:
name: prometheus-example
spec:
type: NodePort
ports:
- name: web
nodePort: 30900
port: 9090
protocol: TCP
targetPort: web
selector:
prometheus: example
```
Once this `Service` is created the Prometheus web UI is available under the
node's IP address on port `30900`. The targets page in the web UI now shows
that the instances of the example application have successfully been
discovered.
> Exposing the Prometheus web UI may not be an applicable solution. Read more
> about the possibilities of exposing it in the [exposing Prometheus and
> Alertmanager guide](../exposing-prometheus-and-alertmanager/exposing-prometheus-and-alertmanager.md).
Further reading:
* In addition to managing Prometheus clusters the Prometheus Operator can also
manage Alertmanager clusters. Learn more in the [Alerting
guide](../alerting/alerting.md).
* Monitoring the Kubernetes cluster itself. Learn more in the [Cluster
Monitoring guide](../cluster-monitoring/cluster-monitoring.md)

View file

@ -48,4 +48,12 @@ promu:
GOARCH=$(subst x86_64,amd64,$(patsubst i%86,386,$(shell uname -m))) \
go get -u github.com/prometheus/promu
.PHONY: all build crossbuild test format check-license container e2e-test e2e-status e2e clean-e2e
embedmd:
@GOOS=$(shell uname -s | tr A-Z a-z) \
GOARCH=$(subst x86_64,amd64,$(patsubst i%86,386,$(shell uname -m))) \
go get github.com/campoy/embedmd
docs: embedmd
echo "test"
.PHONY: all build crossbuild test format check-license container e2e-test e2e-status e2e clean-e2e embedmd docs

View file

@ -13,7 +13,7 @@ spec:
spec:
containers:
- name: prometheus-operator
image: quay.io/coreos/prometheus-operator:latest
image: quay.io/coreos/prometheus-operator:v0.6.0
resources:
requests:
cpu: 100m

View file

@ -1,14 +0,0 @@
apiVersion: "monitoring.coreos.com/v1alpha1"
kind: "ServiceMonitor"
metadata:
name: "example-app"
labels:
app: example-app
spec:
selector:
matchLabels:
app: example-app
endpoints:
- port: "web"
interval: 30s