Prometheus in Kubernetes
Prometheus is a monitor and alert toolkit; it can set up on any platform.
There are some charts for Prometheus to set up in Kubernetes:
Prometheus-operator project has integrated a lot of exports and Grafana for Kubernetes, so it is easy to use.
Another is Kubernetes charts project, now we start set up Prometheus via charts project of Kubernetes,
- https://github.com/kubernetes/charts/tree/master/stable/prometheus
- https://github.com/kubernetes/charts/tree/master/stable/grafana
Install steps:
- clone kubernetes charts project, If you install prometheus by help online, the service account is default
git clone https://github.com/kubernetes/charts.git
- Create persistent volume for Prometheus server, Alert manager, and Grafana.
apiVersion: v1
kind: PersistentVolume
metadata:
name: {{prometheus-alert-pv}}
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
storageClassName: {{ prometheus-alert}}
nfs:
server: {{192.168.1.100}}
path: {{"/data/prometheus/alert"}}
- Create Prometheus via helm
There are some configures need to set if you don't want use default value.
Because I adopt NFS as persistent volume, so we need to set storage class name as configures.
helm install ./stable/prometheus --name k8s-prometheus \
--set alertmanager.persistentVolume.storageClass=prometheus-alert \
--set server.persistentVolume.storageClass=prometheus-server \
--namespace monitoring
- Check Prometheus server is started success.
> kubectl get po -n=monitoring
NAME READY STATUS RESTARTS AGE
k8s-prometheus-prometheus-alertmanager-784f7946bf-ffzz7 2/2 Running 0 1m
k8s-prometheus-prometheus-kube-state-metrics-675dbc4dd7-hgjz7 1/1 Running 0 1m
k8s-prometheus-prometheus-node-exporter-bnnf8 1/1 Running 0 1m
k8s-prometheus-prometheus-node-exporter-xnnb9 1/1 Running 0 1m
k8s-prometheus-prometheus-pushgateway-84b4bb947f-w9fqx 1/1 Running 0 1m
k8s-prometheus-prometheus-server-5fcfd56cd5-gmg48 2/2 Running 0 1m
> kubectl logs k8s-prometheus-prometheus-server-cd5c844d8-mhwx7 -n=monitoring
..
level=info ts=2018-03-12T06:07:58.827303886Z caller=kubernetes.go:191 component="discovery manager notify" discovery=k8s msg="Using pod service account via in-cluster config"
level=info ts=2018-03-12T06:07:58.827659506Z caller=main.go:486 msg="Server is ready to receive web requests."
level=info ts=2018-03-12T06:07:58.827695217Z caller=manager.go:59 component="scrape manager" msg="Starting scrape manager..."
- Install Grafana
helm install ./stable/grafana --name k8s-grafana \
--set server.persistentVolume.storageClass=prometheus-grafana \
--set server.adminPassword=abcd@1234 \
--set server.service.type=NodePort \
--set server.service.nodePort=30266 \
--namespace monitoring
- Check Grafana is running
> kubectl get po -n=monitoring -l app=k8s-grafana-grafana
k8s-grafana-699fff8bb8-pqp5z 1/1 Running 0 <invalid>
- Connect Grafana by browser 192.168.1.100:30266
- Add data source to Grafana, URL enter kubernetes service domain name
- Setting your dashboard to start monitor!